diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/fs | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/fs')
76 files changed, 17069 insertions, 16957 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h index 25bc95e62..294a433fc 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs.h | 22 | * @file fs/fs.h |
@@ -50,8 +50,7 @@ | |||
50 | /** | 50 | /** |
51 | * @brief content hash key | 51 | * @brief content hash key |
52 | */ | 52 | */ |
53 | struct ContentHashKey | 53 | struct ContentHashKey { |
54 | { | ||
55 | /** | 54 | /** |
56 | * Hash of the original content, used for encryption. | 55 | * Hash of the original content, used for encryption. |
57 | */ | 56 | */ |
@@ -71,9 +70,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
71 | * Message sent from a GNUnet (fs) publishing activity to sign | 70 | * Message sent from a GNUnet (fs) publishing activity to sign |
72 | * a LOC URI. | 71 | * a LOC URI. |
73 | */ | 72 | */ |
74 | struct RequestLocSignatureMessage | 73 | struct RequestLocSignatureMessage { |
75 | { | ||
76 | |||
77 | /** | 74 | /** |
78 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN. | 75 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN. |
79 | */ | 76 | */ |
@@ -105,9 +102,7 @@ struct RequestLocSignatureMessage | |||
105 | /** | 102 | /** |
106 | * Message sent from the service with the signed LOC URI. | 103 | * Message sent from the service with the signed LOC URI. |
107 | */ | 104 | */ |
108 | struct ResponseLocSignatureMessage | 105 | struct ResponseLocSignatureMessage { |
109 | { | ||
110 | |||
111 | /** | 106 | /** |
112 | * Message type will be | 107 | * Message type will be |
113 | * #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE. | 108 | * #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE. |
@@ -150,9 +145,7 @@ struct ResponseLocSignatureMessage | |||
150 | * computing it; this is an optimization that should be safe given | 145 | * computing it; this is an optimization that should be safe given |
151 | * that the client is not our adversary). | 146 | * that the client is not our adversary). |
152 | */ | 147 | */ |
153 | struct IndexStartMessage | 148 | struct IndexStartMessage { |
154 | { | ||
155 | |||
156 | /** | 149 | /** |
157 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_INDEX_START. | 150 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_INDEX_START. |
158 | */ | 151 | */ |
@@ -188,7 +181,6 @@ struct IndexStartMessage | |||
188 | /* this is followed by a 0-terminated | 181 | /* this is followed by a 0-terminated |
189 | * filename of a file with the hash | 182 | * filename of a file with the hash |
190 | * "file_id" as seen by the client */ | 183 | * "file_id" as seen by the client */ |
191 | |||
192 | }; | 184 | }; |
193 | 185 | ||
194 | 186 | ||
@@ -196,8 +188,7 @@ struct IndexStartMessage | |||
196 | * Message send by FS service in response to a request | 188 | * Message send by FS service in response to a request |
197 | * asking for a list of all indexed files. | 189 | * asking for a list of all indexed files. |
198 | */ | 190 | */ |
199 | struct IndexInfoMessage | 191 | struct IndexInfoMessage { |
200 | { | ||
201 | /** | 192 | /** |
202 | * Message type will be | 193 | * Message type will be |
203 | * #GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY. | 194 | * #GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY. |
@@ -217,7 +208,6 @@ struct IndexInfoMessage | |||
217 | /* this is followed by a 0-terminated | 208 | /* this is followed by a 0-terminated |
218 | * filename of a file with the hash | 209 | * filename of a file with the hash |
219 | * "file_id" as seen by the client */ | 210 | * "file_id" as seen by the client */ |
220 | |||
221 | }; | 211 | }; |
222 | 212 | ||
223 | 213 | ||
@@ -228,9 +218,7 @@ struct IndexInfoMessage | |||
228 | * files and response with a confirmation message (even if the file | 218 | * files and response with a confirmation message (even if the file |
229 | * was already not on the list). | 219 | * was already not on the list). |
230 | */ | 220 | */ |
231 | struct UnindexMessage | 221 | struct UnindexMessage { |
232 | { | ||
233 | |||
234 | /** | 222 | /** |
235 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_UNINDEX. | 223 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_UNINDEX. |
236 | */ | 224 | */ |
@@ -245,7 +233,6 @@ struct UnindexMessage | |||
245 | * Hash of the file that we will unindex. | 233 | * Hash of the file that we will unindex. |
246 | */ | 234 | */ |
247 | struct GNUNET_HashCode file_id; | 235 | struct GNUNET_HashCode file_id; |
248 | |||
249 | }; | 236 | }; |
250 | 237 | ||
251 | 238 | ||
@@ -272,9 +259,7 @@ struct UnindexMessage | |||
272 | * Message sent from a GNUnet (fs) search activity to the | 259 | * Message sent from a GNUnet (fs) search activity to the |
273 | * gnunet-service-fs to start a search. | 260 | * gnunet-service-fs to start a search. |
274 | */ | 261 | */ |
275 | struct SearchMessage | 262 | struct SearchMessage { |
276 | { | ||
277 | |||
278 | /** | 263 | /** |
279 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_START_SEARCH. | 264 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_START_SEARCH. |
280 | */ | 265 | */ |
@@ -333,9 +318,7 @@ struct SearchMessage | |||
333 | * single response are considered done. This message is transmitted | 318 | * single response are considered done. This message is transmitted |
334 | * between peers. | 319 | * between peers. |
335 | */ | 320 | */ |
336 | struct PutMessage | 321 | struct PutMessage { |
337 | { | ||
338 | |||
339 | /** | 322 | /** |
340 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT. | 323 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT. |
341 | */ | 324 | */ |
@@ -352,7 +335,6 @@ struct PutMessage | |||
352 | struct GNUNET_TIME_AbsoluteNBO expiration; | 335 | struct GNUNET_TIME_AbsoluteNBO expiration; |
353 | 336 | ||
354 | /* this is followed by the actual encrypted content */ | 337 | /* this is followed by the actual encrypted content */ |
355 | |||
356 | }; | 338 | }; |
357 | 339 | ||
358 | /** | 340 | /** |
@@ -361,9 +343,7 @@ struct PutMessage | |||
361 | * single response are considered done. This message is transmitted | 343 | * single response are considered done. This message is transmitted |
362 | * between the service and a client. | 344 | * between the service and a client. |
363 | */ | 345 | */ |
364 | struct ClientPutMessage | 346 | struct ClientPutMessage { |
365 | { | ||
366 | |||
367 | /** | 347 | /** |
368 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT. | 348 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT. |
369 | */ | 349 | */ |
@@ -398,7 +378,6 @@ struct ClientPutMessage | |||
398 | uint32_t respect_offered; | 378 | uint32_t respect_offered; |
399 | 379 | ||
400 | /* this is followed by the actual encrypted content */ | 380 | /* this is followed by the actual encrypted content */ |
401 | |||
402 | }; | 381 | }; |
403 | GNUNET_NETWORK_STRUCT_END | 382 | GNUNET_NETWORK_STRUCT_END |
404 | 383 | ||
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index f7b64a5c9..45051ddcb 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_api.c | 22 | * @file fs/fs_api.c |
@@ -47,23 +47,23 @@ | |||
47 | * @param qe job to start | 47 | * @param qe job to start |
48 | */ | 48 | */ |
49 | static void | 49 | static void |
50 | start_job (struct GNUNET_FS_QueueEntry *qe) | 50 | start_job(struct GNUNET_FS_QueueEntry *qe) |
51 | { | 51 | { |
52 | qe->active = GNUNET_YES; | 52 | qe->active = GNUNET_YES; |
53 | qe->start (qe->cls); | 53 | qe->start(qe->cls); |
54 | qe->start_times++; | 54 | qe->start_times++; |
55 | qe->h->active_blocks += qe->blocks; | 55 | qe->h->active_blocks += qe->blocks; |
56 | qe->h->active_downloads++; | 56 | qe->h->active_downloads++; |
57 | qe->start_time = GNUNET_TIME_absolute_get (); | 57 | qe->start_time = GNUNET_TIME_absolute_get(); |
58 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 58 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
59 | "Starting job %p (%u active)\n", | 59 | "Starting job %p (%u active)\n", |
60 | qe, | 60 | qe, |
61 | qe->h->active_downloads); | 61 | qe->h->active_downloads); |
62 | GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe); | 62 | GNUNET_CONTAINER_DLL_remove(qe->h->pending_head, qe->h->pending_tail, qe); |
63 | GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, | 63 | GNUNET_CONTAINER_DLL_insert_after(qe->h->running_head, |
64 | qe->h->running_tail, | 64 | qe->h->running_tail, |
65 | qe->h->running_tail, | 65 | qe->h->running_tail, |
66 | qe); | 66 | qe); |
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
@@ -74,25 +74,25 @@ start_job (struct GNUNET_FS_QueueEntry *qe) | |||
74 | * @param qe job to stop | 74 | * @param qe job to stop |
75 | */ | 75 | */ |
76 | static void | 76 | static void |
77 | stop_job (struct GNUNET_FS_QueueEntry *qe) | 77 | stop_job(struct GNUNET_FS_QueueEntry *qe) |
78 | { | 78 | { |
79 | qe->active = GNUNET_NO; | 79 | qe->active = GNUNET_NO; |
80 | qe->stop (qe->cls); | 80 | qe->stop(qe->cls); |
81 | GNUNET_assert (0 < qe->h->active_downloads); | 81 | GNUNET_assert(0 < qe->h->active_downloads); |
82 | qe->h->active_downloads--; | 82 | qe->h->active_downloads--; |
83 | qe->h->active_blocks -= qe->blocks; | 83 | qe->h->active_blocks -= qe->blocks; |
84 | qe->run_time = GNUNET_TIME_relative_add (qe->run_time, | 84 | qe->run_time = GNUNET_TIME_relative_add(qe->run_time, |
85 | GNUNET_TIME_absolute_get_duration ( | 85 | GNUNET_TIME_absolute_get_duration( |
86 | qe->start_time)); | 86 | qe->start_time)); |
87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 87 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
88 | "Stopping job %p (%u active)\n", | 88 | "Stopping job %p (%u active)\n", |
89 | qe, | 89 | qe, |
90 | qe->h->active_downloads); | 90 | qe->h->active_downloads); |
91 | GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe); | 91 | GNUNET_CONTAINER_DLL_remove(qe->h->running_head, qe->h->running_tail, qe); |
92 | GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, | 92 | GNUNET_CONTAINER_DLL_insert_after(qe->h->pending_head, |
93 | qe->h->pending_tail, | 93 | qe->h->pending_tail, |
94 | qe->h->pending_tail, | 94 | qe->h->pending_tail, |
95 | qe); | 95 | qe); |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
@@ -103,7 +103,7 @@ stop_job (struct GNUNET_FS_QueueEntry *qe) | |||
103 | * @param cls the `struct GNUNET_FS_Handle *` | 103 | * @param cls the `struct GNUNET_FS_Handle *` |
104 | */ | 104 | */ |
105 | static void | 105 | static void |
106 | process_job_queue (void *cls) | 106 | process_job_queue(void *cls) |
107 | { | 107 | { |
108 | struct GNUNET_FS_Handle *h = cls; | 108 | struct GNUNET_FS_Handle *h = cls; |
109 | struct GNUNET_FS_QueueEntry *qe; | 109 | struct GNUNET_FS_QueueEntry *qe; |
@@ -131,20 +131,22 @@ process_job_queue (void *cls) | |||
131 | num_probes_waiting = 0; | 131 | num_probes_waiting = 0; |
132 | num_downloads_waiting = 0; | 132 | num_downloads_waiting = 0; |
133 | for (qe = h->pending_head; NULL != qe; qe = qe->next) | 133 | for (qe = h->pending_head; NULL != qe; qe = qe->next) |
134 | { | ||
135 | switch (qe->priority) | ||
136 | { | 134 | { |
137 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: | 135 | switch (qe->priority) |
138 | num_probes_waiting++; | 136 | { |
139 | break; | 137 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: |
140 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: | 138 | num_probes_waiting++; |
141 | num_downloads_waiting++; | 139 | break; |
142 | break; | 140 | |
143 | default: | 141 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: |
144 | GNUNET_break (0); | 142 | num_downloads_waiting++; |
145 | break; | 143 | break; |
144 | |||
145 | default: | ||
146 | GNUNET_break(0); | ||
147 | break; | ||
148 | } | ||
146 | } | 149 | } |
147 | } | ||
148 | /* now, calculate some basic statistics on running jobs */ | 150 | /* now, calculate some basic statistics on running jobs */ |
149 | num_probes_active = 0; | 151 | num_probes_active = 0; |
150 | num_probes_expired = 0; | 152 | num_probes_expired = 0; |
@@ -152,161 +154,165 @@ process_job_queue (void *cls) | |||
152 | num_downloads_expired = 0; | 154 | num_downloads_expired = 0; |
153 | next = h->running_head; | 155 | next = h->running_head; |
154 | while (NULL != (qe = next)) | 156 | while (NULL != (qe = next)) |
155 | { | 157 | { |
156 | next = qe->next; | 158 | next = qe->next; |
157 | switch (qe->priority) | 159 | switch (qe->priority) |
158 | { | 160 | { |
159 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: | 161 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: |
160 | run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); | 162 | run_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2); |
161 | end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time); | 163 | end_time = GNUNET_TIME_absolute_add(qe->start_time, run_time); |
162 | rst = GNUNET_TIME_absolute_get_remaining (end_time); | 164 | rst = GNUNET_TIME_absolute_get_remaining(end_time); |
163 | if (0 == rst.rel_value_us) | 165 | if (0 == rst.rel_value_us) |
164 | { | 166 | { |
165 | num_probes_expired++; | 167 | num_probes_expired++; |
166 | stop_job (qe); | 168 | stop_job(qe); |
167 | } | 169 | } |
168 | else | 170 | else |
169 | { | 171 | { |
170 | num_probes_active++; | 172 | num_probes_active++; |
171 | restart_at = GNUNET_TIME_relative_min (rst, restart_at); | 173 | restart_at = GNUNET_TIME_relative_min(rst, restart_at); |
172 | } | 174 | } |
173 | break; | 175 | break; |
174 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: | 176 | |
175 | run_time = | 177 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: |
176 | GNUNET_TIME_relative_saturating_multiply (h->avg_block_latency, | 178 | run_time = |
177 | qe->blocks * qe->start_times); | 179 | GNUNET_TIME_relative_saturating_multiply(h->avg_block_latency, |
178 | end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time); | 180 | qe->blocks * qe->start_times); |
179 | rst = GNUNET_TIME_absolute_get_remaining (end_time); | 181 | end_time = GNUNET_TIME_absolute_add(qe->start_time, run_time); |
180 | if (0 == rst.rel_value_us) | 182 | rst = GNUNET_TIME_absolute_get_remaining(end_time); |
181 | { | 183 | if (0 == rst.rel_value_us) |
182 | num_downloads_expired++; | 184 | { |
183 | stop_job (qe); | 185 | num_downloads_expired++; |
184 | } | 186 | stop_job(qe); |
185 | else | 187 | } |
186 | { | 188 | else |
187 | num_downloads_active++; | 189 | { |
188 | restart_at = GNUNET_TIME_relative_min (rst, restart_at); | 190 | num_downloads_active++; |
189 | } | 191 | restart_at = GNUNET_TIME_relative_min(rst, restart_at); |
190 | break; | 192 | } |
191 | default: | 193 | break; |
192 | GNUNET_break (0); | 194 | |
193 | break; | 195 | default: |
196 | GNUNET_break(0); | ||
197 | break; | ||
198 | } | ||
194 | } | 199 | } |
195 | } | 200 | GNUNET_break(h->active_downloads == |
196 | GNUNET_break (h->active_downloads == | 201 | num_downloads_active + num_probes_active); |
197 | num_downloads_active + num_probes_active); | 202 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 203 | "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", |
199 | "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", | 204 | num_probes_active, |
200 | num_probes_active, | 205 | num_probes_expired, |
201 | num_probes_expired, | 206 | num_probes_waiting, |
202 | num_probes_waiting, | 207 | num_downloads_active, |
203 | num_downloads_active, | 208 | num_downloads_expired, |
204 | num_downloads_expired, | 209 | num_downloads_waiting); |
205 | num_downloads_waiting); | 210 | GNUNET_break(h->active_downloads + num_probes_active <= |
206 | GNUNET_break (h->active_downloads + num_probes_active <= | 211 | h->max_parallel_downloads); |
207 | h->max_parallel_downloads); | ||
208 | /* calculate start/stop decisions */ | 212 | /* calculate start/stop decisions */ |
209 | if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads) | 213 | if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads) |
210 | { | 214 | { |
211 | /* stop as many probes as there are downloads and probes */ | 215 | /* stop as many probes as there are downloads and probes */ |
212 | num_probes_change = -GNUNET_MIN (num_probes_active, num_downloads_waiting); | 216 | num_probes_change = -GNUNET_MIN(num_probes_active, num_downloads_waiting); |
213 | /* start as many downloads as there are free slots, including those | 217 | /* start as many downloads as there are free slots, including those |
214 | we just opened up */ | 218 | we just opened up */ |
215 | num_downloads_change = | 219 | num_downloads_change = |
216 | h->max_parallel_downloads - h->active_downloads - num_probes_change; | 220 | h->max_parallel_downloads - h->active_downloads - num_probes_change; |
217 | } | 221 | } |
218 | else | 222 | else |
219 | { | 223 | { |
220 | /* start all downloads (we can) */ | 224 | /* start all downloads (we can) */ |
221 | num_downloads_change = num_downloads_waiting; | 225 | num_downloads_change = num_downloads_waiting; |
222 | /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */ | 226 | /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */ |
223 | if (1 + h->max_parallel_downloads / 4 >= | 227 | if (1 + h->max_parallel_downloads / 4 >= |
224 | (h->active_downloads + num_downloads_change)) | 228 | (h->active_downloads + num_downloads_change)) |
225 | num_probes_change = | 229 | num_probes_change = |
226 | GNUNET_MIN (num_probes_waiting, | 230 | GNUNET_MIN(num_probes_waiting, |
227 | (1 + h->max_parallel_downloads / 4) - | 231 | (1 + h->max_parallel_downloads / 4) - |
228 | (h->active_downloads + num_downloads_change)); | 232 | (h->active_downloads + num_downloads_change)); |
229 | else | 233 | else |
230 | num_probes_change = 0; | 234 | num_probes_change = 0; |
231 | } | 235 | } |
232 | GNUNET_break (num_downloads_change <= num_downloads_waiting); | 236 | GNUNET_break(num_downloads_change <= num_downloads_waiting); |
233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 237 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
234 | "Changing %d probes and %d/%u/%u downloads\n", | 238 | "Changing %d probes and %d/%u/%u downloads\n", |
235 | num_probes_change, | 239 | num_probes_change, |
236 | num_downloads_change, | 240 | num_downloads_change, |
237 | (unsigned int) h->active_downloads, | 241 | (unsigned int)h->active_downloads, |
238 | (unsigned int) h->max_parallel_downloads); | 242 | (unsigned int)h->max_parallel_downloads); |
239 | /* actually stop probes */ | 243 | /* actually stop probes */ |
240 | next = h->running_head; | 244 | next = h->running_head; |
241 | while (NULL != (qe = next)) | 245 | while (NULL != (qe = next)) |
242 | { | ||
243 | next = qe->next; | ||
244 | if (GNUNET_FS_QUEUE_PRIORITY_PROBE != qe->priority) | ||
245 | continue; | ||
246 | if (num_probes_change < 0) | ||
247 | { | 246 | { |
248 | stop_job (qe); | 247 | next = qe->next; |
249 | num_probes_change++; | 248 | if (GNUNET_FS_QUEUE_PRIORITY_PROBE != qe->priority) |
250 | if (0 == num_probes_change) | 249 | continue; |
251 | break; | 250 | if (num_probes_change < 0) |
251 | { | ||
252 | stop_job(qe); | ||
253 | num_probes_change++; | ||
254 | if (0 == num_probes_change) | ||
255 | break; | ||
256 | } | ||
252 | } | 257 | } |
253 | } | 258 | GNUNET_break(0 <= num_probes_change); |
254 | GNUNET_break (0 <= num_probes_change); | ||
255 | 259 | ||
256 | /* start some more tasks if we now have empty slots */ | 260 | /* start some more tasks if we now have empty slots */ |
257 | block_limit_hit = GNUNET_NO; | 261 | block_limit_hit = GNUNET_NO; |
258 | next = h->pending_head; | 262 | next = h->pending_head; |
259 | while ((NULL != (qe = next)) && | 263 | while ((NULL != (qe = next)) && |
260 | ((num_probes_change > 0) || (num_downloads_change > 0))) | 264 | ((num_probes_change > 0) || (num_downloads_change > 0))) |
261 | { | 265 | { |
262 | next = qe->next; | 266 | next = qe->next; |
263 | switch (qe->priority) | 267 | switch (qe->priority) |
264 | { | 268 | { |
265 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: | 269 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: |
266 | if (num_probes_change > 0) | 270 | if (num_probes_change > 0) |
267 | { | 271 | { |
268 | start_job (qe); | 272 | start_job(qe); |
269 | num_probes_change--; | 273 | num_probes_change--; |
270 | run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); | 274 | run_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2); |
271 | restart_at = GNUNET_TIME_relative_min (run_time, restart_at); | 275 | restart_at = GNUNET_TIME_relative_min(run_time, restart_at); |
272 | } | 276 | } |
273 | break; | 277 | break; |
274 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: | 278 | |
275 | if ((num_downloads_change > 0) && | 279 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: |
276 | ((qe->blocks + h->active_blocks <= h->max_parallel_requests) || | 280 | if ((num_downloads_change > 0) && |
277 | ((qe->blocks > h->max_parallel_requests) && | 281 | ((qe->blocks + h->active_blocks <= h->max_parallel_requests) || |
278 | (0 == h->active_downloads)))) | 282 | ((qe->blocks > h->max_parallel_requests) && |
279 | { | 283 | (0 == h->active_downloads)))) |
280 | start_job (qe); | 284 | { |
281 | num_downloads_change--; | 285 | start_job(qe); |
282 | } | 286 | num_downloads_change--; |
283 | else if (num_downloads_change > 0) | 287 | } |
284 | block_limit_hit = GNUNET_YES; | 288 | else if (num_downloads_change > 0) |
285 | break; | 289 | block_limit_hit = GNUNET_YES; |
286 | default: | 290 | break; |
287 | GNUNET_break (0); | 291 | |
288 | break; | 292 | default: |
293 | GNUNET_break(0); | ||
294 | break; | ||
295 | } | ||
289 | } | 296 | } |
290 | } | 297 | GNUNET_break((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit)); |
291 | GNUNET_break ((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit)); | 298 | GNUNET_break(0 == num_probes_change); |
292 | GNUNET_break (0 == num_probes_change); | ||
293 | 299 | ||
294 | GNUNET_log ( | 300 | GNUNET_log( |
295 | GNUNET_ERROR_TYPE_DEBUG, | 301 | GNUNET_ERROR_TYPE_DEBUG, |
296 | "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n", | 302 | "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n", |
297 | h->active_downloads, | 303 | h->active_downloads, |
298 | h->max_parallel_requests, | 304 | h->max_parallel_requests, |
299 | num_probes_change, | 305 | num_probes_change, |
300 | num_downloads_change, | 306 | num_downloads_change, |
301 | GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES)); | 307 | GNUNET_STRINGS_relative_time_to_string(restart_at, GNUNET_YES)); |
302 | 308 | ||
303 | /* make sure we run again, callbacks might have | 309 | /* make sure we run again, callbacks might have |
304 | already re-scheduled the job, so cancel such | 310 | already re-scheduled the job, so cancel such |
305 | an operation (if it exists) */ | 311 | an operation (if it exists) */ |
306 | if (NULL != h->queue_job) | 312 | if (NULL != h->queue_job) |
307 | GNUNET_SCHEDULER_cancel (h->queue_job); | 313 | GNUNET_SCHEDULER_cancel(h->queue_job); |
308 | h->queue_job = | 314 | h->queue_job = |
309 | GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h); | 315 | GNUNET_SCHEDULER_add_delayed(restart_at, &process_job_queue, h); |
310 | } | 316 | } |
311 | 317 | ||
312 | 318 | ||
@@ -322,31 +328,31 @@ process_job_queue (void *cls) | |||
322 | * @return queue handle | 328 | * @return queue handle |
323 | */ | 329 | */ |
324 | struct GNUNET_FS_QueueEntry * | 330 | struct GNUNET_FS_QueueEntry * |
325 | GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, | 331 | GNUNET_FS_queue_(struct GNUNET_FS_Handle *h, |
326 | GNUNET_SCHEDULER_TaskCallback start, | 332 | GNUNET_SCHEDULER_TaskCallback start, |
327 | GNUNET_SCHEDULER_TaskCallback stop, | 333 | GNUNET_SCHEDULER_TaskCallback stop, |
328 | void *cls, | 334 | void *cls, |
329 | unsigned int blocks, | 335 | unsigned int blocks, |
330 | enum GNUNET_FS_QueuePriority priority) | 336 | enum GNUNET_FS_QueuePriority priority) |
331 | { | 337 | { |
332 | struct GNUNET_FS_QueueEntry *qe; | 338 | struct GNUNET_FS_QueueEntry *qe; |
333 | 339 | ||
334 | qe = GNUNET_new (struct GNUNET_FS_QueueEntry); | 340 | qe = GNUNET_new(struct GNUNET_FS_QueueEntry); |
335 | qe->h = h; | 341 | qe->h = h; |
336 | qe->start = start; | 342 | qe->start = start; |
337 | qe->stop = stop; | 343 | qe->stop = stop; |
338 | qe->cls = cls; | 344 | qe->cls = cls; |
339 | qe->queue_time = GNUNET_TIME_absolute_get (); | 345 | qe->queue_time = GNUNET_TIME_absolute_get(); |
340 | qe->blocks = blocks; | 346 | qe->blocks = blocks; |
341 | qe->priority = priority; | 347 | qe->priority = priority; |
342 | GNUNET_CONTAINER_DLL_insert_after (h->pending_head, | 348 | GNUNET_CONTAINER_DLL_insert_after(h->pending_head, |
343 | h->pending_tail, | 349 | h->pending_tail, |
344 | h->pending_tail, | 350 | h->pending_tail, |
345 | qe); | 351 | qe); |
346 | if (NULL != h->queue_job) | 352 | if (NULL != h->queue_job) |
347 | GNUNET_SCHEDULER_cancel (h->queue_job); | 353 | GNUNET_SCHEDULER_cancel(h->queue_job); |
348 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); | 354 | h->queue_job = GNUNET_SCHEDULER_add_now(&process_job_queue, h); |
349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe); | 355 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe); |
350 | return qe; | 356 | return qe; |
351 | } | 357 | } |
352 | 358 | ||
@@ -357,19 +363,19 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, | |||
357 | * @param qe handle for the job | 363 | * @param qe handle for the job |
358 | */ | 364 | */ |
359 | void | 365 | void |
360 | GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe) | 366 | GNUNET_FS_dequeue_(struct GNUNET_FS_QueueEntry *qe) |
361 | { | 367 | { |
362 | struct GNUNET_FS_Handle *h; | 368 | struct GNUNET_FS_Handle *h; |
363 | 369 | ||
364 | h = qe->h; | 370 | h = qe->h; |
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe); | 371 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe); |
366 | if (GNUNET_YES == qe->active) | 372 | if (GNUNET_YES == qe->active) |
367 | stop_job (qe); | 373 | stop_job(qe); |
368 | GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qe); | 374 | GNUNET_CONTAINER_DLL_remove(h->pending_head, h->pending_tail, qe); |
369 | GNUNET_free (qe); | 375 | GNUNET_free(qe); |
370 | if (NULL != h->queue_job) | 376 | if (NULL != h->queue_job) |
371 | GNUNET_SCHEDULER_cancel (h->queue_job); | 377 | GNUNET_SCHEDULER_cancel(h->queue_job); |
372 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); | 378 | h->queue_job = GNUNET_SCHEDULER_add_now(&process_job_queue, h); |
373 | } | 379 | } |
374 | 380 | ||
375 | 381 | ||
@@ -382,16 +388,16 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe) | |||
382 | * @return fresh top-level activity handle | 388 | * @return fresh top-level activity handle |
383 | */ | 389 | */ |
384 | struct TopLevelActivity * | 390 | struct TopLevelActivity * |
385 | GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, | 391 | GNUNET_FS_make_top(struct GNUNET_FS_Handle *h, |
386 | SuspendSignalFunction ssf, | 392 | SuspendSignalFunction ssf, |
387 | void *ssf_cls) | 393 | void *ssf_cls) |
388 | { | 394 | { |
389 | struct TopLevelActivity *ret; | 395 | struct TopLevelActivity *ret; |
390 | 396 | ||
391 | ret = GNUNET_new (struct TopLevelActivity); | 397 | ret = GNUNET_new(struct TopLevelActivity); |
392 | ret->ssf = ssf; | 398 | ret->ssf = ssf; |
393 | ret->ssf_cls = ssf_cls; | 399 | ret->ssf_cls = ssf_cls; |
394 | GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret); | 400 | GNUNET_CONTAINER_DLL_insert(h->top_head, h->top_tail, ret); |
395 | return ret; | 401 | return ret; |
396 | } | 402 | } |
397 | 403 | ||
@@ -403,18 +409,17 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, | |||
403 | * @param top top level activity entry | 409 | * @param top top level activity entry |
404 | */ | 410 | */ |
405 | void | 411 | void |
406 | GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top) | 412 | GNUNET_FS_end_top(struct GNUNET_FS_Handle *h, struct TopLevelActivity *top) |
407 | { | 413 | { |
408 | GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top); | 414 | GNUNET_CONTAINER_DLL_remove(h->top_head, h->top_tail, top); |
409 | GNUNET_free (top); | 415 | GNUNET_free(top); |
410 | } | 416 | } |
411 | 417 | ||
412 | 418 | ||
413 | /** | 419 | /** |
414 | * Closure for #GNUNET_FS_data_reader_file_(). | 420 | * Closure for #GNUNET_FS_data_reader_file_(). |
415 | */ | 421 | */ |
416 | struct FileInfo | 422 | struct FileInfo { |
417 | { | ||
418 | /** | 423 | /** |
419 | * Name of the file to read. | 424 | * Name of the file to read. |
420 | */ | 425 | */ |
@@ -448,63 +453,63 @@ struct FileInfo | |||
448 | * @return number of bytes written, usually @a max, 0 on error | 453 | * @return number of bytes written, usually @a max, 0 on error |
449 | */ | 454 | */ |
450 | size_t | 455 | size_t |
451 | GNUNET_FS_data_reader_file_ (void *cls, | 456 | GNUNET_FS_data_reader_file_(void *cls, |
452 | uint64_t offset, | 457 | uint64_t offset, |
453 | size_t max, | 458 | size_t max, |
454 | void *buf, | 459 | void *buf, |
455 | char **emsg) | 460 | char **emsg) |
456 | { | 461 | { |
457 | struct FileInfo *fi = cls; | 462 | struct FileInfo *fi = cls; |
458 | ssize_t ret; | 463 | ssize_t ret; |
459 | 464 | ||
460 | if (UINT64_MAX == offset) | 465 | if (UINT64_MAX == offset) |
461 | { | ||
462 | if (NULL != fi->fd) | ||
463 | { | 466 | { |
464 | GNUNET_DISK_file_close (fi->fd); | 467 | if (NULL != fi->fd) |
465 | fi->fd = NULL; | 468 | { |
469 | GNUNET_DISK_file_close(fi->fd); | ||
470 | fi->fd = NULL; | ||
471 | } | ||
472 | return 0; | ||
466 | } | 473 | } |
467 | return 0; | ||
468 | } | ||
469 | if (0 == max) | 474 | if (0 == max) |
470 | { | 475 | { |
471 | if (NULL != fi->fd) | 476 | if (NULL != fi->fd) |
472 | GNUNET_DISK_file_close (fi->fd); | 477 | GNUNET_DISK_file_close(fi->fd); |
473 | GNUNET_free (fi->filename); | 478 | GNUNET_free(fi->filename); |
474 | GNUNET_free (fi); | 479 | GNUNET_free(fi); |
475 | return 0; | ||
476 | } | ||
477 | if (NULL == fi->fd) | ||
478 | { | ||
479 | fi->fd = GNUNET_DISK_file_open (fi->filename, | ||
480 | GNUNET_DISK_OPEN_READ, | ||
481 | GNUNET_DISK_PERM_NONE); | ||
482 | if (NULL == fi->fd) | ||
483 | { | ||
484 | GNUNET_asprintf (emsg, | ||
485 | _ ("Could not open file `%s': %s"), | ||
486 | fi->filename, | ||
487 | strerror (errno)); | ||
488 | return 0; | 480 | return 0; |
489 | } | 481 | } |
490 | } | 482 | if (NULL == fi->fd) |
483 | { | ||
484 | fi->fd = GNUNET_DISK_file_open(fi->filename, | ||
485 | GNUNET_DISK_OPEN_READ, | ||
486 | GNUNET_DISK_PERM_NONE); | ||
487 | if (NULL == fi->fd) | ||
488 | { | ||
489 | GNUNET_asprintf(emsg, | ||
490 | _("Could not open file `%s': %s"), | ||
491 | fi->filename, | ||
492 | strerror(errno)); | ||
493 | return 0; | ||
494 | } | ||
495 | } | ||
491 | if ((GNUNET_SYSERR == | 496 | if ((GNUNET_SYSERR == |
492 | GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) || | 497 | GNUNET_DISK_file_seek(fi->fd, offset, GNUNET_DISK_SEEK_SET)) || |
493 | (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max)))) | 498 | (-1 == (ret = GNUNET_DISK_file_read(fi->fd, buf, max)))) |
494 | { | 499 | { |
495 | GNUNET_asprintf (emsg, | 500 | GNUNET_asprintf(emsg, |
496 | _ ("Could not read file `%s': %s"), | 501 | _("Could not read file `%s': %s"), |
497 | fi->filename, | 502 | fi->filename, |
498 | strerror (errno)); | 503 | strerror(errno)); |
499 | return 0; | 504 | return 0; |
500 | } | 505 | } |
501 | if (ret != max) | 506 | if (ret != max) |
502 | { | 507 | { |
503 | GNUNET_asprintf (emsg, | 508 | GNUNET_asprintf(emsg, |
504 | _ ("Short read reading from file `%s'!"), | 509 | _("Short read reading from file `%s'!"), |
505 | fi->filename); | 510 | fi->filename); |
506 | return 0; | 511 | return 0; |
507 | } | 512 | } |
508 | return max; | 513 | return max; |
509 | } | 514 | } |
510 | 515 | ||
@@ -516,17 +521,17 @@ GNUNET_FS_data_reader_file_ (void *cls, | |||
516 | * @return closure to use, NULL on error | 521 | * @return closure to use, NULL on error |
517 | */ | 522 | */ |
518 | void * | 523 | void * |
519 | GNUNET_FS_make_file_reader_context_ (const char *filename) | 524 | GNUNET_FS_make_file_reader_context_(const char *filename) |
520 | { | 525 | { |
521 | struct FileInfo *fi; | 526 | struct FileInfo *fi; |
522 | 527 | ||
523 | fi = GNUNET_new (struct FileInfo); | 528 | fi = GNUNET_new(struct FileInfo); |
524 | fi->filename = GNUNET_STRINGS_filename_expand (filename); | 529 | fi->filename = GNUNET_STRINGS_filename_expand(filename); |
525 | if (NULL == fi->filename) | 530 | if (NULL == fi->filename) |
526 | { | 531 | { |
527 | GNUNET_free (fi); | 532 | GNUNET_free(fi); |
528 | return NULL; | 533 | return NULL; |
529 | } | 534 | } |
530 | return fi; | 535 | return fi; |
531 | } | 536 | } |
532 | 537 | ||
@@ -552,22 +557,22 @@ GNUNET_FS_make_file_reader_context_ (const char *filename) | |||
552 | * @return number of bytes written, usually @a max, 0 on error | 557 | * @return number of bytes written, usually @a max, 0 on error |
553 | */ | 558 | */ |
554 | size_t | 559 | size_t |
555 | GNUNET_FS_data_reader_copy_ (void *cls, | 560 | GNUNET_FS_data_reader_copy_(void *cls, |
556 | uint64_t offset, | 561 | uint64_t offset, |
557 | size_t max, | 562 | size_t max, |
558 | void *buf, | 563 | void *buf, |
559 | char **emsg) | 564 | char **emsg) |
560 | { | 565 | { |
561 | char *data = cls; | 566 | char *data = cls; |
562 | 567 | ||
563 | if (UINT64_MAX == offset) | 568 | if (UINT64_MAX == offset) |
564 | return 0; | 569 | return 0; |
565 | if (0 == max) | 570 | if (0 == max) |
566 | { | 571 | { |
567 | GNUNET_free_non_null (data); | 572 | GNUNET_free_non_null(data); |
568 | return 0; | 573 | return 0; |
569 | } | 574 | } |
570 | GNUNET_memcpy (buf, &data[offset], max); | 575 | GNUNET_memcpy(buf, &data[offset], max); |
571 | return max; | 576 | return max; |
572 | } | 577 | } |
573 | 578 | ||
@@ -582,30 +587,30 @@ GNUNET_FS_data_reader_copy_ (void *cls, | |||
582 | * @return NULL on error | 587 | * @return NULL on error |
583 | */ | 588 | */ |
584 | static char * | 589 | static char * |
585 | get_serialization_file_name (struct GNUNET_FS_Handle *h, | 590 | get_serialization_file_name(struct GNUNET_FS_Handle *h, |
586 | const char *ext, | 591 | const char *ext, |
587 | const char *ent) | 592 | const char *ent) |
588 | { | 593 | { |
589 | char *basename; | 594 | char *basename; |
590 | char *ret; | 595 | char *ret; |
591 | 596 | ||
592 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 597 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
593 | return NULL; /* persistence not requested */ | 598 | return NULL; /* persistence not requested */ |
594 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, | 599 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(h->cfg, |
595 | "fs", | 600 | "fs", |
596 | "STATE_DIR", | 601 | "STATE_DIR", |
597 | &basename)) | 602 | &basename)) |
598 | return NULL; | 603 | return NULL; |
599 | GNUNET_asprintf (&ret, | 604 | GNUNET_asprintf(&ret, |
600 | "%s%s%s%s%s%s%s", | 605 | "%s%s%s%s%s%s%s", |
601 | basename, | 606 | basename, |
602 | DIR_SEPARATOR_STR, | 607 | DIR_SEPARATOR_STR, |
603 | h->client_name, | 608 | h->client_name, |
604 | DIR_SEPARATOR_STR, | 609 | DIR_SEPARATOR_STR, |
605 | ext, | 610 | ext, |
606 | DIR_SEPARATOR_STR, | 611 | DIR_SEPARATOR_STR, |
607 | ent); | 612 | ent); |
608 | GNUNET_free (basename); | 613 | GNUNET_free(basename); |
609 | return ret; | 614 | return ret; |
610 | } | 615 | } |
611 | 616 | ||
@@ -622,33 +627,33 @@ get_serialization_file_name (struct GNUNET_FS_Handle *h, | |||
622 | * @return NULL on error | 627 | * @return NULL on error |
623 | */ | 628 | */ |
624 | static char * | 629 | static char * |
625 | get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | 630 | get_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, |
626 | const char *ext, | 631 | const char *ext, |
627 | const char *uni, | 632 | const char *uni, |
628 | const char *ent) | 633 | const char *ent) |
629 | { | 634 | { |
630 | char *basename; | 635 | char *basename; |
631 | char *ret; | 636 | char *ret; |
632 | 637 | ||
633 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 638 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
634 | return NULL; /* persistence not requested */ | 639 | return NULL; /* persistence not requested */ |
635 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, | 640 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(h->cfg, |
636 | "fs", | 641 | "fs", |
637 | "STATE_DIR", | 642 | "STATE_DIR", |
638 | &basename)) | 643 | &basename)) |
639 | return NULL; | 644 | return NULL; |
640 | GNUNET_asprintf (&ret, | 645 | GNUNET_asprintf(&ret, |
641 | "%s%s%s%s%s%s%s.dir%s%s", | 646 | "%s%s%s%s%s%s%s.dir%s%s", |
642 | basename, | 647 | basename, |
643 | DIR_SEPARATOR_STR, | 648 | DIR_SEPARATOR_STR, |
644 | h->client_name, | 649 | h->client_name, |
645 | DIR_SEPARATOR_STR, | 650 | DIR_SEPARATOR_STR, |
646 | ext, | 651 | ext, |
647 | DIR_SEPARATOR_STR, | 652 | DIR_SEPARATOR_STR, |
648 | uni, | 653 | uni, |
649 | DIR_SEPARATOR_STR, | 654 | DIR_SEPARATOR_STR, |
650 | ent); | 655 | ent); |
651 | GNUNET_free (basename); | 656 | GNUNET_free(basename); |
652 | return ret; | 657 | return ret; |
653 | } | 658 | } |
654 | 659 | ||
@@ -662,16 +667,16 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
662 | * @return NULL on error | 667 | * @return NULL on error |
663 | */ | 668 | */ |
664 | static struct GNUNET_BIO_ReadHandle * | 669 | static struct GNUNET_BIO_ReadHandle * |
665 | get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) | 670 | get_read_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent) |
666 | { | 671 | { |
667 | char *fn; | 672 | char *fn; |
668 | struct GNUNET_BIO_ReadHandle *ret; | 673 | struct GNUNET_BIO_ReadHandle *ret; |
669 | 674 | ||
670 | fn = get_serialization_file_name (h, ext, ent); | 675 | fn = get_serialization_file_name(h, ext, ent); |
671 | if (NULL == fn) | 676 | if (NULL == fn) |
672 | return NULL; | 677 | return NULL; |
673 | ret = GNUNET_BIO_read_open (fn); | 678 | ret = GNUNET_BIO_read_open(fn); |
674 | GNUNET_free (fn); | 679 | GNUNET_free(fn); |
675 | return ret; | 680 | return ret; |
676 | } | 681 | } |
677 | 682 | ||
@@ -685,17 +690,17 @@ get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) | |||
685 | * @return NULL on error | 690 | * @return NULL on error |
686 | */ | 691 | */ |
687 | static struct GNUNET_BIO_WriteHandle * | 692 | static struct GNUNET_BIO_WriteHandle * |
688 | get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) | 693 | get_write_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent) |
689 | { | 694 | { |
690 | char *fn; | 695 | char *fn; |
691 | struct GNUNET_BIO_WriteHandle *ret; | 696 | struct GNUNET_BIO_WriteHandle *ret; |
692 | 697 | ||
693 | fn = get_serialization_file_name (h, ext, ent); | 698 | fn = get_serialization_file_name(h, ext, ent); |
694 | if (NULL == fn) | 699 | if (NULL == fn) |
695 | return NULL; | 700 | return NULL; |
696 | ret = GNUNET_BIO_write_open (fn); | 701 | ret = GNUNET_BIO_write_open(fn); |
697 | GNUNET_break (NULL != ret); | 702 | GNUNET_break(NULL != ret); |
698 | GNUNET_free (fn); | 703 | GNUNET_free(fn); |
699 | return ret; | 704 | return ret; |
700 | } | 705 | } |
701 | 706 | ||
@@ -710,19 +715,19 @@ get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) | |||
710 | * @return NULL on error | 715 | * @return NULL on error |
711 | */ | 716 | */ |
712 | static struct GNUNET_BIO_WriteHandle * | 717 | static struct GNUNET_BIO_WriteHandle * |
713 | get_write_handle_in_dir (struct GNUNET_FS_Handle *h, | 718 | get_write_handle_in_dir(struct GNUNET_FS_Handle *h, |
714 | const char *ext, | 719 | const char *ext, |
715 | const char *uni, | 720 | const char *uni, |
716 | const char *ent) | 721 | const char *ent) |
717 | { | 722 | { |
718 | char *fn; | 723 | char *fn; |
719 | struct GNUNET_BIO_WriteHandle *ret; | 724 | struct GNUNET_BIO_WriteHandle *ret; |
720 | 725 | ||
721 | fn = get_serialization_file_name_in_dir (h, ext, uni, ent); | 726 | fn = get_serialization_file_name_in_dir(h, ext, uni, ent); |
722 | if (NULL == fn) | 727 | if (NULL == fn) |
723 | return NULL; | 728 | return NULL; |
724 | ret = GNUNET_BIO_write_open (fn); | 729 | ret = GNUNET_BIO_write_open(fn); |
725 | GNUNET_free (fn); | 730 | GNUNET_free(fn); |
726 | return ret; | 731 | return ret; |
727 | } | 732 | } |
728 | 733 | ||
@@ -735,24 +740,24 @@ get_write_handle_in_dir (struct GNUNET_FS_Handle *h, | |||
735 | * @param ent entity identifier | 740 | * @param ent entity identifier |
736 | */ | 741 | */ |
737 | void | 742 | void |
738 | GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, | 743 | GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, |
739 | const char *ext, | 744 | const char *ext, |
740 | const char *ent) | 745 | const char *ent) |
741 | { | 746 | { |
742 | char *filename; | 747 | char *filename; |
743 | 748 | ||
744 | if ((NULL == ent) || (0 == strlen (ent))) | 749 | if ((NULL == ent) || (0 == strlen(ent))) |
745 | { | 750 | { |
746 | GNUNET_break (0); | 751 | GNUNET_break(0); |
747 | return; | 752 | return; |
748 | } | 753 | } |
749 | filename = get_serialization_file_name (h, ext, ent); | 754 | filename = get_serialization_file_name(h, ext, ent); |
750 | if (NULL != filename) | 755 | if (NULL != filename) |
751 | { | 756 | { |
752 | if ((0 != unlink (filename)) && (ENOENT != errno)) | 757 | if ((0 != unlink(filename)) && (ENOENT != errno)) |
753 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 758 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
754 | GNUNET_free (filename); | 759 | GNUNET_free(filename); |
755 | } | 760 | } |
756 | } | 761 | } |
757 | 762 | ||
758 | 763 | ||
@@ -765,24 +770,24 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, | |||
765 | * @param ent entity identifier | 770 | * @param ent entity identifier |
766 | */ | 771 | */ |
767 | static void | 772 | static void |
768 | remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, | 773 | remove_sync_file_in_dir(struct GNUNET_FS_Handle *h, |
769 | const char *ext, | 774 | const char *ext, |
770 | const char *uni, | 775 | const char *uni, |
771 | const char *ent) | 776 | const char *ent) |
772 | { | 777 | { |
773 | char *filename; | 778 | char *filename; |
774 | 779 | ||
775 | if ((NULL == ent) || (0 == strlen (ent))) | 780 | if ((NULL == ent) || (0 == strlen(ent))) |
776 | { | 781 | { |
777 | GNUNET_break (0); | 782 | GNUNET_break(0); |
778 | return; | 783 | return; |
779 | } | 784 | } |
780 | filename = get_serialization_file_name_in_dir (h, ext, uni, ent); | 785 | filename = get_serialization_file_name_in_dir(h, ext, uni, ent); |
781 | if (NULL == filename) | 786 | if (NULL == filename) |
782 | return; | 787 | return; |
783 | if (0 != unlink (filename)) | 788 | if (0 != unlink(filename)) |
784 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 789 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
785 | GNUNET_free (filename); | 790 | GNUNET_free(filename); |
786 | } | 791 | } |
787 | 792 | ||
788 | 793 | ||
@@ -794,21 +799,21 @@ remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, | |||
794 | * @param uni unique name of parent | 799 | * @param uni unique name of parent |
795 | */ | 800 | */ |
796 | void | 801 | void |
797 | GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, | 802 | GNUNET_FS_remove_sync_dir_(struct GNUNET_FS_Handle *h, |
798 | const char *ext, | 803 | const char *ext, |
799 | const char *uni) | 804 | const char *uni) |
800 | { | 805 | { |
801 | char *dn; | 806 | char *dn; |
802 | 807 | ||
803 | if (NULL == uni) | 808 | if (NULL == uni) |
804 | return; | 809 | return; |
805 | dn = get_serialization_file_name_in_dir (h, ext, uni, ""); | 810 | dn = get_serialization_file_name_in_dir(h, ext, uni, ""); |
806 | if (NULL == dn) | 811 | if (NULL == dn) |
807 | return; | 812 | return; |
808 | if ((GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) && | 813 | if ((GNUNET_YES == GNUNET_DISK_directory_test(dn, GNUNET_YES)) && |
809 | (GNUNET_OK != GNUNET_DISK_directory_remove (dn))) | 814 | (GNUNET_OK != GNUNET_DISK_directory_remove(dn))) |
810 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", dn); | 815 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "rmdir", dn); |
811 | GNUNET_free (dn); | 816 | GNUNET_free(dn); |
812 | } | 817 | } |
813 | 818 | ||
814 | 819 | ||
@@ -827,13 +832,13 @@ GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, | |||
827 | * @return #GNUNET_OK on success | 832 | * @return #GNUNET_OK on success |
828 | */ | 833 | */ |
829 | static int | 834 | static int |
830 | write_start_time (struct GNUNET_BIO_WriteHandle *wh, | 835 | write_start_time(struct GNUNET_BIO_WriteHandle *wh, |
831 | struct GNUNET_TIME_Absolute timestamp) | 836 | struct GNUNET_TIME_Absolute timestamp) |
832 | { | 837 | { |
833 | struct GNUNET_TIME_Relative dur; | 838 | struct GNUNET_TIME_Relative dur; |
834 | 839 | ||
835 | dur = GNUNET_TIME_absolute_get_duration (timestamp); | 840 | dur = GNUNET_TIME_absolute_get_duration(timestamp); |
836 | return GNUNET_BIO_write_int64 (wh, dur.rel_value_us); | 841 | return GNUNET_BIO_write_int64(wh, dur.rel_value_us); |
837 | } | 842 | } |
838 | 843 | ||
839 | 844 | ||
@@ -852,14 +857,14 @@ write_start_time (struct GNUNET_BIO_WriteHandle *wh, | |||
852 | * @return #GNUNET_OK on success | 857 | * @return #GNUNET_OK on success |
853 | */ | 858 | */ |
854 | static int | 859 | static int |
855 | read_start_time (struct GNUNET_BIO_ReadHandle *rh, | 860 | read_start_time(struct GNUNET_BIO_ReadHandle *rh, |
856 | struct GNUNET_TIME_Absolute *timestamp) | 861 | struct GNUNET_TIME_Absolute *timestamp) |
857 | { | 862 | { |
858 | struct GNUNET_TIME_Relative dur; | 863 | struct GNUNET_TIME_Relative dur; |
859 | 864 | ||
860 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dur.rel_value_us)) | 865 | if (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dur.rel_value_us)) |
861 | return GNUNET_SYSERR; | 866 | return GNUNET_SYSERR; |
862 | *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), dur); | 867 | *timestamp = GNUNET_TIME_absolute_subtract(GNUNET_TIME_absolute_get(), dur); |
863 | return GNUNET_OK; | 868 | return GNUNET_OK; |
864 | } | 869 | } |
865 | 870 | ||
@@ -874,7 +879,7 @@ read_start_time (struct GNUNET_BIO_ReadHandle *rh, | |||
874 | * @return NULL on error | 879 | * @return NULL on error |
875 | */ | 880 | */ |
876 | static struct GNUNET_FS_FileInformation * | 881 | static struct GNUNET_FS_FileInformation * |
877 | deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename); | 882 | deserialize_file_information(struct GNUNET_FS_Handle *h, const char *filename); |
878 | 883 | ||
879 | 884 | ||
880 | /** | 885 | /** |
@@ -888,9 +893,9 @@ deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename); | |||
888 | * @return NULL on error | 893 | * @return NULL on error |
889 | */ | 894 | */ |
890 | static struct GNUNET_FS_FileInformation * | 895 | static struct GNUNET_FS_FileInformation * |
891 | deserialize_fi_node (struct GNUNET_FS_Handle *h, | 896 | deserialize_fi_node(struct GNUNET_FS_Handle *h, |
892 | const char *fn, | 897 | const char *fn, |
893 | struct GNUNET_BIO_ReadHandle *rh) | 898 | struct GNUNET_BIO_ReadHandle *rh) |
894 | { | 899 | { |
895 | struct GNUNET_FS_FileInformation *ret; | 900 | struct GNUNET_FS_FileInformation *ret; |
896 | struct GNUNET_FS_FileInformation *nxt; | 901 | struct GNUNET_FS_FileInformation *nxt; |
@@ -901,204 +906,209 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
901 | char *filename; | 906 | char *filename; |
902 | uint32_t dsize; | 907 | uint32_t dsize; |
903 | 908 | ||
904 | if (GNUNET_OK != GNUNET_BIO_read (rh, "status flag", &b, sizeof (b))) | 909 | if (GNUNET_OK != GNUNET_BIO_read(rh, "status flag", &b, sizeof(b))) |
905 | { | 910 | { |
906 | GNUNET_break (0); | 911 | GNUNET_break(0); |
907 | return NULL; | 912 | return NULL; |
908 | } | 913 | } |
909 | ret = GNUNET_new (struct GNUNET_FS_FileInformation); | 914 | ret = GNUNET_new(struct GNUNET_FS_FileInformation); |
910 | ret->h = h; | 915 | ret->h = h; |
911 | ksks = NULL; | 916 | ksks = NULL; |
912 | chks = NULL; | 917 | chks = NULL; |
913 | skss = NULL; | 918 | skss = NULL; |
914 | filename = NULL; | 919 | filename = NULL; |
915 | if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) || | 920 | if ((GNUNET_OK != GNUNET_BIO_read_meta_data(rh, "metadata", &ret->meta)) || |
916 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) || | 921 | (GNUNET_OK != GNUNET_BIO_read_string(rh, "ksk-uri", &ksks, 32 * 1024)) || |
917 | ((NULL != ksks) && | 922 | ((NULL != ksks) && |
918 | ((NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) || | 923 | ((NULL == (ret->keywords = GNUNET_FS_uri_parse(ksks, NULL))) || |
919 | (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)))) || | 924 | (GNUNET_YES != GNUNET_FS_uri_test_ksk(ret->keywords)))) || |
920 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) || | 925 | (GNUNET_OK != GNUNET_BIO_read_string(rh, "chk-uri", &chks, 1024)) || |
921 | ((NULL != chks) && | 926 | ((NULL != chks) && |
922 | ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || | 927 | ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse(chks, NULL))) || |
923 | (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) || | 928 | (GNUNET_YES != GNUNET_FS_uri_test_chk(ret->chk_uri)))) || |
924 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) || | 929 | (GNUNET_OK != GNUNET_BIO_read_string(rh, "sks-uri", &skss, 1024)) || |
925 | ((NULL != skss) && | 930 | ((NULL != skss) && |
926 | ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) || | 931 | ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse(skss, NULL))) || |
927 | (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri)))) || | 932 | (GNUNET_YES != GNUNET_FS_uri_test_sks(ret->sks_uri)))) || |
928 | (GNUNET_OK != read_start_time (rh, &ret->start_time)) || | 933 | (GNUNET_OK != read_start_time(rh, &ret->start_time)) || |
929 | (GNUNET_OK != | 934 | (GNUNET_OK != |
930 | GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) || | 935 | GNUNET_BIO_read_string(rh, "emsg", &ret->emsg, 16 * 1024)) || |
931 | (GNUNET_OK != | 936 | (GNUNET_OK != |
932 | GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || | 937 | GNUNET_BIO_read_string(rh, "fn", &ret->filename, 16 * 1024)) || |
933 | (GNUNET_OK != | 938 | (GNUNET_OK != |
934 | GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) || | 939 | GNUNET_BIO_read_int64(rh, &ret->bo.expiration_time.abs_value_us)) || |
935 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || | 940 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &ret->bo.anonymity_level)) || |
936 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) || | 941 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &ret->bo.content_priority)) || |
937 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level))) | 942 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &ret->bo.replication_level))) |
938 | { | ||
939 | GNUNET_break (0); | ||
940 | goto cleanup; | ||
941 | } | ||
942 | switch (b) | ||
943 | { | ||
944 | case 0: /* file-insert */ | ||
945 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) | ||
946 | { | 943 | { |
947 | GNUNET_break (0); | 944 | GNUNET_break(0); |
948 | goto cleanup; | 945 | goto cleanup; |
949 | } | 946 | } |
950 | ret->is_directory = GNUNET_NO; | 947 | switch (b) |
951 | ret->data.file.do_index = GNUNET_NO; | ||
952 | ret->data.file.have_hash = GNUNET_NO; | ||
953 | ret->data.file.index_start_confirmed = GNUNET_NO; | ||
954 | if (GNUNET_NO == ret->is_published) | ||
955 | { | 948 | { |
949 | case 0: /* file-insert */ | ||
950 | if (GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) | ||
951 | { | ||
952 | GNUNET_break(0); | ||
953 | goto cleanup; | ||
954 | } | ||
955 | ret->is_directory = GNUNET_NO; | ||
956 | ret->data.file.do_index = GNUNET_NO; | ||
957 | ret->data.file.have_hash = GNUNET_NO; | ||
958 | ret->data.file.index_start_confirmed = GNUNET_NO; | ||
959 | if (GNUNET_NO == ret->is_published) | ||
960 | { | ||
961 | if (NULL == ret->filename) | ||
962 | { | ||
963 | ret->data.file.reader = &GNUNET_FS_data_reader_copy_; | ||
964 | ret->data.file.reader_cls = | ||
965 | GNUNET_malloc_large(ret->data.file.file_size); | ||
966 | if (ret->data.file.reader_cls == NULL) | ||
967 | goto cleanup; | ||
968 | if (GNUNET_OK != GNUNET_BIO_read(rh, | ||
969 | "file-data", | ||
970 | ret->data.file.reader_cls, | ||
971 | ret->data.file.file_size)) | ||
972 | { | ||
973 | GNUNET_break(0); | ||
974 | goto cleanup; | ||
975 | } | ||
976 | } | ||
977 | else | ||
978 | { | ||
979 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | ||
980 | ret->data.file.reader_cls = | ||
981 | GNUNET_FS_make_file_reader_context_(ret->filename); | ||
982 | } | ||
983 | } | ||
984 | break; | ||
985 | |||
986 | case 1: /* file-index, no hash */ | ||
987 | if (NULL == ret->filename) | ||
988 | { | ||
989 | GNUNET_break(0); | ||
990 | goto cleanup; | ||
991 | } | ||
992 | if (GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) | ||
993 | { | ||
994 | GNUNET_break(0); | ||
995 | goto cleanup; | ||
996 | } | ||
997 | ret->is_directory = GNUNET_NO; | ||
998 | ret->data.file.do_index = GNUNET_YES; | ||
999 | ret->data.file.have_hash = GNUNET_NO; | ||
1000 | ret->data.file.index_start_confirmed = GNUNET_NO; | ||
1001 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | ||
1002 | ret->data.file.reader_cls = | ||
1003 | GNUNET_FS_make_file_reader_context_(ret->filename); | ||
1004 | break; | ||
1005 | |||
1006 | case 2: /* file-index-with-hash */ | ||
956 | if (NULL == ret->filename) | 1007 | if (NULL == ret->filename) |
957 | { | 1008 | { |
958 | ret->data.file.reader = &GNUNET_FS_data_reader_copy_; | 1009 | GNUNET_break(0); |
959 | ret->data.file.reader_cls = | ||
960 | GNUNET_malloc_large (ret->data.file.file_size); | ||
961 | if (ret->data.file.reader_cls == NULL) | ||
962 | goto cleanup; | 1010 | goto cleanup; |
963 | if (GNUNET_OK != GNUNET_BIO_read (rh, | 1011 | } |
964 | "file-data", | 1012 | if ((GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) || |
965 | ret->data.file.reader_cls, | 1013 | (GNUNET_OK != GNUNET_BIO_read(rh, |
966 | ret->data.file.file_size)) | 1014 | "fileid", |
1015 | &ret->data.file.file_id, | ||
1016 | sizeof(struct GNUNET_HashCode)))) | ||
967 | { | 1017 | { |
968 | GNUNET_break (0); | 1018 | GNUNET_break(0); |
969 | goto cleanup; | 1019 | goto cleanup; |
970 | } | 1020 | } |
971 | } | 1021 | ret->is_directory = GNUNET_NO; |
972 | else | 1022 | ret->data.file.do_index = GNUNET_YES; |
973 | { | 1023 | ret->data.file.have_hash = GNUNET_YES; |
974 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 1024 | ret->data.file.index_start_confirmed = GNUNET_NO; |
975 | ret->data.file.reader_cls = | 1025 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; |
976 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 1026 | ret->data.file.reader_cls = |
977 | } | 1027 | GNUNET_FS_make_file_reader_context_(ret->filename); |
978 | } | 1028 | break; |
979 | break; | 1029 | |
980 | case 1: /* file-index, no hash */ | 1030 | case 3: /* file-index-with-hash-confirmed */ |
981 | if (NULL == ret->filename) | 1031 | if (NULL == ret->filename) |
982 | { | 1032 | { |
983 | GNUNET_break (0); | 1033 | GNUNET_break(0); |
984 | goto cleanup; | 1034 | goto cleanup; |
985 | } | 1035 | } |
986 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) | 1036 | if ((GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) || |
987 | { | 1037 | (GNUNET_OK != GNUNET_BIO_read(rh, |
988 | GNUNET_break (0); | 1038 | "fileid", |
989 | goto cleanup; | 1039 | &ret->data.file.file_id, |
990 | } | 1040 | sizeof(struct GNUNET_HashCode)))) |
991 | ret->is_directory = GNUNET_NO; | 1041 | { |
992 | ret->data.file.do_index = GNUNET_YES; | 1042 | GNUNET_break(0); |
993 | ret->data.file.have_hash = GNUNET_NO; | 1043 | goto cleanup; |
994 | ret->data.file.index_start_confirmed = GNUNET_NO; | 1044 | } |
995 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 1045 | ret->is_directory = GNUNET_NO; |
996 | ret->data.file.reader_cls = | 1046 | ret->data.file.do_index = GNUNET_YES; |
997 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 1047 | ret->data.file.have_hash = GNUNET_YES; |
998 | break; | 1048 | ret->data.file.index_start_confirmed = GNUNET_YES; |
999 | case 2: /* file-index-with-hash */ | 1049 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; |
1000 | if (NULL == ret->filename) | 1050 | ret->data.file.reader_cls = |
1001 | { | 1051 | GNUNET_FS_make_file_reader_context_(ret->filename); |
1002 | GNUNET_break (0); | 1052 | break; |
1003 | goto cleanup; | 1053 | |
1004 | } | 1054 | case 4: /* directory */ |
1005 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || | 1055 | ret->is_directory = GNUNET_YES; |
1006 | (GNUNET_OK != GNUNET_BIO_read (rh, | 1056 | if ((GNUNET_OK != GNUNET_BIO_read_int32(rh, &dsize)) || |
1007 | "fileid", | 1057 | (GNUNET_OK != |
1008 | &ret->data.file.file_id, | 1058 | GNUNET_BIO_read_int64(rh, &ret->data.dir.contents_completed)) || |
1009 | sizeof (struct GNUNET_HashCode)))) | 1059 | (GNUNET_OK != |
1010 | { | 1060 | GNUNET_BIO_read_int64(rh, &ret->data.dir.contents_size)) || |
1011 | GNUNET_break (0); | 1061 | (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large(dsize))) || |
1012 | goto cleanup; | 1062 | (GNUNET_OK != |
1013 | } | 1063 | GNUNET_BIO_read(rh, "dir-data", ret->data.dir.dir_data, dsize)) || |
1014 | ret->is_directory = GNUNET_NO; | 1064 | (GNUNET_OK != |
1015 | ret->data.file.do_index = GNUNET_YES; | 1065 | GNUNET_BIO_read_string(rh, "ent-filename", &filename, 16 * 1024))) |
1016 | ret->data.file.have_hash = GNUNET_YES; | 1066 | { |
1017 | ret->data.file.index_start_confirmed = GNUNET_NO; | 1067 | GNUNET_break(0); |
1018 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 1068 | goto cleanup; |
1019 | ret->data.file.reader_cls = | 1069 | } |
1020 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 1070 | ret->data.dir.dir_size = (uint32_t)dsize; |
1021 | break; | 1071 | if (NULL != filename) |
1022 | case 3: /* file-index-with-hash-confirmed */ | 1072 | { |
1023 | if (NULL == ret->filename) | 1073 | ret->data.dir.entries = deserialize_file_information(h, filename); |
1024 | { | 1074 | GNUNET_free(filename); |
1025 | GNUNET_break (0); | 1075 | filename = NULL; |
1076 | nxt = ret->data.dir.entries; | ||
1077 | while (NULL != nxt) | ||
1078 | { | ||
1079 | nxt->dir = ret; | ||
1080 | nxt = nxt->next; | ||
1081 | } | ||
1082 | } | ||
1083 | break; | ||
1084 | |||
1085 | default: | ||
1086 | GNUNET_break(0); | ||
1026 | goto cleanup; | 1087 | goto cleanup; |
1027 | } | 1088 | } |
1028 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || | 1089 | ret->serialization = GNUNET_strdup(fn); |
1029 | (GNUNET_OK != GNUNET_BIO_read (rh, | 1090 | if (GNUNET_OK != |
1030 | "fileid", | 1091 | GNUNET_BIO_read_string(rh, "nxt-filename", &filename, 16 * 1024)) |
1031 | &ret->data.file.file_id, | ||
1032 | sizeof (struct GNUNET_HashCode)))) | ||
1033 | { | 1092 | { |
1034 | GNUNET_break (0); | 1093 | GNUNET_break(0); |
1035 | goto cleanup; | 1094 | goto cleanup; |
1036 | } | 1095 | } |
1037 | ret->is_directory = GNUNET_NO; | 1096 | if (NULL != filename) |
1038 | ret->data.file.do_index = GNUNET_YES; | ||
1039 | ret->data.file.have_hash = GNUNET_YES; | ||
1040 | ret->data.file.index_start_confirmed = GNUNET_YES; | ||
1041 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | ||
1042 | ret->data.file.reader_cls = | ||
1043 | GNUNET_FS_make_file_reader_context_ (ret->filename); | ||
1044 | break; | ||
1045 | case 4: /* directory */ | ||
1046 | ret->is_directory = GNUNET_YES; | ||
1047 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) || | ||
1048 | (GNUNET_OK != | ||
1049 | GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) || | ||
1050 | (GNUNET_OK != | ||
1051 | GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) || | ||
1052 | (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || | ||
1053 | (GNUNET_OK != | ||
1054 | GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || | ||
1055 | (GNUNET_OK != | ||
1056 | GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16 * 1024))) | ||
1057 | { | ||
1058 | GNUNET_break (0); | ||
1059 | goto cleanup; | ||
1060 | } | ||
1061 | ret->data.dir.dir_size = (uint32_t) dsize; | ||
1062 | if (NULL != filename) | ||
1063 | { | 1097 | { |
1064 | ret->data.dir.entries = deserialize_file_information (h, filename); | 1098 | ret->next = deserialize_file_information(h, filename); |
1065 | GNUNET_free (filename); | 1099 | GNUNET_free(filename); |
1066 | filename = NULL; | 1100 | filename = NULL; |
1067 | nxt = ret->data.dir.entries; | 1101 | } |
1068 | while (NULL != nxt) | 1102 | GNUNET_free_non_null(ksks); |
1069 | { | 1103 | GNUNET_free_non_null(skss); |
1070 | nxt->dir = ret; | 1104 | GNUNET_free_non_null(chks); |
1071 | nxt = nxt->next; | ||
1072 | } | ||
1073 | } | ||
1074 | break; | ||
1075 | default: | ||
1076 | GNUNET_break (0); | ||
1077 | goto cleanup; | ||
1078 | } | ||
1079 | ret->serialization = GNUNET_strdup (fn); | ||
1080 | if (GNUNET_OK != | ||
1081 | GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16 * 1024)) | ||
1082 | { | ||
1083 | GNUNET_break (0); | ||
1084 | goto cleanup; | ||
1085 | } | ||
1086 | if (NULL != filename) | ||
1087 | { | ||
1088 | ret->next = deserialize_file_information (h, filename); | ||
1089 | GNUNET_free (filename); | ||
1090 | filename = NULL; | ||
1091 | } | ||
1092 | GNUNET_free_non_null (ksks); | ||
1093 | GNUNET_free_non_null (skss); | ||
1094 | GNUNET_free_non_null (chks); | ||
1095 | return ret; | 1105 | return ret; |
1096 | cleanup: | 1106 | cleanup: |
1097 | GNUNET_free_non_null (ksks); | 1107 | GNUNET_free_non_null(ksks); |
1098 | GNUNET_free_non_null (chks); | 1108 | GNUNET_free_non_null(chks); |
1099 | GNUNET_free_non_null (skss); | 1109 | GNUNET_free_non_null(skss); |
1100 | GNUNET_free_non_null (filename); | 1110 | GNUNET_free_non_null(filename); |
1101 | GNUNET_FS_file_information_destroy (ret, NULL, NULL); | 1111 | GNUNET_FS_file_information_destroy(ret, NULL, NULL); |
1102 | return NULL; | 1112 | return NULL; |
1103 | } | 1113 | } |
1104 | 1114 | ||
@@ -1113,36 +1123,36 @@ cleanup: | |||
1113 | * @return NULL on error | 1123 | * @return NULL on error |
1114 | */ | 1124 | */ |
1115 | static struct GNUNET_FS_FileInformation * | 1125 | static struct GNUNET_FS_FileInformation * |
1116 | deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename) | 1126 | deserialize_file_information(struct GNUNET_FS_Handle *h, const char *filename) |
1117 | { | 1127 | { |
1118 | struct GNUNET_FS_FileInformation *ret; | 1128 | struct GNUNET_FS_FileInformation *ret; |
1119 | struct GNUNET_BIO_ReadHandle *rh; | 1129 | struct GNUNET_BIO_ReadHandle *rh; |
1120 | char *emsg; | 1130 | char *emsg; |
1121 | char *fn; | 1131 | char *fn; |
1122 | 1132 | ||
1123 | rh = get_read_handle (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); | 1133 | rh = get_read_handle(h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); |
1124 | if (NULL == rh) | 1134 | if (NULL == rh) |
1125 | return NULL; | 1135 | return NULL; |
1126 | ret = deserialize_fi_node (h, filename, rh); | 1136 | ret = deserialize_fi_node(h, filename, rh); |
1127 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 1137 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
1128 | { | 1138 | { |
1129 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1139 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1130 | _ ("Failed to resume publishing information `%s': %s\n"), | 1140 | _("Failed to resume publishing information `%s': %s\n"), |
1131 | filename, | 1141 | filename, |
1132 | emsg); | 1142 | emsg); |
1133 | GNUNET_free (emsg); | 1143 | GNUNET_free(emsg); |
1134 | } | 1144 | } |
1135 | if (NULL == ret) | 1145 | if (NULL == ret) |
1136 | { | ||
1137 | fn = | ||
1138 | get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); | ||
1139 | if (NULL != fn) | ||
1140 | { | 1146 | { |
1141 | if (0 != unlink (fn)) | 1147 | fn = |
1142 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 1148 | get_serialization_file_name(h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); |
1143 | GNUNET_free (fn); | 1149 | if (NULL != fn) |
1150 | { | ||
1151 | if (0 != unlink(fn)) | ||
1152 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | ||
1153 | GNUNET_free(fn); | ||
1154 | } | ||
1144 | } | 1155 | } |
1145 | } | ||
1146 | return ret; | 1156 | return ret; |
1147 | } | 1157 | } |
1148 | 1158 | ||
@@ -1156,7 +1166,7 @@ deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename) | |||
1156 | * @return copy of the basename, NULL on error | 1166 | * @return copy of the basename, NULL on error |
1157 | */ | 1167 | */ |
1158 | static char * | 1168 | static char * |
1159 | get_serialization_short_name (const char *fullname) | 1169 | get_serialization_short_name(const char *fullname) |
1160 | { | 1170 | { |
1161 | const char *end; | 1171 | const char *end; |
1162 | const char *nxt; | 1172 | const char *nxt; |
@@ -1166,18 +1176,18 @@ get_serialization_short_name (const char *fullname) | |||
1166 | /* FIXME: we could do this faster since we know | 1176 | /* FIXME: we could do this faster since we know |
1167 | * the length of 'end'... */ | 1177 | * the length of 'end'... */ |
1168 | while ('\0' != *nxt) | 1178 | while ('\0' != *nxt) |
1169 | { | 1179 | { |
1170 | if (DIR_SEPARATOR == *nxt) | 1180 | if (DIR_SEPARATOR == *nxt) |
1171 | end = nxt + 1; | 1181 | end = nxt + 1; |
1172 | nxt++; | 1182 | nxt++; |
1173 | } | 1183 | } |
1174 | if ((NULL == end) || (0 == strlen (end))) | 1184 | if ((NULL == end) || (0 == strlen(end))) |
1175 | { | 1185 | { |
1176 | GNUNET_break (0); | 1186 | GNUNET_break(0); |
1177 | return NULL; | 1187 | return NULL; |
1178 | } | 1188 | } |
1179 | GNUNET_break (6 == strlen (end)); | 1189 | GNUNET_break(6 == strlen(end)); |
1180 | return GNUNET_strdup (end); | 1190 | return GNUNET_strdup(end); |
1181 | } | 1191 | } |
1182 | 1192 | ||
1183 | 1193 | ||
@@ -1190,7 +1200,7 @@ get_serialization_short_name (const char *fullname) | |||
1190 | * @return NULL on errror | 1200 | * @return NULL on errror |
1191 | */ | 1201 | */ |
1192 | static char * | 1202 | static char * |
1193 | make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext) | 1203 | make_serialization_file_name(struct GNUNET_FS_Handle *h, const char *ext) |
1194 | { | 1204 | { |
1195 | char *fn; | 1205 | char *fn; |
1196 | char *dn; | 1206 | char *dn; |
@@ -1198,20 +1208,20 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext) | |||
1198 | 1208 | ||
1199 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 1209 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
1200 | return NULL; /* persistence not requested */ | 1210 | return NULL; /* persistence not requested */ |
1201 | dn = get_serialization_file_name (h, ext, ""); | 1211 | dn = get_serialization_file_name(h, ext, ""); |
1202 | if (NULL == dn) | 1212 | if (NULL == dn) |
1203 | return NULL; | 1213 | return NULL; |
1204 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn)) | 1214 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(dn)) |
1205 | { | 1215 | { |
1206 | GNUNET_free (dn); | 1216 | GNUNET_free(dn); |
1207 | return NULL; | 1217 | return NULL; |
1208 | } | 1218 | } |
1209 | fn = GNUNET_DISK_mktemp (dn); | 1219 | fn = GNUNET_DISK_mktemp(dn); |
1210 | GNUNET_free (dn); | 1220 | GNUNET_free(dn); |
1211 | if (NULL == fn) | 1221 | if (NULL == fn) |
1212 | return NULL; /* epic fail */ | 1222 | return NULL; /* epic fail */ |
1213 | ret = get_serialization_short_name (fn); | 1223 | ret = get_serialization_short_name(fn); |
1214 | GNUNET_free (fn); | 1224 | GNUNET_free(fn); |
1215 | return ret; | 1225 | return ret; |
1216 | } | 1226 | } |
1217 | 1227 | ||
@@ -1226,9 +1236,9 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext) | |||
1226 | * @return NULL on errror | 1236 | * @return NULL on errror |
1227 | */ | 1237 | */ |
1228 | static char * | 1238 | static char * |
1229 | make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | 1239 | make_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, |
1230 | const char *ext, | 1240 | const char *ext, |
1231 | const char *uni) | 1241 | const char *uni) |
1232 | { | 1242 | { |
1233 | char *fn; | 1243 | char *fn; |
1234 | char *dn; | 1244 | char *dn; |
@@ -1236,20 +1246,20 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
1236 | 1246 | ||
1237 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 1247 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
1238 | return NULL; /* persistence not requested */ | 1248 | return NULL; /* persistence not requested */ |
1239 | dn = get_serialization_file_name_in_dir (h, ext, uni, ""); | 1249 | dn = get_serialization_file_name_in_dir(h, ext, uni, ""); |
1240 | if (NULL == dn) | 1250 | if (NULL == dn) |
1241 | return NULL; | 1251 | return NULL; |
1242 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn)) | 1252 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(dn)) |
1243 | { | 1253 | { |
1244 | GNUNET_free (dn); | 1254 | GNUNET_free(dn); |
1245 | return NULL; | 1255 | return NULL; |
1246 | } | 1256 | } |
1247 | fn = GNUNET_DISK_mktemp (dn); | 1257 | fn = GNUNET_DISK_mktemp(dn); |
1248 | GNUNET_free (dn); | 1258 | GNUNET_free(dn); |
1249 | if (NULL == fn) | 1259 | if (NULL == fn) |
1250 | return NULL; /* epic fail */ | 1260 | return NULL; /* epic fail */ |
1251 | ret = get_serialization_short_name (fn); | 1261 | ret = get_serialization_short_name(fn); |
1252 | GNUNET_free (fn); | 1262 | GNUNET_free(fn); |
1253 | return ret; | 1263 | return ret; |
1254 | } | 1264 | } |
1255 | 1265 | ||
@@ -1262,8 +1272,8 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
1262 | * @return #GNUNET_OK on success | 1272 | * @return #GNUNET_OK on success |
1263 | */ | 1273 | */ |
1264 | static int | 1274 | static int |
1265 | copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, | 1275 | copy_from_reader(struct GNUNET_BIO_WriteHandle *wh, |
1266 | struct GNUNET_FS_FileInformation *fi) | 1276 | struct GNUNET_FS_FileInformation *fi) |
1267 | { | 1277 | { |
1268 | char buf[32 * 1024]; | 1278 | char buf[32 * 1024]; |
1269 | uint64_t off; | 1279 | uint64_t off; |
@@ -1274,19 +1284,19 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, | |||
1274 | emsg = NULL; | 1284 | emsg = NULL; |
1275 | off = 0; | 1285 | off = 0; |
1276 | while (off < fi->data.file.file_size) | 1286 | while (off < fi->data.file.file_size) |
1277 | { | 1287 | { |
1278 | left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off); | 1288 | left = GNUNET_MIN(sizeof(buf), fi->data.file.file_size - off); |
1279 | ret = | 1289 | ret = |
1280 | fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg); | 1290 | fi->data.file.reader(fi->data.file.reader_cls, off, left, buf, &emsg); |
1281 | if (0 == ret) | 1291 | if (0 == ret) |
1282 | { | 1292 | { |
1283 | GNUNET_free (emsg); | 1293 | GNUNET_free(emsg); |
1284 | return GNUNET_SYSERR; | 1294 | return GNUNET_SYSERR; |
1285 | } | 1295 | } |
1286 | if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret)) | 1296 | if (GNUNET_OK != GNUNET_BIO_write(wh, buf, ret)) |
1287 | return GNUNET_SYSERR; | 1297 | return GNUNET_SYSERR; |
1288 | off += ret; | 1298 | off += ret; |
1289 | } | 1299 | } |
1290 | return GNUNET_OK; | 1300 | return GNUNET_OK; |
1291 | } | 1301 | } |
1292 | 1302 | ||
@@ -1298,7 +1308,7 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, | |||
1298 | * @param fi file information to sync with disk | 1308 | * @param fi file information to sync with disk |
1299 | */ | 1309 | */ |
1300 | void | 1310 | void |
1301 | GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | 1311 | GNUNET_FS_file_information_sync_(struct GNUNET_FS_FileInformation *fi) |
1302 | { | 1312 | { |
1303 | char *fn; | 1313 | char *fn; |
1304 | struct GNUNET_BIO_WriteHandle *wh; | 1314 | struct GNUNET_BIO_WriteHandle *wh; |
@@ -1309,17 +1319,17 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1309 | 1319 | ||
1310 | if (NULL == fi->serialization) | 1320 | if (NULL == fi->serialization) |
1311 | fi->serialization = | 1321 | fi->serialization = |
1312 | make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); | 1322 | make_serialization_file_name(fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); |
1313 | if (NULL == fi->serialization) | 1323 | if (NULL == fi->serialization) |
1314 | return; | 1324 | return; |
1315 | wh = | 1325 | wh = |
1316 | get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); | 1326 | get_write_handle(fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); |
1317 | if (NULL == wh) | 1327 | if (NULL == wh) |
1318 | { | 1328 | { |
1319 | GNUNET_free (fi->serialization); | 1329 | GNUNET_free(fi->serialization); |
1320 | fi->serialization = NULL; | 1330 | fi->serialization = NULL; |
1321 | return; | 1331 | return; |
1322 | } | 1332 | } |
1323 | if (GNUNET_YES == fi->is_directory) | 1333 | if (GNUNET_YES == fi->is_directory) |
1324 | b = 4; | 1334 | b = 4; |
1325 | else if (GNUNET_YES == fi->data.file.index_start_confirmed) | 1335 | else if (GNUNET_YES == fi->data.file.index_start_confirmed) |
@@ -1331,143 +1341,147 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1331 | else | 1341 | else |
1332 | b = 0; | 1342 | b = 0; |
1333 | if (NULL != fi->keywords) | 1343 | if (NULL != fi->keywords) |
1334 | ksks = GNUNET_FS_uri_to_string (fi->keywords); | 1344 | ksks = GNUNET_FS_uri_to_string(fi->keywords); |
1335 | else | 1345 | else |
1336 | ksks = NULL; | 1346 | ksks = NULL; |
1337 | if (NULL != fi->chk_uri) | 1347 | if (NULL != fi->chk_uri) |
1338 | chks = GNUNET_FS_uri_to_string (fi->chk_uri); | 1348 | chks = GNUNET_FS_uri_to_string(fi->chk_uri); |
1339 | else | 1349 | else |
1340 | chks = NULL; | 1350 | chks = NULL; |
1341 | if (NULL != fi->sks_uri) | 1351 | if (NULL != fi->sks_uri) |
1342 | skss = GNUNET_FS_uri_to_string (fi->sks_uri); | 1352 | skss = GNUNET_FS_uri_to_string(fi->sks_uri); |
1343 | else | 1353 | else |
1344 | skss = NULL; | 1354 | skss = NULL; |
1345 | if ((GNUNET_OK != GNUNET_BIO_write (wh, &b, sizeof (b))) || | 1355 | if ((GNUNET_OK != GNUNET_BIO_write(wh, &b, sizeof(b))) || |
1346 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, fi->meta)) || | 1356 | (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, fi->meta)) || |
1347 | (GNUNET_OK != GNUNET_BIO_write_string (wh, ksks)) || | 1357 | (GNUNET_OK != GNUNET_BIO_write_string(wh, ksks)) || |
1348 | (GNUNET_OK != GNUNET_BIO_write_string (wh, chks)) || | 1358 | (GNUNET_OK != GNUNET_BIO_write_string(wh, chks)) || |
1349 | (GNUNET_OK != GNUNET_BIO_write_string (wh, skss)) || | 1359 | (GNUNET_OK != GNUNET_BIO_write_string(wh, skss)) || |
1350 | (GNUNET_OK != write_start_time (wh, fi->start_time)) || | 1360 | (GNUNET_OK != write_start_time(wh, fi->start_time)) || |
1351 | (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->emsg)) || | 1361 | (GNUNET_OK != GNUNET_BIO_write_string(wh, fi->emsg)) || |
1352 | (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->filename)) || | 1362 | (GNUNET_OK != GNUNET_BIO_write_string(wh, fi->filename)) || |
1353 | (GNUNET_OK != | 1363 | (GNUNET_OK != |
1354 | GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value_us)) || | 1364 | GNUNET_BIO_write_int64(wh, fi->bo.expiration_time.abs_value_us)) || |
1355 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) || | 1365 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->bo.anonymity_level)) || |
1356 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) || | 1366 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->bo.content_priority)) || |
1357 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.replication_level))) | 1367 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->bo.replication_level))) |
1358 | { | 1368 | { |
1359 | GNUNET_break (0); | 1369 | GNUNET_break(0); |
1360 | goto cleanup; | 1370 | goto cleanup; |
1361 | } | 1371 | } |
1362 | GNUNET_free_non_null (chks); | 1372 | GNUNET_free_non_null(chks); |
1363 | chks = NULL; | 1373 | chks = NULL; |
1364 | GNUNET_free_non_null (ksks); | 1374 | GNUNET_free_non_null(ksks); |
1365 | ksks = NULL; | 1375 | ksks = NULL; |
1366 | GNUNET_free_non_null (skss); | 1376 | GNUNET_free_non_null(skss); |
1367 | skss = NULL; | 1377 | skss = NULL; |
1368 | 1378 | ||
1369 | switch (b) | 1379 | switch (b) |
1370 | { | ||
1371 | case 0: /* file-insert */ | ||
1372 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) | ||
1373 | { | ||
1374 | GNUNET_break (0); | ||
1375 | goto cleanup; | ||
1376 | } | ||
1377 | if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename)) | ||
1378 | if (GNUNET_OK != copy_from_reader (wh, fi)) | ||
1379 | { | ||
1380 | GNUNET_break (0); | ||
1381 | goto cleanup; | ||
1382 | } | ||
1383 | break; | ||
1384 | case 1: /* file-index, no hash */ | ||
1385 | if (NULL == fi->filename) | ||
1386 | { | 1380 | { |
1387 | GNUNET_break (0); | 1381 | case 0: /* file-insert */ |
1388 | goto cleanup; | 1382 | if (GNUNET_OK != GNUNET_BIO_write_int64(wh, fi->data.file.file_size)) |
1389 | } | 1383 | { |
1390 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) | 1384 | GNUNET_break(0); |
1391 | { | 1385 | goto cleanup; |
1392 | GNUNET_break (0); | 1386 | } |
1387 | if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename)) | ||
1388 | if (GNUNET_OK != copy_from_reader(wh, fi)) | ||
1389 | { | ||
1390 | GNUNET_break(0); | ||
1391 | goto cleanup; | ||
1392 | } | ||
1393 | break; | ||
1394 | |||
1395 | case 1: /* file-index, no hash */ | ||
1396 | if (NULL == fi->filename) | ||
1397 | { | ||
1398 | GNUNET_break(0); | ||
1399 | goto cleanup; | ||
1400 | } | ||
1401 | if (GNUNET_OK != GNUNET_BIO_write_int64(wh, fi->data.file.file_size)) | ||
1402 | { | ||
1403 | GNUNET_break(0); | ||
1404 | goto cleanup; | ||
1405 | } | ||
1406 | break; | ||
1407 | |||
1408 | case 2: /* file-index-with-hash */ | ||
1409 | case 3: /* file-index-with-hash-confirmed */ | ||
1410 | if (NULL == fi->filename) | ||
1411 | { | ||
1412 | GNUNET_break(0); | ||
1413 | goto cleanup; | ||
1414 | } | ||
1415 | if ((GNUNET_OK != GNUNET_BIO_write_int64(wh, fi->data.file.file_size)) || | ||
1416 | (GNUNET_OK != GNUNET_BIO_write(wh, | ||
1417 | &fi->data.file.file_id, | ||
1418 | sizeof(struct GNUNET_HashCode)))) | ||
1419 | { | ||
1420 | GNUNET_break(0); | ||
1421 | goto cleanup; | ||
1422 | } | ||
1423 | break; | ||
1424 | |||
1425 | case 4: /* directory */ | ||
1426 | if ((NULL != fi->data.dir.entries) && | ||
1427 | (NULL == fi->data.dir.entries->serialization)) | ||
1428 | GNUNET_FS_file_information_sync_(fi->data.dir.entries); | ||
1429 | if ((GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->data.dir.dir_size)) || | ||
1430 | (GNUNET_OK != | ||
1431 | GNUNET_BIO_write_int64(wh, fi->data.dir.contents_completed)) || | ||
1432 | (GNUNET_OK != | ||
1433 | GNUNET_BIO_write_int64(wh, fi->data.dir.contents_size)) || | ||
1434 | (GNUNET_OK != GNUNET_BIO_write(wh, | ||
1435 | fi->data.dir.dir_data, | ||
1436 | (uint32_t)fi->data.dir.dir_size)) || | ||
1437 | (GNUNET_OK != | ||
1438 | GNUNET_BIO_write_string(wh, | ||
1439 | (fi->data.dir.entries == NULL) | ||
1440 | ? NULL | ||
1441 | : fi->data.dir.entries->serialization))) | ||
1442 | { | ||
1443 | GNUNET_break(0); | ||
1444 | goto cleanup; | ||
1445 | } | ||
1446 | break; | ||
1447 | |||
1448 | default: | ||
1449 | GNUNET_assert(0); | ||
1393 | goto cleanup; | 1450 | goto cleanup; |
1394 | } | 1451 | } |
1395 | break; | 1452 | if ((NULL != fi->next) && (NULL == fi->next->serialization)) |
1396 | case 2: /* file-index-with-hash */ | 1453 | GNUNET_FS_file_information_sync_(fi->next); |
1397 | case 3: /* file-index-with-hash-confirmed */ | 1454 | if (GNUNET_OK != GNUNET_BIO_write_string(wh, |
1398 | if (NULL == fi->filename) | 1455 | (fi->next != NULL) |
1456 | ? fi->next->serialization | ||
1457 | : NULL)) | ||
1399 | { | 1458 | { |
1400 | GNUNET_break (0); | 1459 | GNUNET_break(0); |
1401 | goto cleanup; | 1460 | goto cleanup; |
1402 | } | 1461 | } |
1403 | if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) || | 1462 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
1404 | (GNUNET_OK != GNUNET_BIO_write (wh, | ||
1405 | &fi->data.file.file_id, | ||
1406 | sizeof (struct GNUNET_HashCode)))) | ||
1407 | { | 1463 | { |
1408 | GNUNET_break (0); | 1464 | wh = NULL; |
1465 | GNUNET_break(0); | ||
1409 | goto cleanup; | 1466 | goto cleanup; |
1410 | } | 1467 | } |
1411 | break; | ||
1412 | case 4: /* directory */ | ||
1413 | if ((NULL != fi->data.dir.entries) && | ||
1414 | (NULL == fi->data.dir.entries->serialization)) | ||
1415 | GNUNET_FS_file_information_sync_ (fi->data.dir.entries); | ||
1416 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) || | ||
1417 | (GNUNET_OK != | ||
1418 | GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) || | ||
1419 | (GNUNET_OK != | ||
1420 | GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) || | ||
1421 | (GNUNET_OK != GNUNET_BIO_write (wh, | ||
1422 | fi->data.dir.dir_data, | ||
1423 | (uint32_t) fi->data.dir.dir_size)) || | ||
1424 | (GNUNET_OK != | ||
1425 | GNUNET_BIO_write_string (wh, | ||
1426 | (fi->data.dir.entries == NULL) | ||
1427 | ? NULL | ||
1428 | : fi->data.dir.entries->serialization))) | ||
1429 | { | ||
1430 | GNUNET_break (0); | ||
1431 | goto cleanup; | ||
1432 | } | ||
1433 | break; | ||
1434 | default: | ||
1435 | GNUNET_assert (0); | ||
1436 | goto cleanup; | ||
1437 | } | ||
1438 | if ((NULL != fi->next) && (NULL == fi->next->serialization)) | ||
1439 | GNUNET_FS_file_information_sync_ (fi->next); | ||
1440 | if (GNUNET_OK != GNUNET_BIO_write_string (wh, | ||
1441 | (fi->next != NULL) | ||
1442 | ? fi->next->serialization | ||
1443 | : NULL)) | ||
1444 | { | ||
1445 | GNUNET_break (0); | ||
1446 | goto cleanup; | ||
1447 | } | ||
1448 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | ||
1449 | { | ||
1450 | wh = NULL; | ||
1451 | GNUNET_break (0); | ||
1452 | goto cleanup; | ||
1453 | } | ||
1454 | return; /* done! */ | 1468 | return; /* done! */ |
1455 | cleanup: | 1469 | cleanup: |
1456 | if (NULL != wh) | 1470 | if (NULL != wh) |
1457 | (void) GNUNET_BIO_write_close (wh); | 1471 | (void)GNUNET_BIO_write_close(wh); |
1458 | GNUNET_free_non_null (chks); | 1472 | GNUNET_free_non_null(chks); |
1459 | GNUNET_free_non_null (ksks); | 1473 | GNUNET_free_non_null(ksks); |
1460 | GNUNET_free_non_null (skss); | 1474 | GNUNET_free_non_null(skss); |
1461 | fn = get_serialization_file_name (fi->h, | 1475 | fn = get_serialization_file_name(fi->h, |
1462 | GNUNET_FS_SYNC_PATH_FILE_INFO, | 1476 | GNUNET_FS_SYNC_PATH_FILE_INFO, |
1463 | fi->serialization); | 1477 | fi->serialization); |
1464 | if (NULL != fn) | 1478 | if (NULL != fn) |
1465 | { | 1479 | { |
1466 | if (0 != unlink (fn)) | 1480 | if (0 != unlink(fn)) |
1467 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 1481 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
1468 | GNUNET_free (fn); | 1482 | GNUNET_free(fn); |
1469 | } | 1483 | } |
1470 | GNUNET_free (fi->serialization); | 1484 | GNUNET_free(fi->serialization); |
1471 | fi->serialization = NULL; | 1485 | fi->serialization = NULL; |
1472 | } | 1486 | } |
1473 | 1487 | ||
@@ -1481,19 +1495,19 @@ cleanup: | |||
1481 | * @return NULL if srch was not found in this subtree | 1495 | * @return NULL if srch was not found in this subtree |
1482 | */ | 1496 | */ |
1483 | static struct GNUNET_FS_FileInformation * | 1497 | static struct GNUNET_FS_FileInformation * |
1484 | find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch) | 1498 | find_file_position(struct GNUNET_FS_FileInformation *pos, const char *srch) |
1485 | { | 1499 | { |
1486 | struct GNUNET_FS_FileInformation *r; | 1500 | struct GNUNET_FS_FileInformation *r; |
1487 | 1501 | ||
1488 | while (NULL != pos) | 1502 | while (NULL != pos) |
1489 | { | 1503 | { |
1490 | if (0 == strcmp (srch, pos->serialization)) | 1504 | if (0 == strcmp(srch, pos->serialization)) |
1491 | return pos; | 1505 | return pos; |
1492 | if ((GNUNET_YES == pos->is_directory) && | 1506 | if ((GNUNET_YES == pos->is_directory) && |
1493 | (NULL != (r = find_file_position (pos->data.dir.entries, srch)))) | 1507 | (NULL != (r = find_file_position(pos->data.dir.entries, srch)))) |
1494 | return r; | 1508 | return r; |
1495 | pos = pos->next; | 1509 | pos = pos->next; |
1496 | } | 1510 | } |
1497 | return NULL; | 1511 | return NULL; |
1498 | } | 1512 | } |
1499 | 1513 | ||
@@ -1513,33 +1527,33 @@ find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch) | |||
1513 | * @return #GNUNET_OK to continue (always) | 1527 | * @return #GNUNET_OK to continue (always) |
1514 | */ | 1528 | */ |
1515 | static int | 1529 | static int |
1516 | fip_signal_resume (void *cls, | 1530 | fip_signal_resume(void *cls, |
1517 | struct GNUNET_FS_FileInformation *fi, | 1531 | struct GNUNET_FS_FileInformation *fi, |
1518 | uint64_t length, | 1532 | uint64_t length, |
1519 | struct GNUNET_CONTAINER_MetaData *meta, | 1533 | struct GNUNET_CONTAINER_MetaData *meta, |
1520 | struct GNUNET_FS_Uri **uri, | 1534 | struct GNUNET_FS_Uri **uri, |
1521 | struct GNUNET_FS_BlockOptions *bo, | 1535 | struct GNUNET_FS_BlockOptions *bo, |
1522 | int *do_index, | 1536 | int *do_index, |
1523 | void **client_info) | 1537 | void **client_info) |
1524 | { | 1538 | { |
1525 | struct GNUNET_FS_PublishContext *pc = cls; | 1539 | struct GNUNET_FS_PublishContext *pc = cls; |
1526 | struct GNUNET_FS_ProgressInfo pi; | 1540 | struct GNUNET_FS_ProgressInfo pi; |
1527 | 1541 | ||
1528 | if (GNUNET_YES == pc->skip_next_fi_callback) | 1542 | if (GNUNET_YES == pc->skip_next_fi_callback) |
1529 | { | 1543 | { |
1530 | pc->skip_next_fi_callback = GNUNET_NO; | 1544 | pc->skip_next_fi_callback = GNUNET_NO; |
1531 | return GNUNET_OK; | 1545 | return GNUNET_OK; |
1532 | } | 1546 | } |
1533 | pi.status = GNUNET_FS_STATUS_PUBLISH_RESUME; | 1547 | pi.status = GNUNET_FS_STATUS_PUBLISH_RESUME; |
1534 | pi.value.publish.specifics.resume.message = fi->emsg; | 1548 | pi.value.publish.specifics.resume.message = fi->emsg; |
1535 | pi.value.publish.specifics.resume.chk_uri = fi->chk_uri; | 1549 | pi.value.publish.specifics.resume.chk_uri = fi->chk_uri; |
1536 | *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0); | 1550 | *client_info = GNUNET_FS_publish_make_status_(&pi, pc, fi, 0); |
1537 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) | 1551 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) |
1538 | { | 1552 | { |
1539 | /* process entries in directory */ | 1553 | /* process entries in directory */ |
1540 | pc->skip_next_fi_callback = GNUNET_YES; | 1554 | pc->skip_next_fi_callback = GNUNET_YES; |
1541 | GNUNET_FS_file_information_inspect (fi, &fip_signal_resume, pc); | 1555 | GNUNET_FS_file_information_inspect(fi, &fip_signal_resume, pc); |
1542 | } | 1556 | } |
1543 | return GNUNET_OK; | 1557 | return GNUNET_OK; |
1544 | } | 1558 | } |
1545 | 1559 | ||
@@ -1553,7 +1567,7 @@ fip_signal_resume (void *cls, | |||
1553 | * @return #GNUNET_OK (continue to iterate) | 1567 | * @return #GNUNET_OK (continue to iterate) |
1554 | */ | 1568 | */ |
1555 | static int | 1569 | static int |
1556 | deserialize_publish_file (void *cls, const char *filename) | 1570 | deserialize_publish_file(void *cls, const char *filename) |
1557 | { | 1571 | { |
1558 | struct GNUNET_FS_Handle *h = cls; | 1572 | struct GNUNET_FS_Handle *h = cls; |
1559 | struct GNUNET_BIO_ReadHandle *rh; | 1573 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -1566,115 +1580,115 @@ deserialize_publish_file (void *cls, const char *filename) | |||
1566 | char *fi_pos; | 1580 | char *fi_pos; |
1567 | char *emsg; | 1581 | char *emsg; |
1568 | 1582 | ||
1569 | pc = GNUNET_new (struct GNUNET_FS_PublishContext); | 1583 | pc = GNUNET_new(struct GNUNET_FS_PublishContext); |
1570 | pc->h = h; | 1584 | pc->h = h; |
1571 | pc->serialization = get_serialization_short_name (filename); | 1585 | pc->serialization = get_serialization_short_name(filename); |
1572 | fi_root = NULL; | 1586 | fi_root = NULL; |
1573 | fi_pos = NULL; | 1587 | fi_pos = NULL; |
1574 | rh = GNUNET_BIO_read_open (filename); | 1588 | rh = GNUNET_BIO_read_open(filename); |
1575 | if (NULL == rh) | 1589 | if (NULL == rh) |
1576 | { | 1590 | { |
1577 | GNUNET_break (0); | 1591 | GNUNET_break(0); |
1578 | goto cleanup; | 1592 | goto cleanup; |
1579 | } | 1593 | } |
1580 | if ((GNUNET_OK != | 1594 | if ((GNUNET_OK != |
1581 | GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) || | 1595 | GNUNET_BIO_read_string(rh, "publish-nid", &pc->nid, 1024)) || |
1582 | (GNUNET_OK != | 1596 | (GNUNET_OK != |
1583 | GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || | 1597 | GNUNET_BIO_read_string(rh, "publish-nuid", &pc->nuid, 1024)) || |
1584 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 1598 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &options)) || |
1585 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) || | 1599 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &all_done)) || |
1586 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) || | 1600 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &have_ns)) || |
1587 | (GNUNET_OK != | 1601 | (GNUNET_OK != |
1588 | GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || | 1602 | GNUNET_BIO_read_string(rh, "publish-firoot", &fi_root, 128)) || |
1589 | (GNUNET_OK != | 1603 | (GNUNET_OK != |
1590 | GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) || | 1604 | GNUNET_BIO_read_string(rh, "publish-fipos", &fi_pos, 128)) || |
1591 | ((GNUNET_YES == have_ns) && | 1605 | ((GNUNET_YES == have_ns) && |
1592 | (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns))))) | 1606 | (GNUNET_OK != GNUNET_BIO_read(rh, "publish-ns", &ns, sizeof(ns))))) |
1593 | { | 1607 | { |
1594 | GNUNET_break (0); | 1608 | GNUNET_break(0); |
1595 | goto cleanup; | 1609 | goto cleanup; |
1596 | } | 1610 | } |
1597 | pc->options = options; | 1611 | pc->options = options; |
1598 | pc->all_done = all_done; | 1612 | pc->all_done = all_done; |
1599 | if (NULL == fi_root) | 1613 | if (NULL == fi_root) |
1600 | { | 1614 | { |
1601 | GNUNET_break (0); | 1615 | GNUNET_break(0); |
1602 | goto cleanup; | 1616 | goto cleanup; |
1603 | } | 1617 | } |
1604 | pc->fi = deserialize_file_information (h, fi_root); | 1618 | pc->fi = deserialize_file_information(h, fi_root); |
1605 | if (NULL == pc->fi) | 1619 | if (NULL == pc->fi) |
1606 | { | 1620 | { |
1607 | GNUNET_break (0); | 1621 | GNUNET_break(0); |
1608 | goto cleanup; | 1622 | goto cleanup; |
1609 | } | 1623 | } |
1610 | if (GNUNET_YES == have_ns) | 1624 | if (GNUNET_YES == have_ns) |
1611 | { | 1625 | { |
1612 | pc->ns = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); | 1626 | pc->ns = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPrivateKey); |
1613 | *pc->ns = ns; | 1627 | *pc->ns = ns; |
1614 | } | 1628 | } |
1615 | if ((0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) && | 1629 | if ((0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) && |
1616 | (GNUNET_YES != pc->all_done)) | 1630 | (GNUNET_YES != pc->all_done)) |
1617 | { | 1631 | { |
1618 | pc->dsh = GNUNET_DATASTORE_connect (h->cfg); | 1632 | pc->dsh = GNUNET_DATASTORE_connect(h->cfg); |
1619 | if (NULL == pc->dsh) | 1633 | if (NULL == pc->dsh) |
1620 | goto cleanup; | 1634 | goto cleanup; |
1621 | } | 1635 | } |
1622 | if (NULL != fi_pos) | 1636 | if (NULL != fi_pos) |
1623 | { | 1637 | { |
1624 | pc->fi_pos = find_file_position (pc->fi, fi_pos); | 1638 | pc->fi_pos = find_file_position(pc->fi, fi_pos); |
1625 | GNUNET_free (fi_pos); | 1639 | GNUNET_free(fi_pos); |
1626 | fi_pos = NULL; | 1640 | fi_pos = NULL; |
1627 | if (NULL == pc->fi_pos) | 1641 | if (NULL == pc->fi_pos) |
1628 | { | 1642 | { |
1629 | /* failed to find position for resuming, outch! Will start from root! */ | 1643 | /* failed to find position for resuming, outch! Will start from root! */ |
1630 | GNUNET_break (0); | 1644 | GNUNET_break(0); |
1631 | if (GNUNET_YES != pc->all_done) | 1645 | if (GNUNET_YES != pc->all_done) |
1632 | pc->fi_pos = pc->fi; | 1646 | pc->fi_pos = pc->fi; |
1633 | } | 1647 | } |
1634 | } | 1648 | } |
1635 | GNUNET_free (fi_root); | 1649 | GNUNET_free(fi_root); |
1636 | fi_root = NULL; | 1650 | fi_root = NULL; |
1637 | /* generate RESUME event(s) */ | 1651 | /* generate RESUME event(s) */ |
1638 | GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_resume, pc); | 1652 | GNUNET_FS_file_information_inspect(pc->fi, &fip_signal_resume, pc); |
1639 | 1653 | ||
1640 | /* re-start publishing (if needed)... */ | 1654 | /* re-start publishing (if needed)... */ |
1641 | if (GNUNET_YES != pc->all_done) | 1655 | if (GNUNET_YES != pc->all_done) |
1642 | { | 1656 | { |
1643 | GNUNET_assert (NULL == pc->upload_task); | 1657 | GNUNET_assert(NULL == pc->upload_task); |
1644 | pc->upload_task = | 1658 | pc->upload_task = |
1645 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 1659 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
1646 | &GNUNET_FS_publish_main_, | 1660 | &GNUNET_FS_publish_main_, |
1647 | pc); | 1661 | pc); |
1648 | } | 1662 | } |
1649 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 1663 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
1650 | { | 1664 | { |
1651 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1665 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1652 | _ ("Failure while resuming publishing operation `%s': %s\n"), | 1666 | _("Failure while resuming publishing operation `%s': %s\n"), |
1653 | filename, | 1667 | filename, |
1654 | emsg); | 1668 | emsg); |
1655 | GNUNET_free (emsg); | 1669 | GNUNET_free(emsg); |
1656 | } | 1670 | } |
1657 | pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc); | 1671 | pc->top = GNUNET_FS_make_top(h, &GNUNET_FS_publish_signal_suspend_, pc); |
1658 | return GNUNET_OK; | 1672 | return GNUNET_OK; |
1659 | cleanup: | 1673 | cleanup: |
1660 | GNUNET_free_non_null (pc->nid); | 1674 | GNUNET_free_non_null(pc->nid); |
1661 | GNUNET_free_non_null (pc->nuid); | 1675 | GNUNET_free_non_null(pc->nuid); |
1662 | GNUNET_free_non_null (fi_root); | 1676 | GNUNET_free_non_null(fi_root); |
1663 | GNUNET_free_non_null (fi_pos); | 1677 | GNUNET_free_non_null(fi_pos); |
1664 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) | 1678 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))) |
1665 | { | 1679 | { |
1666 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1680 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1667 | _ ("Failed to resume publishing operation `%s': %s\n"), | 1681 | _("Failed to resume publishing operation `%s': %s\n"), |
1668 | filename, | 1682 | filename, |
1669 | emsg); | 1683 | emsg); |
1670 | GNUNET_free (emsg); | 1684 | GNUNET_free(emsg); |
1671 | } | 1685 | } |
1672 | if (NULL != pc->fi) | 1686 | if (NULL != pc->fi) |
1673 | GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); | 1687 | GNUNET_FS_file_information_destroy(pc->fi, NULL, NULL); |
1674 | if (0 != unlink (filename)) | 1688 | if (0 != unlink(filename)) |
1675 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 1689 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
1676 | GNUNET_free (pc->serialization); | 1690 | GNUNET_free(pc->serialization); |
1677 | GNUNET_free (pc); | 1691 | GNUNET_free(pc); |
1678 | return GNUNET_OK; | 1692 | return GNUNET_OK; |
1679 | } | 1693 | } |
1680 | 1694 | ||
@@ -1688,65 +1702,65 @@ cleanup: | |||
1688 | * @param pc the struct to sync | 1702 | * @param pc the struct to sync |
1689 | */ | 1703 | */ |
1690 | void | 1704 | void |
1691 | GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | 1705 | GNUNET_FS_publish_sync_(struct GNUNET_FS_PublishContext *pc) |
1692 | { | 1706 | { |
1693 | struct GNUNET_BIO_WriteHandle *wh; | 1707 | struct GNUNET_BIO_WriteHandle *wh; |
1694 | int32_t have_ns; | 1708 | int32_t have_ns; |
1695 | 1709 | ||
1696 | if (NULL == pc->serialization) | 1710 | if (NULL == pc->serialization) |
1697 | pc->serialization = | 1711 | pc->serialization = |
1698 | make_serialization_file_name (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); | 1712 | make_serialization_file_name(pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); |
1699 | if (NULL == pc->serialization) | 1713 | if (NULL == pc->serialization) |
1700 | return; | 1714 | return; |
1701 | if (NULL == pc->fi) | 1715 | if (NULL == pc->fi) |
1702 | return; | 1716 | return; |
1703 | if (NULL == pc->fi->serialization) | 1717 | if (NULL == pc->fi->serialization) |
1704 | { | 1718 | { |
1705 | GNUNET_break (0); | 1719 | GNUNET_break(0); |
1706 | return; | 1720 | return; |
1707 | } | 1721 | } |
1708 | wh = get_write_handle (pc->h, | 1722 | wh = get_write_handle(pc->h, |
1709 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1723 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
1710 | pc->serialization); | 1724 | pc->serialization); |
1711 | if (NULL == wh) | 1725 | if (NULL == wh) |
1712 | { | 1726 | { |
1713 | GNUNET_break (0); | 1727 | GNUNET_break(0); |
1714 | goto cleanup; | 1728 | goto cleanup; |
1715 | } | 1729 | } |
1716 | have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO; | 1730 | have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO; |
1717 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nid)) || | 1731 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, pc->nid)) || |
1718 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nuid)) || | 1732 | (GNUNET_OK != GNUNET_BIO_write_string(wh, pc->nuid)) || |
1719 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->options)) || | 1733 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, pc->options)) || |
1720 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) || | 1734 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, pc->all_done)) || |
1721 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) || | 1735 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, have_ns)) || |
1722 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) || | 1736 | (GNUNET_OK != GNUNET_BIO_write_string(wh, pc->fi->serialization)) || |
1723 | (GNUNET_OK != GNUNET_BIO_write_string (wh, | 1737 | (GNUNET_OK != GNUNET_BIO_write_string(wh, |
1724 | (NULL == pc->fi_pos) | 1738 | (NULL == pc->fi_pos) |
1725 | ? NULL | 1739 | ? NULL |
1726 | : pc->fi_pos->serialization)) || | 1740 | : pc->fi_pos->serialization)) || |
1727 | ((NULL != pc->ns) && | 1741 | ((NULL != pc->ns) && |
1728 | (GNUNET_OK != | 1742 | (GNUNET_OK != |
1729 | GNUNET_BIO_write (wh, | 1743 | GNUNET_BIO_write(wh, |
1730 | pc->ns, | 1744 | pc->ns, |
1731 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))))) | 1745 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey))))) |
1732 | { | 1746 | { |
1733 | GNUNET_break (0); | 1747 | GNUNET_break(0); |
1734 | goto cleanup; | 1748 | goto cleanup; |
1735 | } | 1749 | } |
1736 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1750 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
1737 | { | 1751 | { |
1738 | wh = NULL; | 1752 | wh = NULL; |
1739 | GNUNET_break (0); | 1753 | GNUNET_break(0); |
1740 | goto cleanup; | 1754 | goto cleanup; |
1741 | } | 1755 | } |
1742 | return; | 1756 | return; |
1743 | cleanup: | 1757 | cleanup: |
1744 | if (NULL != wh) | 1758 | if (NULL != wh) |
1745 | (void) GNUNET_BIO_write_close (wh); | 1759 | (void)GNUNET_BIO_write_close(wh); |
1746 | GNUNET_FS_remove_sync_file_ (pc->h, | 1760 | GNUNET_FS_remove_sync_file_(pc->h, |
1747 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1761 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
1748 | pc->serialization); | 1762 | pc->serialization); |
1749 | GNUNET_free (pc->serialization); | 1763 | GNUNET_free(pc->serialization); |
1750 | pc->serialization = NULL; | 1764 | pc->serialization = NULL; |
1751 | } | 1765 | } |
1752 | 1766 | ||
@@ -1760,60 +1774,60 @@ cleanup: | |||
1760 | * @param uc the struct to sync | 1774 | * @param uc the struct to sync |
1761 | */ | 1775 | */ |
1762 | void | 1776 | void |
1763 | GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) | 1777 | GNUNET_FS_unindex_sync_(struct GNUNET_FS_UnindexContext *uc) |
1764 | { | 1778 | { |
1765 | struct GNUNET_BIO_WriteHandle *wh; | 1779 | struct GNUNET_BIO_WriteHandle *wh; |
1766 | char *uris; | 1780 | char *uris; |
1767 | 1781 | ||
1768 | if (NULL == uc->serialization) | 1782 | if (NULL == uc->serialization) |
1769 | uc->serialization = | 1783 | uc->serialization = |
1770 | make_serialization_file_name (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); | 1784 | make_serialization_file_name(uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); |
1771 | if (NULL == uc->serialization) | 1785 | if (NULL == uc->serialization) |
1772 | return; | 1786 | return; |
1773 | wh = get_write_handle (uc->h, | 1787 | wh = get_write_handle(uc->h, |
1774 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 1788 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
1775 | uc->serialization); | 1789 | uc->serialization); |
1776 | if (NULL == wh) | 1790 | if (NULL == wh) |
1777 | { | 1791 | { |
1778 | GNUNET_break (0); | 1792 | GNUNET_break(0); |
1779 | goto cleanup; | 1793 | goto cleanup; |
1780 | } | 1794 | } |
1781 | if (NULL != uc->ksk_uri) | 1795 | if (NULL != uc->ksk_uri) |
1782 | uris = GNUNET_FS_uri_to_string (uc->ksk_uri); | 1796 | uris = GNUNET_FS_uri_to_string(uc->ksk_uri); |
1783 | else | 1797 | else |
1784 | uris = NULL; | 1798 | uris = NULL; |
1785 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uc->filename)) || | 1799 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uc->filename)) || |
1786 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, uc->file_size)) || | 1800 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, uc->file_size)) || |
1787 | (GNUNET_OK != write_start_time (wh, uc->start_time)) || | 1801 | (GNUNET_OK != write_start_time(wh, uc->start_time)) || |
1788 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) || | 1802 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)uc->state)) || |
1789 | (GNUNET_OK != | 1803 | (GNUNET_OK != |
1790 | GNUNET_BIO_write (wh, &uc->chk, sizeof (struct ContentHashKey))) || | 1804 | GNUNET_BIO_write(wh, &uc->chk, sizeof(struct ContentHashKey))) || |
1791 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 1805 | (GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) || |
1792 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) || | 1806 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)uc->ksk_offset)) || |
1793 | ((uc->state == UNINDEX_STATE_FS_NOTIFY) && | 1807 | ((uc->state == UNINDEX_STATE_FS_NOTIFY) && |
1794 | (GNUNET_OK != GNUNET_BIO_write (wh, | 1808 | (GNUNET_OK != GNUNET_BIO_write(wh, |
1795 | &uc->file_id, | 1809 | &uc->file_id, |
1796 | sizeof (struct GNUNET_HashCode)))) || | 1810 | sizeof(struct GNUNET_HashCode)))) || |
1797 | ((uc->state == UNINDEX_STATE_ERROR) && | 1811 | ((uc->state == UNINDEX_STATE_ERROR) && |
1798 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg)))) | 1812 | (GNUNET_OK != GNUNET_BIO_write_string(wh, uc->emsg)))) |
1799 | { | 1813 | { |
1800 | GNUNET_break (0); | 1814 | GNUNET_break(0); |
1801 | goto cleanup; | 1815 | goto cleanup; |
1802 | } | 1816 | } |
1803 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1817 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
1804 | { | 1818 | { |
1805 | wh = NULL; | 1819 | wh = NULL; |
1806 | GNUNET_break (0); | 1820 | GNUNET_break(0); |
1807 | goto cleanup; | 1821 | goto cleanup; |
1808 | } | 1822 | } |
1809 | return; | 1823 | return; |
1810 | cleanup: | 1824 | cleanup: |
1811 | if (NULL != wh) | 1825 | if (NULL != wh) |
1812 | (void) GNUNET_BIO_write_close (wh); | 1826 | (void)GNUNET_BIO_write_close(wh); |
1813 | GNUNET_FS_remove_sync_file_ (uc->h, | 1827 | GNUNET_FS_remove_sync_file_(uc->h, |
1814 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 1828 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
1815 | uc->serialization); | 1829 | uc->serialization); |
1816 | GNUNET_free (uc->serialization); | 1830 | GNUNET_free(uc->serialization); |
1817 | uc->serialization = NULL; | 1831 | uc->serialization = NULL; |
1818 | } | 1832 | } |
1819 | 1833 | ||
@@ -1826,22 +1840,22 @@ cleanup: | |||
1826 | * @return #GNUNET_YES on success, #GNUNET_NO on error | 1840 | * @return #GNUNET_YES on success, #GNUNET_NO on error |
1827 | */ | 1841 | */ |
1828 | static int | 1842 | static int |
1829 | write_download_request (struct GNUNET_BIO_WriteHandle *wh, | 1843 | write_download_request(struct GNUNET_BIO_WriteHandle *wh, |
1830 | struct DownloadRequest *dr) | 1844 | struct DownloadRequest *dr) |
1831 | { | 1845 | { |
1832 | unsigned int i; | 1846 | unsigned int i; |
1833 | 1847 | ||
1834 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->state)) || | 1848 | if ((GNUNET_OK != GNUNET_BIO_write_int32(wh, dr->state)) || |
1835 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dr->offset)) || | 1849 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, dr->offset)) || |
1836 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->num_children)) || | 1850 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, dr->num_children)) || |
1837 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth))) | 1851 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, dr->depth))) |
1838 | return GNUNET_NO; | 1852 | return GNUNET_NO; |
1839 | if ((BRS_CHK_SET == dr->state) && | 1853 | if ((BRS_CHK_SET == dr->state) && |
1840 | (GNUNET_OK != | 1854 | (GNUNET_OK != |
1841 | GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey)))) | 1855 | GNUNET_BIO_write(wh, &dr->chk, sizeof(struct ContentHashKey)))) |
1842 | return GNUNET_NO; | 1856 | return GNUNET_NO; |
1843 | for (i = 0; i < dr->num_children; i++) | 1857 | for (i = 0; i < dr->num_children; i++) |
1844 | if (GNUNET_NO == write_download_request (wh, dr->children[i])) | 1858 | if (GNUNET_NO == write_download_request(wh, dr->children[i])) |
1845 | return GNUNET_NO; | 1859 | return GNUNET_NO; |
1846 | return GNUNET_YES; | 1860 | return GNUNET_YES; |
1847 | } | 1861 | } |
@@ -1854,56 +1868,59 @@ write_download_request (struct GNUNET_BIO_WriteHandle *wh, | |||
1854 | * @return value the download request read from disk, NULL on error | 1868 | * @return value the download request read from disk, NULL on error |
1855 | */ | 1869 | */ |
1856 | static struct DownloadRequest * | 1870 | static struct DownloadRequest * |
1857 | read_download_request (struct GNUNET_BIO_ReadHandle *rh) | 1871 | read_download_request(struct GNUNET_BIO_ReadHandle *rh) |
1858 | { | 1872 | { |
1859 | struct DownloadRequest *dr; | 1873 | struct DownloadRequest *dr; |
1860 | unsigned int i; | 1874 | unsigned int i; |
1861 | 1875 | ||
1862 | dr = GNUNET_new (struct DownloadRequest); | 1876 | dr = GNUNET_new(struct DownloadRequest); |
1863 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->state)) || | 1877 | if ((GNUNET_OK != GNUNET_BIO_read_int32(rh, &dr->state)) || |
1864 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dr->offset)) || | 1878 | (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dr->offset)) || |
1865 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) || | 1879 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &dr->num_children)) || |
1866 | (dr->num_children > CHK_PER_INODE) || | 1880 | (dr->num_children > CHK_PER_INODE) || |
1867 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) || | 1881 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &dr->depth)) || |
1868 | ((0 == dr->depth) && (dr->num_children > 0)) || | 1882 | ((0 == dr->depth) && (dr->num_children > 0)) || |
1869 | ((dr->depth > 0) && (0 == dr->num_children))) | 1883 | ((dr->depth > 0) && (0 == dr->num_children))) |
1870 | { | 1884 | { |
1871 | GNUNET_break (0); | 1885 | GNUNET_break(0); |
1872 | dr->num_children = 0; | 1886 | dr->num_children = 0; |
1873 | goto cleanup; | 1887 | goto cleanup; |
1874 | } | 1888 | } |
1875 | if (dr->num_children > 0) | 1889 | if (dr->num_children > 0) |
1876 | dr->children = | 1890 | dr->children = |
1877 | GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); | 1891 | GNUNET_malloc(dr->num_children * sizeof(struct DownloadRequest *)); |
1878 | switch (dr->state) | 1892 | switch (dr->state) |
1879 | { | 1893 | { |
1880 | case BRS_INIT: | 1894 | case BRS_INIT: |
1881 | case BRS_RECONSTRUCT_DOWN: | 1895 | case BRS_RECONSTRUCT_DOWN: |
1882 | case BRS_RECONSTRUCT_META_UP: | 1896 | case BRS_RECONSTRUCT_META_UP: |
1883 | case BRS_RECONSTRUCT_UP: | 1897 | case BRS_RECONSTRUCT_UP: |
1884 | break; | 1898 | break; |
1885 | case BRS_CHK_SET: | 1899 | |
1886 | if (GNUNET_OK != | 1900 | case BRS_CHK_SET: |
1887 | GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct ContentHashKey))) | 1901 | if (GNUNET_OK != |
1902 | GNUNET_BIO_read(rh, "chk", &dr->chk, sizeof(struct ContentHashKey))) | ||
1903 | goto cleanup; | ||
1904 | break; | ||
1905 | |||
1906 | case BRS_DOWNLOAD_DOWN: | ||
1907 | case BRS_DOWNLOAD_UP: | ||
1908 | case BRS_ERROR: | ||
1909 | break; | ||
1910 | |||
1911 | default: | ||
1912 | GNUNET_break(0); | ||
1888 | goto cleanup; | 1913 | goto cleanup; |
1889 | break; | 1914 | } |
1890 | case BRS_DOWNLOAD_DOWN: | ||
1891 | case BRS_DOWNLOAD_UP: | ||
1892 | case BRS_ERROR: | ||
1893 | break; | ||
1894 | default: | ||
1895 | GNUNET_break (0); | ||
1896 | goto cleanup; | ||
1897 | } | ||
1898 | for (i = 0; i < dr->num_children; i++) | 1915 | for (i = 0; i < dr->num_children; i++) |
1899 | { | 1916 | { |
1900 | if (NULL == (dr->children[i] = read_download_request (rh))) | 1917 | if (NULL == (dr->children[i] = read_download_request(rh))) |
1901 | goto cleanup; | 1918 | goto cleanup; |
1902 | dr->children[i]->parent = dr; | 1919 | dr->children[i]->parent = dr; |
1903 | } | 1920 | } |
1904 | return dr; | 1921 | return dr; |
1905 | cleanup: | 1922 | cleanup: |
1906 | GNUNET_FS_free_download_request_ (dr); | 1923 | GNUNET_FS_free_download_request_(dr); |
1907 | return NULL; | 1924 | return NULL; |
1908 | } | 1925 | } |
1909 | 1926 | ||
@@ -1918,26 +1935,26 @@ cleanup: | |||
1918 | * @return the expanded file name, NULL for none | 1935 | * @return the expanded file name, NULL for none |
1919 | */ | 1936 | */ |
1920 | static char * | 1937 | static char * |
1921 | get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc, | 1938 | get_download_sync_filename(struct GNUNET_FS_DownloadContext *dc, |
1922 | const char *uni, | 1939 | const char *uni, |
1923 | const char *ext) | 1940 | const char *ext) |
1924 | { | 1941 | { |
1925 | char *par; | 1942 | char *par; |
1926 | char *epar; | 1943 | char *epar; |
1927 | 1944 | ||
1928 | if (dc->parent == NULL) | 1945 | if (dc->parent == NULL) |
1929 | return get_serialization_file_name (dc->h, | 1946 | return get_serialization_file_name(dc->h, |
1930 | (dc->search != NULL) | 1947 | (dc->search != NULL) |
1931 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD | 1948 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD |
1932 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 1949 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
1933 | uni); | 1950 | uni); |
1934 | if (NULL == dc->parent->serialization) | 1951 | if (NULL == dc->parent->serialization) |
1935 | return NULL; | 1952 | return NULL; |
1936 | par = get_download_sync_filename (dc->parent, dc->parent->serialization, ""); | 1953 | par = get_download_sync_filename(dc->parent, dc->parent->serialization, ""); |
1937 | if (NULL == par) | 1954 | if (NULL == par) |
1938 | return NULL; | 1955 | return NULL; |
1939 | GNUNET_asprintf (&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext); | 1956 | GNUNET_asprintf(&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext); |
1940 | GNUNET_free (par); | 1957 | GNUNET_free(par); |
1941 | return epar; | 1958 | return epar; |
1942 | } | 1959 | } |
1943 | 1960 | ||
@@ -1951,7 +1968,7 @@ get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc, | |||
1951 | * @param dc the struct to sync | 1968 | * @param dc the struct to sync |
1952 | */ | 1969 | */ |
1953 | void | 1970 | void |
1954 | GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) | 1971 | GNUNET_FS_download_sync_(struct GNUNET_FS_DownloadContext *dc) |
1955 | { | 1972 | { |
1956 | struct GNUNET_BIO_WriteHandle *wh; | 1973 | struct GNUNET_BIO_WriteHandle *wh; |
1957 | char *uris; | 1974 | char *uris; |
@@ -1961,87 +1978,87 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) | |||
1961 | if (0 != (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) | 1978 | if (0 != (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) |
1962 | return; /* we don't sync probes */ | 1979 | return; /* we don't sync probes */ |
1963 | if (NULL == dc->serialization) | 1980 | if (NULL == dc->serialization) |
1964 | { | ||
1965 | dir = get_download_sync_filename (dc, "", ""); | ||
1966 | if (NULL == dir) | ||
1967 | return; | ||
1968 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dir)) | ||
1969 | { | 1981 | { |
1970 | GNUNET_free (dir); | 1982 | dir = get_download_sync_filename(dc, "", ""); |
1971 | return; | 1983 | if (NULL == dir) |
1984 | return; | ||
1985 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(dir)) | ||
1986 | { | ||
1987 | GNUNET_free(dir); | ||
1988 | return; | ||
1989 | } | ||
1990 | fn = GNUNET_DISK_mktemp(dir); | ||
1991 | GNUNET_free(dir); | ||
1992 | if (NULL == fn) | ||
1993 | return; | ||
1994 | dc->serialization = get_serialization_short_name(fn); | ||
1972 | } | 1995 | } |
1973 | fn = GNUNET_DISK_mktemp (dir); | ||
1974 | GNUNET_free (dir); | ||
1975 | if (NULL == fn) | ||
1976 | return; | ||
1977 | dc->serialization = get_serialization_short_name (fn); | ||
1978 | } | ||
1979 | else | 1996 | else |
1980 | { | ||
1981 | fn = get_download_sync_filename (dc, dc->serialization, ""); | ||
1982 | if (NULL == fn) | ||
1983 | { | 1997 | { |
1984 | GNUNET_free (dc->serialization); | 1998 | fn = get_download_sync_filename(dc, dc->serialization, ""); |
1999 | if (NULL == fn) | ||
2000 | { | ||
2001 | GNUNET_free(dc->serialization); | ||
2002 | dc->serialization = NULL; | ||
2003 | GNUNET_free(fn); | ||
2004 | return; | ||
2005 | } | ||
2006 | } | ||
2007 | wh = GNUNET_BIO_write_open(fn); | ||
2008 | if (NULL == wh) | ||
2009 | { | ||
2010 | GNUNET_free(dc->serialization); | ||
1985 | dc->serialization = NULL; | 2011 | dc->serialization = NULL; |
1986 | GNUNET_free (fn); | 2012 | GNUNET_free(fn); |
1987 | return; | 2013 | return; |
1988 | } | 2014 | } |
1989 | } | 2015 | GNUNET_assert((GNUNET_YES == GNUNET_FS_uri_test_chk(dc->uri)) || |
1990 | wh = GNUNET_BIO_write_open (fn); | 2016 | (GNUNET_YES == GNUNET_FS_uri_test_loc(dc->uri))); |
1991 | if (NULL == wh) | 2017 | uris = GNUNET_FS_uri_to_string(dc->uri); |
1992 | { | 2018 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) || |
1993 | GNUNET_free (dc->serialization); | 2019 | (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, dc->meta)) || |
1994 | dc->serialization = NULL; | 2020 | (GNUNET_OK != GNUNET_BIO_write_string(wh, dc->emsg)) || |
1995 | GNUNET_free (fn); | 2021 | (GNUNET_OK != GNUNET_BIO_write_string(wh, dc->filename)) || |
1996 | return; | 2022 | (GNUNET_OK != GNUNET_BIO_write_string(wh, dc->temp_filename)) || |
1997 | } | 2023 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->old_file_size)) || |
1998 | GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) || | 2024 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->offset)) || |
1999 | (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri))); | 2025 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->length)) || |
2000 | uris = GNUNET_FS_uri_to_string (dc->uri); | 2026 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->completed)) || |
2001 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2027 | (GNUNET_OK != write_start_time(wh, dc->start_time)) || |
2002 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, dc->meta)) || | 2028 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, dc->anonymity)) || |
2003 | (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->emsg)) || | 2029 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)dc->options)) || |
2004 | (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->filename)) || | 2030 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)dc->has_finished))) |
2005 | (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->temp_filename)) || | ||
2006 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->old_file_size)) || | ||
2007 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->offset)) || | ||
2008 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->length)) || | ||
2009 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->completed)) || | ||
2010 | (GNUNET_OK != write_start_time (wh, dc->start_time)) || | ||
2011 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dc->anonymity)) || | ||
2012 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) || | ||
2013 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished))) | ||
2014 | { | ||
2015 | GNUNET_break (0); | ||
2016 | goto cleanup; | ||
2017 | } | ||
2018 | if (NULL == dc->emsg) | ||
2019 | { | ||
2020 | GNUNET_assert (dc->top_request != NULL); | ||
2021 | if (GNUNET_YES != write_download_request (wh, dc->top_request)) | ||
2022 | { | 2031 | { |
2023 | GNUNET_break (0); | 2032 | GNUNET_break(0); |
2024 | goto cleanup; | 2033 | goto cleanup; |
2025 | } | 2034 | } |
2026 | } | 2035 | if (NULL == dc->emsg) |
2027 | GNUNET_free_non_null (uris); | 2036 | { |
2037 | GNUNET_assert(dc->top_request != NULL); | ||
2038 | if (GNUNET_YES != write_download_request(wh, dc->top_request)) | ||
2039 | { | ||
2040 | GNUNET_break(0); | ||
2041 | goto cleanup; | ||
2042 | } | ||
2043 | } | ||
2044 | GNUNET_free_non_null(uris); | ||
2028 | uris = NULL; | 2045 | uris = NULL; |
2029 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 2046 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
2030 | { | 2047 | { |
2031 | wh = NULL; | 2048 | wh = NULL; |
2032 | GNUNET_break (0); | 2049 | GNUNET_break(0); |
2033 | goto cleanup; | 2050 | goto cleanup; |
2034 | } | 2051 | } |
2035 | GNUNET_free (fn); | 2052 | GNUNET_free(fn); |
2036 | return; | 2053 | return; |
2037 | cleanup: | 2054 | cleanup: |
2038 | if (NULL != wh) | 2055 | if (NULL != wh) |
2039 | (void) GNUNET_BIO_write_close (wh); | 2056 | (void)GNUNET_BIO_write_close(wh); |
2040 | GNUNET_free_non_null (uris); | 2057 | GNUNET_free_non_null(uris); |
2041 | if (0 != unlink (fn)) | 2058 | if (0 != unlink(fn)) |
2042 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 2059 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
2043 | GNUNET_free (fn); | 2060 | GNUNET_free(fn); |
2044 | GNUNET_free (dc->serialization); | 2061 | GNUNET_free(dc->serialization); |
2045 | dc->serialization = NULL; | 2062 | dc->serialization = NULL; |
2046 | } | 2063 | } |
2047 | 2064 | ||
@@ -2055,7 +2072,7 @@ cleanup: | |||
2055 | * @param sr the struct to sync | 2072 | * @param sr the struct to sync |
2056 | */ | 2073 | */ |
2057 | void | 2074 | void |
2058 | GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | 2075 | GNUNET_FS_search_result_sync_(struct GNUNET_FS_SearchResult *sr) |
2059 | { | 2076 | { |
2060 | struct GNUNET_BIO_WriteHandle *wh; | 2077 | struct GNUNET_BIO_WriteHandle *wh; |
2061 | char *uris; | 2078 | char *uris; |
@@ -2065,74 +2082,74 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | |||
2065 | uris = NULL; | 2082 | uris = NULL; |
2066 | if (NULL == sr->serialization) | 2083 | if (NULL == sr->serialization) |
2067 | sr->serialization = | 2084 | sr->serialization = |
2068 | make_serialization_file_name_in_dir (sr->h, | 2085 | make_serialization_file_name_in_dir(sr->h, |
2069 | (sr->sc->psearch_result == NULL) | 2086 | (sr->sc->psearch_result == NULL) |
2070 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2087 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2071 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2088 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2072 | sr->sc->serialization); | 2089 | sr->sc->serialization); |
2073 | if (NULL == sr->serialization) | 2090 | if (NULL == sr->serialization) |
2074 | return; | 2091 | return; |
2075 | wh = get_write_handle_in_dir (sr->h, | 2092 | wh = get_write_handle_in_dir(sr->h, |
2076 | (sr->sc->psearch_result == NULL) | 2093 | (sr->sc->psearch_result == NULL) |
2077 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2094 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2078 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2095 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2079 | sr->sc->serialization, | 2096 | sr->sc->serialization, |
2080 | sr->serialization); | 2097 | sr->serialization); |
2081 | if (NULL == wh) | 2098 | if (NULL == wh) |
2082 | { | 2099 | { |
2083 | GNUNET_break (0); | 2100 | GNUNET_break(0); |
2084 | goto cleanup; | 2101 | goto cleanup; |
2085 | } | 2102 | } |
2086 | uris = GNUNET_FS_uri_to_string (sr->uri); | 2103 | uris = GNUNET_FS_uri_to_string(sr->uri); |
2087 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2104 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) || |
2088 | (GNUNET_OK != GNUNET_BIO_write_string (wh, | 2105 | (GNUNET_OK != GNUNET_BIO_write_string(wh, |
2089 | sr->download != NULL | 2106 | sr->download != NULL |
2090 | ? sr->download->serialization | 2107 | ? sr->download->serialization |
2091 | : NULL)) || | 2108 | : NULL)) || |
2092 | (GNUNET_OK != | 2109 | (GNUNET_OK != |
2093 | GNUNET_BIO_write_string (wh, | 2110 | GNUNET_BIO_write_string(wh, |
2094 | sr->update_search != NULL | 2111 | sr->update_search != NULL |
2095 | ? sr->update_search->serialization | 2112 | ? sr->update_search->serialization |
2096 | : NULL)) || | 2113 | : NULL)) || |
2097 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) || | 2114 | (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, sr->meta)) || |
2098 | (GNUNET_OK != | 2115 | (GNUNET_OK != |
2099 | GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode))) || | 2116 | GNUNET_BIO_write(wh, &sr->key, sizeof(struct GNUNET_HashCode))) || |
2100 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || | 2117 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, sr->mandatory_missing)) || |
2101 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) || | 2118 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, sr->optional_support)) || |
2102 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) || | 2119 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, sr->availability_success)) || |
2103 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials))) | 2120 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, sr->availability_trials))) |
2104 | { | 2121 | { |
2105 | GNUNET_break (0); | 2122 | GNUNET_break(0); |
2106 | goto cleanup; | 2123 | goto cleanup; |
2107 | } | 2124 | } |
2108 | if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) && | 2125 | if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) && |
2109 | (GNUNET_OK != | 2126 | (GNUNET_OK != |
2110 | GNUNET_BIO_write (wh, | 2127 | GNUNET_BIO_write(wh, |
2111 | sr->keyword_bitmap, | 2128 | sr->keyword_bitmap, |
2112 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) | 2129 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) |
2113 | { | 2130 | { |
2114 | GNUNET_break (0); | 2131 | GNUNET_break(0); |
2115 | goto cleanup; | 2132 | goto cleanup; |
2116 | } | 2133 | } |
2117 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 2134 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
2118 | { | 2135 | { |
2119 | wh = NULL; | 2136 | wh = NULL; |
2120 | GNUNET_break (0); | 2137 | GNUNET_break(0); |
2121 | goto cleanup; | 2138 | goto cleanup; |
2122 | } | 2139 | } |
2123 | GNUNET_free_non_null (uris); | 2140 | GNUNET_free_non_null(uris); |
2124 | return; | 2141 | return; |
2125 | cleanup: | 2142 | cleanup: |
2126 | GNUNET_free_non_null (uris); | 2143 | GNUNET_free_non_null(uris); |
2127 | if (NULL != wh) | 2144 | if (NULL != wh) |
2128 | (void) GNUNET_BIO_write_close (wh); | 2145 | (void)GNUNET_BIO_write_close(wh); |
2129 | remove_sync_file_in_dir (sr->h, | 2146 | remove_sync_file_in_dir(sr->h, |
2130 | (NULL == sr->sc->psearch_result) | 2147 | (NULL == sr->sc->psearch_result) |
2131 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2148 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2132 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2149 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2133 | sr->sc->serialization, | 2150 | sr->sc->serialization, |
2134 | sr->serialization); | 2151 | sr->serialization); |
2135 | GNUNET_free (sr->serialization); | 2152 | GNUNET_free(sr->serialization); |
2136 | sr->serialization = NULL; | 2153 | sr->serialization = NULL; |
2137 | } | 2154 | } |
2138 | 2155 | ||
@@ -2146,7 +2163,7 @@ cleanup: | |||
2146 | * @param sc the struct to sync | 2163 | * @param sc the struct to sync |
2147 | */ | 2164 | */ |
2148 | void | 2165 | void |
2149 | GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) | 2166 | GNUNET_FS_search_sync_(struct GNUNET_FS_SearchContext *sc) |
2150 | { | 2167 | { |
2151 | struct GNUNET_BIO_WriteHandle *wh; | 2168 | struct GNUNET_BIO_WriteHandle *wh; |
2152 | char *uris; | 2169 | char *uris; |
@@ -2154,47 +2171,47 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) | |||
2154 | const char *category; | 2171 | const char *category; |
2155 | 2172 | ||
2156 | category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2173 | category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2157 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; | 2174 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; |
2158 | if (NULL == sc->serialization) | 2175 | if (NULL == sc->serialization) |
2159 | sc->serialization = make_serialization_file_name (sc->h, category); | 2176 | sc->serialization = make_serialization_file_name(sc->h, category); |
2160 | if (NULL == sc->serialization) | 2177 | if (NULL == sc->serialization) |
2161 | return; | 2178 | return; |
2162 | uris = NULL; | 2179 | uris = NULL; |
2163 | wh = get_write_handle (sc->h, category, sc->serialization); | 2180 | wh = get_write_handle(sc->h, category, sc->serialization); |
2164 | if (NULL == wh) | 2181 | if (NULL == wh) |
2165 | { | 2182 | { |
2166 | GNUNET_break (0); | 2183 | GNUNET_break(0); |
2167 | goto cleanup; | 2184 | goto cleanup; |
2168 | } | 2185 | } |
2169 | GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) || | 2186 | GNUNET_assert((GNUNET_YES == GNUNET_FS_uri_test_ksk(sc->uri)) || |
2170 | (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri))); | 2187 | (GNUNET_YES == GNUNET_FS_uri_test_sks(sc->uri))); |
2171 | uris = GNUNET_FS_uri_to_string (sc->uri); | 2188 | uris = GNUNET_FS_uri_to_string(sc->uri); |
2172 | in_pause = (sc->task != NULL) ? 'r' : '\0'; | 2189 | in_pause = (sc->task != NULL) ? 'r' : '\0'; |
2173 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2190 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) || |
2174 | (GNUNET_OK != write_start_time (wh, sc->start_time)) || | 2191 | (GNUNET_OK != write_start_time(wh, sc->start_time)) || |
2175 | (GNUNET_OK != GNUNET_BIO_write_string (wh, sc->emsg)) || | 2192 | (GNUNET_OK != GNUNET_BIO_write_string(wh, sc->emsg)) || |
2176 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) || | 2193 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)sc->options)) || |
2177 | (GNUNET_OK != GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) || | 2194 | (GNUNET_OK != GNUNET_BIO_write(wh, &in_pause, sizeof(in_pause))) || |
2178 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sc->anonymity))) | 2195 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, sc->anonymity))) |
2179 | { | 2196 | { |
2180 | GNUNET_break (0); | 2197 | GNUNET_break(0); |
2181 | goto cleanup; | 2198 | goto cleanup; |
2182 | } | 2199 | } |
2183 | GNUNET_free (uris); | 2200 | GNUNET_free(uris); |
2184 | uris = NULL; | 2201 | uris = NULL; |
2185 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 2202 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
2186 | { | 2203 | { |
2187 | wh = NULL; | 2204 | wh = NULL; |
2188 | GNUNET_break (0); | 2205 | GNUNET_break(0); |
2189 | goto cleanup; | 2206 | goto cleanup; |
2190 | } | 2207 | } |
2191 | return; | 2208 | return; |
2192 | cleanup: | 2209 | cleanup: |
2193 | if (NULL != wh) | 2210 | if (NULL != wh) |
2194 | (void) GNUNET_BIO_write_close (wh); | 2211 | (void)GNUNET_BIO_write_close(wh); |
2195 | GNUNET_free_non_null (uris); | 2212 | GNUNET_free_non_null(uris); |
2196 | GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization); | 2213 | GNUNET_FS_remove_sync_file_(sc->h, category, sc->serialization); |
2197 | GNUNET_free (sc->serialization); | 2214 | GNUNET_free(sc->serialization); |
2198 | sc->serialization = NULL; | 2215 | sc->serialization = NULL; |
2199 | } | 2216 | } |
2200 | 2217 | ||
@@ -2208,7 +2225,7 @@ cleanup: | |||
2208 | * @return #GNUNET_OK (continue to iterate) | 2225 | * @return #GNUNET_OK (continue to iterate) |
2209 | */ | 2226 | */ |
2210 | static int | 2227 | static int |
2211 | deserialize_unindex_file (void *cls, const char *filename) | 2228 | deserialize_unindex_file(void *cls, const char *filename) |
2212 | { | 2229 | { |
2213 | struct GNUNET_FS_Handle *h = cls; | 2230 | struct GNUNET_FS_Handle *h = cls; |
2214 | struct GNUNET_BIO_ReadHandle *rh; | 2231 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -2218,144 +2235,155 @@ deserialize_unindex_file (void *cls, const char *filename) | |||
2218 | char *uris; | 2235 | char *uris; |
2219 | uint32_t state; | 2236 | uint32_t state; |
2220 | 2237 | ||
2221 | uc = GNUNET_new (struct GNUNET_FS_UnindexContext); | 2238 | uc = GNUNET_new(struct GNUNET_FS_UnindexContext); |
2222 | uc->h = h; | 2239 | uc->h = h; |
2223 | uc->serialization = get_serialization_short_name (filename); | 2240 | uc->serialization = get_serialization_short_name(filename); |
2224 | rh = GNUNET_BIO_read_open (filename); | 2241 | rh = GNUNET_BIO_read_open(filename); |
2225 | if (NULL == rh) | 2242 | if (NULL == rh) |
2226 | { | 2243 | { |
2227 | GNUNET_break (0); | 2244 | GNUNET_break(0); |
2228 | goto cleanup; | 2245 | goto cleanup; |
2229 | } | 2246 | } |
2230 | uris = NULL; | 2247 | uris = NULL; |
2231 | if ((GNUNET_OK != | 2248 | if ((GNUNET_OK != |
2232 | GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) || | 2249 | GNUNET_BIO_read_string(rh, "unindex-fn", &uc->filename, 10 * 1024)) || |
2233 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) || | 2250 | (GNUNET_OK != GNUNET_BIO_read_int64(rh, &uc->file_size)) || |
2234 | (GNUNET_OK != read_start_time (rh, &uc->start_time)) || | 2251 | (GNUNET_OK != read_start_time(rh, &uc->start_time)) || |
2235 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) || | 2252 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &state)) || |
2236 | (GNUNET_OK != | 2253 | (GNUNET_OK != |
2237 | GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) || | 2254 | GNUNET_BIO_read(rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) || |
2238 | (GNUNET_OK != | 2255 | (GNUNET_OK != |
2239 | GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || | 2256 | GNUNET_BIO_read_string(rh, "unindex-kskuri", &uris, 10 * 1024)) || |
2240 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset))) | 2257 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &uc->ksk_offset))) |
2241 | { | ||
2242 | GNUNET_free_non_null (uris); | ||
2243 | GNUNET_break (0); | ||
2244 | goto cleanup; | ||
2245 | } | ||
2246 | if (NULL != uris) | ||
2247 | { | ||
2248 | uc->ksk_uri = GNUNET_FS_uri_parse (uris, &emsg); | ||
2249 | GNUNET_free (uris); | ||
2250 | if (NULL == uc->ksk_uri) | ||
2251 | { | 2258 | { |
2252 | GNUNET_break (0); | 2259 | GNUNET_free_non_null(uris); |
2253 | GNUNET_free_non_null (emsg); | 2260 | GNUNET_break(0); |
2254 | goto cleanup; | 2261 | goto cleanup; |
2255 | } | 2262 | } |
2256 | } | 2263 | if (NULL != uris) |
2264 | { | ||
2265 | uc->ksk_uri = GNUNET_FS_uri_parse(uris, &emsg); | ||
2266 | GNUNET_free(uris); | ||
2267 | if (NULL == uc->ksk_uri) | ||
2268 | { | ||
2269 | GNUNET_break(0); | ||
2270 | GNUNET_free_non_null(emsg); | ||
2271 | goto cleanup; | ||
2272 | } | ||
2273 | } | ||
2257 | if ((uc->ksk_offset > 0) && | 2274 | if ((uc->ksk_offset > 0) && |
2258 | ((NULL == uc->ksk_uri) || | 2275 | ((NULL == uc->ksk_uri) || |
2259 | (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount))) | 2276 | (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount))) |
2260 | { | ||
2261 | GNUNET_break (0); | ||
2262 | goto cleanup; | ||
2263 | } | ||
2264 | uc->state = (enum UnindexState) state; | ||
2265 | switch (state) | ||
2266 | { | ||
2267 | case UNINDEX_STATE_HASHING: | ||
2268 | break; | ||
2269 | case UNINDEX_STATE_FS_NOTIFY: | ||
2270 | if (GNUNET_OK != GNUNET_BIO_read (rh, | ||
2271 | "unindex-hash", | ||
2272 | &uc->file_id, | ||
2273 | sizeof (struct GNUNET_HashCode))) | ||
2274 | { | 2277 | { |
2275 | GNUNET_break (0); | 2278 | GNUNET_break(0); |
2276 | goto cleanup; | 2279 | goto cleanup; |
2277 | } | 2280 | } |
2278 | break; | 2281 | uc->state = (enum UnindexState)state; |
2279 | case UNINDEX_STATE_DS_REMOVE: | 2282 | switch (state) |
2280 | case UNINDEX_STATE_EXTRACT_KEYWORDS: | 2283 | { |
2281 | case UNINDEX_STATE_DS_REMOVE_KBLOCKS: | 2284 | case UNINDEX_STATE_HASHING: |
2282 | break; | 2285 | break; |
2283 | case UNINDEX_STATE_COMPLETE: | 2286 | |
2284 | break; | 2287 | case UNINDEX_STATE_FS_NOTIFY: |
2285 | case UNINDEX_STATE_ERROR: | 2288 | if (GNUNET_OK != GNUNET_BIO_read(rh, |
2286 | if (GNUNET_OK != | 2289 | "unindex-hash", |
2287 | GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10 * 1024)) | 2290 | &uc->file_id, |
2288 | { | 2291 | sizeof(struct GNUNET_HashCode))) |
2289 | GNUNET_break (0); | 2292 | { |
2293 | GNUNET_break(0); | ||
2294 | goto cleanup; | ||
2295 | } | ||
2296 | break; | ||
2297 | |||
2298 | case UNINDEX_STATE_DS_REMOVE: | ||
2299 | case UNINDEX_STATE_EXTRACT_KEYWORDS: | ||
2300 | case UNINDEX_STATE_DS_REMOVE_KBLOCKS: | ||
2301 | break; | ||
2302 | |||
2303 | case UNINDEX_STATE_COMPLETE: | ||
2304 | break; | ||
2305 | |||
2306 | case UNINDEX_STATE_ERROR: | ||
2307 | if (GNUNET_OK != | ||
2308 | GNUNET_BIO_read_string(rh, "unindex-emsg", &uc->emsg, 10 * 1024)) | ||
2309 | { | ||
2310 | GNUNET_break(0); | ||
2311 | goto cleanup; | ||
2312 | } | ||
2313 | break; | ||
2314 | |||
2315 | default: | ||
2316 | GNUNET_break(0); | ||
2290 | goto cleanup; | 2317 | goto cleanup; |
2291 | } | 2318 | } |
2292 | break; | 2319 | uc->top = GNUNET_FS_make_top(h, &GNUNET_FS_unindex_signal_suspend_, uc); |
2293 | default: | ||
2294 | GNUNET_break (0); | ||
2295 | goto cleanup; | ||
2296 | } | ||
2297 | uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc); | ||
2298 | pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; | 2320 | pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; |
2299 | pi.value.unindex.specifics.resume.message = uc->emsg; | 2321 | pi.value.unindex.specifics.resume.message = uc->emsg; |
2300 | GNUNET_FS_unindex_make_status_ (&pi, | 2322 | GNUNET_FS_unindex_make_status_(&pi, |
2301 | uc, | 2323 | uc, |
2302 | (uc->state == UNINDEX_STATE_COMPLETE) | 2324 | (uc->state == UNINDEX_STATE_COMPLETE) |
2303 | ? uc->file_size | 2325 | ? uc->file_size |
2304 | : 0); | 2326 | : 0); |
2305 | switch (uc->state) | 2327 | switch (uc->state) |
2306 | { | 2328 | { |
2307 | case UNINDEX_STATE_HASHING: | 2329 | case UNINDEX_STATE_HASHING: |
2308 | uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, | 2330 | uc->fhc = GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, |
2309 | uc->filename, | 2331 | uc->filename, |
2310 | HASHING_BLOCKSIZE, | 2332 | HASHING_BLOCKSIZE, |
2311 | &GNUNET_FS_unindex_process_hash_, | 2333 | &GNUNET_FS_unindex_process_hash_, |
2312 | uc); | 2334 | uc); |
2313 | break; | 2335 | break; |
2314 | case UNINDEX_STATE_FS_NOTIFY: | 2336 | |
2315 | uc->state = UNINDEX_STATE_HASHING; | 2337 | case UNINDEX_STATE_FS_NOTIFY: |
2316 | GNUNET_FS_unindex_process_hash_ (uc, &uc->file_id); | 2338 | uc->state = UNINDEX_STATE_HASHING; |
2317 | break; | 2339 | GNUNET_FS_unindex_process_hash_(uc, &uc->file_id); |
2318 | case UNINDEX_STATE_DS_REMOVE: | 2340 | break; |
2319 | GNUNET_FS_unindex_do_remove_ (uc); | 2341 | |
2320 | break; | 2342 | case UNINDEX_STATE_DS_REMOVE: |
2321 | case UNINDEX_STATE_EXTRACT_KEYWORDS: | 2343 | GNUNET_FS_unindex_do_remove_(uc); |
2322 | GNUNET_FS_unindex_do_extract_keywords_ (uc); | 2344 | break; |
2323 | break; | 2345 | |
2324 | case UNINDEX_STATE_DS_REMOVE_KBLOCKS: | 2346 | case UNINDEX_STATE_EXTRACT_KEYWORDS: |
2325 | GNUNET_FS_unindex_do_remove_kblocks_ (uc); | 2347 | GNUNET_FS_unindex_do_extract_keywords_(uc); |
2326 | break; | 2348 | break; |
2327 | case UNINDEX_STATE_COMPLETE: | 2349 | |
2328 | case UNINDEX_STATE_ERROR: | 2350 | case UNINDEX_STATE_DS_REMOVE_KBLOCKS: |
2329 | /* no need to resume any operation, we were done */ | 2351 | GNUNET_FS_unindex_do_remove_kblocks_(uc); |
2330 | break; | 2352 | break; |
2331 | default: | 2353 | |
2332 | break; | 2354 | case UNINDEX_STATE_COMPLETE: |
2333 | } | 2355 | case UNINDEX_STATE_ERROR: |
2334 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2356 | /* no need to resume any operation, we were done */ |
2335 | { | 2357 | break; |
2336 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2358 | |
2337 | _ ("Failure while resuming unindexing operation `%s': %s\n"), | 2359 | default: |
2338 | filename, | 2360 | break; |
2339 | emsg); | 2361 | } |
2340 | GNUNET_free (emsg); | 2362 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
2341 | } | 2363 | { |
2364 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
2365 | _("Failure while resuming unindexing operation `%s': %s\n"), | ||
2366 | filename, | ||
2367 | emsg); | ||
2368 | GNUNET_free(emsg); | ||
2369 | } | ||
2342 | return GNUNET_OK; | 2370 | return GNUNET_OK; |
2343 | cleanup: | 2371 | cleanup: |
2344 | GNUNET_free_non_null (uc->filename); | 2372 | GNUNET_free_non_null(uc->filename); |
2345 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) | 2373 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))) |
2346 | { | 2374 | { |
2347 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2375 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2348 | _ ("Failed to resume unindexing operation `%s': %s\n"), | 2376 | _("Failed to resume unindexing operation `%s': %s\n"), |
2349 | filename, | 2377 | filename, |
2350 | emsg); | 2378 | emsg); |
2351 | GNUNET_free (emsg); | 2379 | GNUNET_free(emsg); |
2352 | } | 2380 | } |
2353 | if (NULL != uc->serialization) | 2381 | if (NULL != uc->serialization) |
2354 | GNUNET_FS_remove_sync_file_ (h, | 2382 | GNUNET_FS_remove_sync_file_(h, |
2355 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 2383 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
2356 | uc->serialization); | 2384 | uc->serialization); |
2357 | GNUNET_free_non_null (uc->serialization); | 2385 | GNUNET_free_non_null(uc->serialization); |
2358 | GNUNET_free (uc); | 2386 | GNUNET_free(uc); |
2359 | return GNUNET_OK; | 2387 | return GNUNET_OK; |
2360 | } | 2388 | } |
2361 | 2389 | ||
@@ -2370,11 +2398,11 @@ cleanup: | |||
2370 | * @param serialization name under which the search was serialized | 2398 | * @param serialization name under which the search was serialized |
2371 | */ | 2399 | */ |
2372 | static void | 2400 | static void |
2373 | deserialize_download (struct GNUNET_FS_Handle *h, | 2401 | deserialize_download(struct GNUNET_FS_Handle *h, |
2374 | struct GNUNET_BIO_ReadHandle *rh, | 2402 | struct GNUNET_BIO_ReadHandle *rh, |
2375 | struct GNUNET_FS_DownloadContext *parent, | 2403 | struct GNUNET_FS_DownloadContext *parent, |
2376 | struct GNUNET_FS_SearchResult *search, | 2404 | struct GNUNET_FS_SearchResult *search, |
2377 | const char *serialization); | 2405 | const char *serialization); |
2378 | 2406 | ||
2379 | 2407 | ||
2380 | /** | 2408 | /** |
@@ -2386,10 +2414,10 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2386 | * @param serialization name under which the search was serialized | 2414 | * @param serialization name under which the search was serialized |
2387 | */ | 2415 | */ |
2388 | static struct GNUNET_FS_SearchContext * | 2416 | static struct GNUNET_FS_SearchContext * |
2389 | deserialize_search (struct GNUNET_FS_Handle *h, | 2417 | deserialize_search(struct GNUNET_FS_Handle *h, |
2390 | struct GNUNET_BIO_ReadHandle *rh, | 2418 | struct GNUNET_BIO_ReadHandle *rh, |
2391 | struct GNUNET_FS_SearchResult *psearch_result, | 2419 | struct GNUNET_FS_SearchResult *psearch_result, |
2392 | const char *serialization); | 2420 | const char *serialization); |
2393 | 2421 | ||
2394 | 2422 | ||
2395 | /** | 2423 | /** |
@@ -2401,7 +2429,7 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2401 | * @return #GNUNET_OK (continue to iterate) | 2429 | * @return #GNUNET_OK (continue to iterate) |
2402 | */ | 2430 | */ |
2403 | static int | 2431 | static int |
2404 | deserialize_search_result (void *cls, const char *filename) | 2432 | deserialize_search_result(void *cls, const char *filename) |
2405 | { | 2433 | { |
2406 | struct GNUNET_FS_SearchContext *sc = cls; | 2434 | struct GNUNET_FS_SearchContext *sc = cls; |
2407 | char *ser; | 2435 | char *ser; |
@@ -2413,133 +2441,133 @@ deserialize_search_result (void *cls, const char *filename) | |||
2413 | struct GNUNET_BIO_ReadHandle *drh; | 2441 | struct GNUNET_BIO_ReadHandle *drh; |
2414 | struct GNUNET_FS_SearchResult *sr; | 2442 | struct GNUNET_FS_SearchResult *sr; |
2415 | 2443 | ||
2416 | ser = get_serialization_short_name (filename); | 2444 | ser = get_serialization_short_name(filename); |
2417 | rh = GNUNET_BIO_read_open (filename); | 2445 | rh = GNUNET_BIO_read_open(filename); |
2418 | if (NULL == rh) | 2446 | if (NULL == rh) |
2419 | { | ||
2420 | if (NULL != ser) | ||
2421 | { | 2447 | { |
2422 | remove_sync_file_in_dir (sc->h, | 2448 | if (NULL != ser) |
2423 | (NULL == sc->psearch_result) | 2449 | { |
2424 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2450 | remove_sync_file_in_dir(sc->h, |
2425 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2451 | (NULL == sc->psearch_result) |
2426 | sc->serialization, | 2452 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2427 | ser); | 2453 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2428 | GNUNET_free (ser); | 2454 | sc->serialization, |
2455 | ser); | ||
2456 | GNUNET_free(ser); | ||
2457 | } | ||
2458 | return GNUNET_OK; | ||
2429 | } | 2459 | } |
2430 | return GNUNET_OK; | ||
2431 | } | ||
2432 | emsg = NULL; | 2460 | emsg = NULL; |
2433 | uris = NULL; | 2461 | uris = NULL; |
2434 | download = NULL; | 2462 | download = NULL; |
2435 | update_srch = NULL; | 2463 | update_srch = NULL; |
2436 | sr = GNUNET_new (struct GNUNET_FS_SearchResult); | 2464 | sr = GNUNET_new(struct GNUNET_FS_SearchResult); |
2437 | sr->h = sc->h; | 2465 | sr->h = sc->h; |
2438 | sr->sc = sc; | 2466 | sr->sc = sc; |
2439 | sr->serialization = ser; | 2467 | sr->serialization = ser; |
2440 | if ((GNUNET_OK != | 2468 | if ((GNUNET_OK != |
2441 | GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) || | 2469 | GNUNET_BIO_read_string(rh, "result-uri", &uris, 10 * 1024)) || |
2442 | (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || | 2470 | (NULL == (sr->uri = GNUNET_FS_uri_parse(uris, &emsg))) || |
2443 | (GNUNET_OK != | 2471 | (GNUNET_OK != |
2444 | GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) || | 2472 | GNUNET_BIO_read_string(rh, "download-lnk", &download, 16)) || |
2445 | (GNUNET_OK != | 2473 | (GNUNET_OK != |
2446 | GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) || | 2474 | GNUNET_BIO_read_string(rh, "search-lnk", &update_srch, 16)) || |
2447 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) || | 2475 | (GNUNET_OK != GNUNET_BIO_read_meta_data(rh, "result-meta", &sr->meta)) || |
2448 | (GNUNET_OK != GNUNET_BIO_read (rh, | 2476 | (GNUNET_OK != GNUNET_BIO_read(rh, |
2449 | "result-key", | 2477 | "result-key", |
2450 | &sr->key, | 2478 | &sr->key, |
2451 | sizeof (struct GNUNET_HashCode))) || | 2479 | sizeof(struct GNUNET_HashCode))) || |
2452 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || | 2480 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sr->mandatory_missing)) || |
2453 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || | 2481 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sr->optional_support)) || |
2454 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || | 2482 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sr->availability_success)) || |
2455 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials))) | 2483 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sr->availability_trials))) |
2456 | { | 2484 | { |
2457 | GNUNET_break (0); | 2485 | GNUNET_break(0); |
2458 | goto cleanup; | ||
2459 | } | ||
2460 | if (GNUNET_FS_URI_KSK == sr->sc->uri->type) | ||
2461 | { | ||
2462 | sr->keyword_bitmap = GNUNET_malloc ( | ||
2463 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ | ||
2464 | if (GNUNET_OK != | ||
2465 | GNUNET_BIO_read (rh, | ||
2466 | "keyword-bitmap", | ||
2467 | sr->keyword_bitmap, | ||
2468 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) | ||
2469 | { | ||
2470 | GNUNET_break (0); | ||
2471 | goto cleanup; | 2486 | goto cleanup; |
2472 | } | 2487 | } |
2473 | } | 2488 | if (GNUNET_FS_URI_KSK == sr->sc->uri->type) |
2474 | GNUNET_free (uris); | 2489 | { |
2490 | sr->keyword_bitmap = GNUNET_malloc( | ||
2491 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ | ||
2492 | if (GNUNET_OK != | ||
2493 | GNUNET_BIO_read(rh, | ||
2494 | "keyword-bitmap", | ||
2495 | sr->keyword_bitmap, | ||
2496 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) | ||
2497 | { | ||
2498 | GNUNET_break(0); | ||
2499 | goto cleanup; | ||
2500 | } | ||
2501 | } | ||
2502 | GNUNET_free(uris); | ||
2475 | if (NULL != download) | 2503 | if (NULL != download) |
2476 | { | 2504 | { |
2477 | drh = get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, download); | 2505 | drh = get_read_handle(sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, download); |
2478 | if (NULL != drh) | 2506 | if (NULL != drh) |
2479 | { | 2507 | { |
2480 | deserialize_download (sc->h, drh, NULL, sr, download); | 2508 | deserialize_download(sc->h, drh, NULL, sr, download); |
2481 | if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) | 2509 | if (GNUNET_OK != GNUNET_BIO_read_close(drh, &emsg)) |
2482 | { | 2510 | { |
2483 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2511 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2484 | _ ("Failed to resume sub-download `%s': %s\n"), | 2512 | _("Failed to resume sub-download `%s': %s\n"), |
2485 | download, | 2513 | download, |
2486 | emsg); | 2514 | emsg); |
2487 | GNUNET_free (emsg); | 2515 | GNUNET_free(emsg); |
2488 | } | 2516 | } |
2489 | } | 2517 | } |
2490 | GNUNET_free (download); | 2518 | GNUNET_free(download); |
2491 | } | 2519 | } |
2492 | if (NULL != update_srch) | 2520 | if (NULL != update_srch) |
2493 | { | 2521 | { |
2494 | drh = | 2522 | drh = |
2495 | get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); | 2523 | get_read_handle(sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); |
2496 | if (NULL != drh) | 2524 | if (NULL != drh) |
2497 | { | 2525 | { |
2498 | deserialize_search (sc->h, drh, sr, update_srch); | 2526 | deserialize_search(sc->h, drh, sr, update_srch); |
2499 | if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) | 2527 | if (GNUNET_OK != GNUNET_BIO_read_close(drh, &emsg)) |
2500 | { | 2528 | { |
2501 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2529 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2502 | _ ("Failed to resume sub-search `%s': %s\n"), | 2530 | _("Failed to resume sub-search `%s': %s\n"), |
2503 | update_srch, | 2531 | update_srch, |
2504 | emsg); | 2532 | emsg); |
2505 | GNUNET_free (emsg); | 2533 | GNUNET_free(emsg); |
2506 | } | 2534 | } |
2507 | } | 2535 | } |
2508 | GNUNET_free (update_srch); | 2536 | GNUNET_free(update_srch); |
2509 | } | 2537 | } |
2510 | GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_multihashmap_put ( | 2538 | GNUNET_break(GNUNET_YES == GNUNET_CONTAINER_multihashmap_put( |
2511 | sc->master_result_map, | 2539 | sc->master_result_map, |
2512 | &sr->key, | 2540 | &sr->key, |
2513 | sr, | 2541 | sr, |
2514 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 2542 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
2515 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2543 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
2516 | { | 2544 | { |
2517 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2545 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2518 | _ ("Failure while resuming search operation `%s': %s\n"), | 2546 | _("Failure while resuming search operation `%s': %s\n"), |
2519 | filename, | 2547 | filename, |
2520 | emsg); | 2548 | emsg); |
2521 | GNUNET_free (emsg); | 2549 | GNUNET_free(emsg); |
2522 | } | 2550 | } |
2523 | return GNUNET_OK; | 2551 | return GNUNET_OK; |
2524 | cleanup: | 2552 | cleanup: |
2525 | GNUNET_free_non_null (download); | 2553 | GNUNET_free_non_null(download); |
2526 | GNUNET_free_non_null (emsg); | 2554 | GNUNET_free_non_null(emsg); |
2527 | GNUNET_free_non_null (uris); | 2555 | GNUNET_free_non_null(uris); |
2528 | GNUNET_free_non_null (update_srch); | 2556 | GNUNET_free_non_null(update_srch); |
2529 | if (NULL != sr->uri) | 2557 | if (NULL != sr->uri) |
2530 | GNUNET_FS_uri_destroy (sr->uri); | 2558 | GNUNET_FS_uri_destroy(sr->uri); |
2531 | if (NULL != sr->meta) | 2559 | if (NULL != sr->meta) |
2532 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); | 2560 | GNUNET_CONTAINER_meta_data_destroy(sr->meta); |
2533 | GNUNET_free (sr->serialization); | 2561 | GNUNET_free(sr->serialization); |
2534 | GNUNET_free (sr); | 2562 | GNUNET_free(sr); |
2535 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2563 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
2536 | { | 2564 | { |
2537 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2565 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2538 | _ ("Failure while resuming search operation `%s': %s\n"), | 2566 | _("Failure while resuming search operation `%s': %s\n"), |
2539 | filename, | 2567 | filename, |
2540 | emsg); | 2568 | emsg); |
2541 | GNUNET_free (emsg); | 2569 | GNUNET_free(emsg); |
2542 | } | 2570 | } |
2543 | return GNUNET_OK; | 2571 | return GNUNET_OK; |
2544 | } | 2572 | } |
2545 | 2573 | ||
@@ -2553,7 +2581,7 @@ cleanup: | |||
2553 | * @param dc download to resume | 2581 | * @param dc download to resume |
2554 | */ | 2582 | */ |
2555 | static void | 2583 | static void |
2556 | signal_download_resume (struct GNUNET_FS_DownloadContext *dc) | 2584 | signal_download_resume(struct GNUNET_FS_DownloadContext *dc) |
2557 | { | 2585 | { |
2558 | struct GNUNET_FS_DownloadContext *dcc; | 2586 | struct GNUNET_FS_DownloadContext *dcc; |
2559 | struct GNUNET_FS_ProgressInfo pi; | 2587 | struct GNUNET_FS_ProgressInfo pi; |
@@ -2561,13 +2589,13 @@ signal_download_resume (struct GNUNET_FS_DownloadContext *dc) | |||
2561 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME; | 2589 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME; |
2562 | pi.value.download.specifics.resume.meta = dc->meta; | 2590 | pi.value.download.specifics.resume.meta = dc->meta; |
2563 | pi.value.download.specifics.resume.message = dc->emsg; | 2591 | pi.value.download.specifics.resume.message = dc->emsg; |
2564 | GNUNET_FS_download_make_status_ (&pi, dc); | 2592 | GNUNET_FS_download_make_status_(&pi, dc); |
2565 | dcc = dc->child_head; | 2593 | dcc = dc->child_head; |
2566 | while (NULL != dcc) | 2594 | while (NULL != dcc) |
2567 | { | 2595 | { |
2568 | signal_download_resume (dcc); | 2596 | signal_download_resume(dcc); |
2569 | dcc = dcc->next; | 2597 | dcc = dcc->next; |
2570 | } | 2598 | } |
2571 | } | 2599 | } |
2572 | 2600 | ||
2573 | 2601 | ||
@@ -2578,7 +2606,7 @@ signal_download_resume (struct GNUNET_FS_DownloadContext *dc) | |||
2578 | * @param sc search being resumed | 2606 | * @param sc search being resumed |
2579 | */ | 2607 | */ |
2580 | static void | 2608 | static void |
2581 | signal_search_resume (struct GNUNET_FS_SearchContext *sc); | 2609 | signal_search_resume(struct GNUNET_FS_SearchContext *sc); |
2582 | 2610 | ||
2583 | 2611 | ||
2584 | /** | 2612 | /** |
@@ -2591,36 +2619,36 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc); | |||
2591 | * @return #GNUNET_YES (we should continue to iterate) | 2619 | * @return #GNUNET_YES (we should continue to iterate) |
2592 | */ | 2620 | */ |
2593 | static int | 2621 | static int |
2594 | signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value) | 2622 | signal_result_resume(void *cls, const struct GNUNET_HashCode *key, void *value) |
2595 | { | 2623 | { |
2596 | struct GNUNET_FS_SearchContext *sc = cls; | 2624 | struct GNUNET_FS_SearchContext *sc = cls; |
2597 | struct GNUNET_FS_ProgressInfo pi; | 2625 | struct GNUNET_FS_ProgressInfo pi; |
2598 | struct GNUNET_FS_SearchResult *sr = value; | 2626 | struct GNUNET_FS_SearchResult *sr = value; |
2599 | 2627 | ||
2600 | if (0 == sr->mandatory_missing) | 2628 | if (0 == sr->mandatory_missing) |
2601 | { | 2629 | { |
2602 | pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT; | 2630 | pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT; |
2603 | pi.value.search.specifics.resume_result.meta = sr->meta; | 2631 | pi.value.search.specifics.resume_result.meta = sr->meta; |
2604 | pi.value.search.specifics.resume_result.uri = sr->uri; | 2632 | pi.value.search.specifics.resume_result.uri = sr->uri; |
2605 | pi.value.search.specifics.resume_result.result = sr; | 2633 | pi.value.search.specifics.resume_result.result = sr; |
2606 | pi.value.search.specifics.resume_result.availability_rank = | 2634 | pi.value.search.specifics.resume_result.availability_rank = |
2607 | 2 * sr->availability_success - sr->availability_trials; | 2635 | 2 * sr->availability_success - sr->availability_trials; |
2608 | pi.value.search.specifics.resume_result.availability_certainty = | 2636 | pi.value.search.specifics.resume_result.availability_certainty = |
2609 | sr->availability_trials; | 2637 | sr->availability_trials; |
2610 | pi.value.search.specifics.resume_result.applicability_rank = | 2638 | pi.value.search.specifics.resume_result.applicability_rank = |
2611 | sr->optional_support; | 2639 | sr->optional_support; |
2612 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 2640 | sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); |
2613 | } | 2641 | } |
2614 | if (NULL != sr->download) | 2642 | if (NULL != sr->download) |
2615 | { | 2643 | { |
2616 | signal_download_resume (sr->download); | 2644 | signal_download_resume(sr->download); |
2617 | } | 2645 | } |
2618 | else | 2646 | else |
2619 | { | 2647 | { |
2620 | GNUNET_FS_search_start_probe_ (sr); | 2648 | GNUNET_FS_search_start_probe_(sr); |
2621 | } | 2649 | } |
2622 | if (NULL != sr->update_search) | 2650 | if (NULL != sr->update_search) |
2623 | signal_search_resume (sr->update_search); | 2651 | signal_search_resume(sr->update_search); |
2624 | return GNUNET_YES; | 2652 | return GNUNET_YES; |
2625 | } | 2653 | } |
2626 | 2654 | ||
@@ -2631,7 +2659,7 @@ signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
2631 | * @param sc search context to free | 2659 | * @param sc search context to free |
2632 | */ | 2660 | */ |
2633 | static void | 2661 | static void |
2634 | free_search_context (struct GNUNET_FS_SearchContext *sc); | 2662 | free_search_context(struct GNUNET_FS_SearchContext *sc); |
2635 | 2663 | ||
2636 | 2664 | ||
2637 | /** | 2665 | /** |
@@ -2643,18 +2671,18 @@ free_search_context (struct GNUNET_FS_SearchContext *sc); | |||
2643 | * @return #GNUNET_YES (we should continue to iterate) | 2671 | * @return #GNUNET_YES (we should continue to iterate) |
2644 | */ | 2672 | */ |
2645 | static int | 2673 | static int |
2646 | free_result (void *cls, const struct GNUNET_HashCode *key, void *value) | 2674 | free_result(void *cls, const struct GNUNET_HashCode *key, void *value) |
2647 | { | 2675 | { |
2648 | struct GNUNET_FS_SearchResult *sr = value; | 2676 | struct GNUNET_FS_SearchResult *sr = value; |
2649 | 2677 | ||
2650 | if (NULL != sr->update_search) | 2678 | if (NULL != sr->update_search) |
2651 | { | 2679 | { |
2652 | free_search_context (sr->update_search); | 2680 | free_search_context(sr->update_search); |
2653 | GNUNET_assert (NULL == sr->update_search); | 2681 | GNUNET_assert(NULL == sr->update_search); |
2654 | } | 2682 | } |
2655 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); | 2683 | GNUNET_CONTAINER_meta_data_destroy(sr->meta); |
2656 | GNUNET_FS_uri_destroy (sr->uri); | 2684 | GNUNET_FS_uri_destroy(sr->uri); |
2657 | GNUNET_free (sr); | 2685 | GNUNET_free(sr); |
2658 | return GNUNET_YES; | 2686 | return GNUNET_YES; |
2659 | } | 2687 | } |
2660 | 2688 | ||
@@ -2665,33 +2693,33 @@ free_result (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
2665 | * @param sc search context to free | 2693 | * @param sc search context to free |
2666 | */ | 2694 | */ |
2667 | static void | 2695 | static void |
2668 | free_search_context (struct GNUNET_FS_SearchContext *sc) | 2696 | free_search_context(struct GNUNET_FS_SearchContext *sc) |
2669 | { | 2697 | { |
2670 | if (NULL != sc->serialization) | 2698 | if (NULL != sc->serialization) |
2671 | { | 2699 | { |
2672 | GNUNET_FS_remove_sync_file_ (sc->h, | 2700 | GNUNET_FS_remove_sync_file_(sc->h, |
2673 | (sc->psearch_result == NULL) | 2701 | (sc->psearch_result == NULL) |
2674 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | ||
2675 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | ||
2676 | sc->serialization); | ||
2677 | GNUNET_FS_remove_sync_dir_ (sc->h, | ||
2678 | (sc->psearch_result == NULL) | ||
2679 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2702 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2680 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2703 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2681 | sc->serialization); | 2704 | sc->serialization); |
2682 | } | 2705 | GNUNET_FS_remove_sync_dir_(sc->h, |
2683 | GNUNET_free_non_null (sc->serialization); | 2706 | (sc->psearch_result == NULL) |
2684 | GNUNET_free_non_null (sc->emsg); | 2707 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2708 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | ||
2709 | sc->serialization); | ||
2710 | } | ||
2711 | GNUNET_free_non_null(sc->serialization); | ||
2712 | GNUNET_free_non_null(sc->emsg); | ||
2685 | if (NULL != sc->uri) | 2713 | if (NULL != sc->uri) |
2686 | GNUNET_FS_uri_destroy (sc->uri); | 2714 | GNUNET_FS_uri_destroy(sc->uri); |
2687 | if (NULL != sc->master_result_map) | 2715 | if (NULL != sc->master_result_map) |
2688 | { | 2716 | { |
2689 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 2717 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, |
2690 | &free_result, | 2718 | &free_result, |
2691 | sc); | 2719 | sc); |
2692 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); | 2720 | GNUNET_CONTAINER_multihashmap_destroy(sc->master_result_map); |
2693 | } | 2721 | } |
2694 | GNUNET_free (sc); | 2722 | GNUNET_free(sc); |
2695 | } | 2723 | } |
2696 | 2724 | ||
2697 | 2725 | ||
@@ -2704,35 +2732,35 @@ free_search_context (struct GNUNET_FS_SearchContext *sc) | |||
2704 | * @return #GNUNET_OK (continue to iterate) | 2732 | * @return #GNUNET_OK (continue to iterate) |
2705 | */ | 2733 | */ |
2706 | static int | 2734 | static int |
2707 | deserialize_subdownload (void *cls, const char *filename) | 2735 | deserialize_subdownload(void *cls, const char *filename) |
2708 | { | 2736 | { |
2709 | struct GNUNET_FS_DownloadContext *parent = cls; | 2737 | struct GNUNET_FS_DownloadContext *parent = cls; |
2710 | char *ser; | 2738 | char *ser; |
2711 | char *emsg; | 2739 | char *emsg; |
2712 | struct GNUNET_BIO_ReadHandle *rh; | 2740 | struct GNUNET_BIO_ReadHandle *rh; |
2713 | 2741 | ||
2714 | ser = get_serialization_short_name (filename); | 2742 | ser = get_serialization_short_name(filename); |
2715 | rh = GNUNET_BIO_read_open (filename); | 2743 | rh = GNUNET_BIO_read_open(filename); |
2716 | if (NULL == rh) | 2744 | if (NULL == rh) |
2717 | { | 2745 | { |
2718 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2746 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2719 | _ ( | 2747 | _( |
2720 | "Failed to resume sub-download `%s': could not open file `%s'\n"), | 2748 | "Failed to resume sub-download `%s': could not open file `%s'\n"), |
2721 | ser, | 2749 | ser, |
2722 | filename); | 2750 | filename); |
2723 | GNUNET_free (ser); | 2751 | GNUNET_free(ser); |
2724 | return GNUNET_OK; | 2752 | return GNUNET_OK; |
2725 | } | 2753 | } |
2726 | deserialize_download (parent->h, rh, parent, NULL, ser); | 2754 | deserialize_download(parent->h, rh, parent, NULL, ser); |
2727 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2755 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
2728 | { | 2756 | { |
2729 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2757 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2730 | _ ("Failed to resume sub-download `%s': %s\n"), | 2758 | _("Failed to resume sub-download `%s': %s\n"), |
2731 | ser, | 2759 | ser, |
2732 | emsg); | 2760 | emsg); |
2733 | GNUNET_free (emsg); | 2761 | GNUNET_free(emsg); |
2734 | } | 2762 | } |
2735 | GNUNET_free (ser); | 2763 | GNUNET_free(ser); |
2736 | return GNUNET_OK; | 2764 | return GNUNET_OK; |
2737 | } | 2765 | } |
2738 | 2766 | ||
@@ -2745,27 +2773,27 @@ deserialize_subdownload (void *cls, const char *filename) | |||
2745 | * @param dc context to free | 2773 | * @param dc context to free |
2746 | */ | 2774 | */ |
2747 | static void | 2775 | static void |
2748 | free_download_context (struct GNUNET_FS_DownloadContext *dc) | 2776 | free_download_context(struct GNUNET_FS_DownloadContext *dc) |
2749 | { | 2777 | { |
2750 | struct GNUNET_FS_DownloadContext *dcc; | 2778 | struct GNUNET_FS_DownloadContext *dcc; |
2751 | 2779 | ||
2752 | if (NULL != dc->meta) | 2780 | if (NULL != dc->meta) |
2753 | GNUNET_CONTAINER_meta_data_destroy (dc->meta); | 2781 | GNUNET_CONTAINER_meta_data_destroy(dc->meta); |
2754 | if (NULL != dc->uri) | 2782 | if (NULL != dc->uri) |
2755 | GNUNET_FS_uri_destroy (dc->uri); | 2783 | GNUNET_FS_uri_destroy(dc->uri); |
2756 | GNUNET_free_non_null (dc->temp_filename); | 2784 | GNUNET_free_non_null(dc->temp_filename); |
2757 | GNUNET_free_non_null (dc->emsg); | 2785 | GNUNET_free_non_null(dc->emsg); |
2758 | GNUNET_free_non_null (dc->filename); | 2786 | GNUNET_free_non_null(dc->filename); |
2759 | GNUNET_free_non_null (dc->serialization); | 2787 | GNUNET_free_non_null(dc->serialization); |
2760 | while (NULL != (dcc = dc->child_head)) | 2788 | while (NULL != (dcc = dc->child_head)) |
2761 | { | 2789 | { |
2762 | GNUNET_CONTAINER_DLL_remove (dc->child_head, dc->child_tail, dcc); | 2790 | GNUNET_CONTAINER_DLL_remove(dc->child_head, dc->child_tail, dcc); |
2763 | free_download_context (dcc); | 2791 | free_download_context(dcc); |
2764 | } | 2792 | } |
2765 | GNUNET_FS_free_download_request_ (dc->top_request); | 2793 | GNUNET_FS_free_download_request_(dc->top_request); |
2766 | if (NULL != dc->active) | 2794 | if (NULL != dc->active) |
2767 | GNUNET_CONTAINER_multihashmap_destroy (dc->active); | 2795 | GNUNET_CONTAINER_multihashmap_destroy(dc->active); |
2768 | GNUNET_free (dc); | 2796 | GNUNET_free(dc); |
2769 | } | 2797 | } |
2770 | 2798 | ||
2771 | 2799 | ||
@@ -2779,11 +2807,11 @@ free_download_context (struct GNUNET_FS_DownloadContext *dc) | |||
2779 | * @param serialization name under which the search was serialized | 2807 | * @param serialization name under which the search was serialized |
2780 | */ | 2808 | */ |
2781 | static void | 2809 | static void |
2782 | deserialize_download (struct GNUNET_FS_Handle *h, | 2810 | deserialize_download(struct GNUNET_FS_Handle *h, |
2783 | struct GNUNET_BIO_ReadHandle *rh, | 2811 | struct GNUNET_BIO_ReadHandle *rh, |
2784 | struct GNUNET_FS_DownloadContext *parent, | 2812 | struct GNUNET_FS_DownloadContext *parent, |
2785 | struct GNUNET_FS_SearchResult *search, | 2813 | struct GNUNET_FS_SearchResult *search, |
2786 | const char *serialization) | 2814 | const char *serialization) |
2787 | { | 2815 | { |
2788 | struct GNUNET_FS_DownloadContext *dc; | 2816 | struct GNUNET_FS_DownloadContext *dc; |
2789 | char *emsg; | 2817 | char *emsg; |
@@ -2794,86 +2822,86 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2794 | 2822 | ||
2795 | uris = NULL; | 2823 | uris = NULL; |
2796 | emsg = NULL; | 2824 | emsg = NULL; |
2797 | dc = GNUNET_new (struct GNUNET_FS_DownloadContext); | 2825 | dc = GNUNET_new(struct GNUNET_FS_DownloadContext); |
2798 | dc->parent = parent; | 2826 | dc->parent = parent; |
2799 | dc->h = h; | 2827 | dc->h = h; |
2800 | dc->serialization = GNUNET_strdup (serialization); | 2828 | dc->serialization = GNUNET_strdup(serialization); |
2801 | if ((GNUNET_OK != | 2829 | if ((GNUNET_OK != |
2802 | GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) || | 2830 | GNUNET_BIO_read_string(rh, "download-uri", &uris, 10 * 1024)) || |
2803 | (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || | 2831 | (NULL == (dc->uri = GNUNET_FS_uri_parse(uris, &emsg))) || |
2804 | ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && | 2832 | ((GNUNET_YES != GNUNET_FS_uri_test_chk(dc->uri)) && |
2805 | (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || | 2833 | (GNUNET_YES != GNUNET_FS_uri_test_loc(dc->uri))) || |
2806 | (GNUNET_OK != | 2834 | (GNUNET_OK != |
2807 | GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) || | 2835 | GNUNET_BIO_read_meta_data(rh, "download-meta", &dc->meta)) || |
2808 | (GNUNET_OK != | 2836 | (GNUNET_OK != |
2809 | GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) || | 2837 | GNUNET_BIO_read_string(rh, "download-emsg", &dc->emsg, 10 * 1024)) || |
2810 | (GNUNET_OK != | 2838 | (GNUNET_OK != |
2811 | GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || | 2839 | GNUNET_BIO_read_string(rh, "download-fn", &dc->filename, 10 * 1024)) || |
2812 | (GNUNET_OK != GNUNET_BIO_read_string (rh, | 2840 | (GNUNET_OK != GNUNET_BIO_read_string(rh, |
2813 | "download-tfn", | 2841 | "download-tfn", |
2814 | &dc->temp_filename, | 2842 | &dc->temp_filename, |
2815 | 10 * 1024)) || | 2843 | 10 * 1024)) || |
2816 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || | 2844 | (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->old_file_size)) || |
2817 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) || | 2845 | (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->offset)) || |
2818 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) || | 2846 | (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->length)) || |
2819 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->completed)) || | 2847 | (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->completed)) || |
2820 | (GNUNET_OK != read_start_time (rh, &dc->start_time)) || | 2848 | (GNUNET_OK != read_start_time(rh, &dc->start_time)) || |
2821 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dc->anonymity)) || | 2849 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &dc->anonymity)) || |
2822 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 2850 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &options)) || |
2823 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &status))) | 2851 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &status))) |
2824 | { | 2852 | { |
2825 | GNUNET_break (0); | 2853 | GNUNET_break(0); |
2826 | goto cleanup; | 2854 | goto cleanup; |
2827 | } | 2855 | } |
2828 | dc->options = (enum GNUNET_FS_DownloadOptions) options; | 2856 | dc->options = (enum GNUNET_FS_DownloadOptions)options; |
2829 | dc->active = | 2857 | dc->active = |
2830 | GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE), | 2858 | GNUNET_CONTAINER_multihashmap_create(1 + 2 * (dc->length / DBLOCK_SIZE), |
2831 | GNUNET_NO); | 2859 | GNUNET_NO); |
2832 | dc->has_finished = (int) status; | 2860 | dc->has_finished = (int)status; |
2833 | dc->treedepth = | 2861 | dc->treedepth = |
2834 | GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); | 2862 | GNUNET_FS_compute_depth(GNUNET_FS_uri_chk_get_file_size(dc->uri)); |
2835 | if (GNUNET_FS_uri_test_loc (dc->uri)) | 2863 | if (GNUNET_FS_uri_test_loc(dc->uri)) |
2836 | GNUNET_assert (GNUNET_OK == | 2864 | GNUNET_assert(GNUNET_OK == |
2837 | GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target)); | 2865 | GNUNET_FS_uri_loc_get_peer_identity(dc->uri, &dc->target)); |
2838 | if (NULL == dc->emsg) | 2866 | if (NULL == dc->emsg) |
2839 | { | ||
2840 | dc->top_request = read_download_request (rh); | ||
2841 | if (NULL == dc->top_request) | ||
2842 | { | 2867 | { |
2843 | GNUNET_break (0); | 2868 | dc->top_request = read_download_request(rh); |
2844 | goto cleanup; | 2869 | if (NULL == dc->top_request) |
2870 | { | ||
2871 | GNUNET_break(0); | ||
2872 | goto cleanup; | ||
2873 | } | ||
2845 | } | 2874 | } |
2846 | } | 2875 | dn = get_download_sync_filename(dc, dc->serialization, ".dir"); |
2847 | dn = get_download_sync_filename (dc, dc->serialization, ".dir"); | ||
2848 | if (NULL != dn) | 2876 | if (NULL != dn) |
2849 | { | 2877 | { |
2850 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) | 2878 | if (GNUNET_YES == GNUNET_DISK_directory_test(dn, GNUNET_YES)) |
2851 | GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc); | 2879 | GNUNET_DISK_directory_scan(dn, &deserialize_subdownload, dc); |
2852 | GNUNET_free (dn); | 2880 | GNUNET_free(dn); |
2853 | } | 2881 | } |
2854 | if (NULL != parent) | 2882 | if (NULL != parent) |
2855 | { | 2883 | { |
2856 | GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); | 2884 | GNUNET_CONTAINER_DLL_insert(parent->child_head, parent->child_tail, dc); |
2857 | } | 2885 | } |
2858 | if (NULL != search) | 2886 | if (NULL != search) |
2859 | { | 2887 | { |
2860 | dc->search = search; | 2888 | dc->search = search; |
2861 | search->download = dc; | 2889 | search->download = dc; |
2862 | } | 2890 | } |
2863 | if ((NULL == parent) && (NULL == search)) | 2891 | if ((NULL == parent) && (NULL == search)) |
2864 | { | 2892 | { |
2865 | dc->top = | 2893 | dc->top = |
2866 | GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); | 2894 | GNUNET_FS_make_top(dc->h, &GNUNET_FS_download_signal_suspend_, dc); |
2867 | signal_download_resume (dc); | 2895 | signal_download_resume(dc); |
2868 | } | 2896 | } |
2869 | GNUNET_free (uris); | 2897 | GNUNET_free(uris); |
2870 | GNUNET_assert (NULL == dc->job_queue); | 2898 | GNUNET_assert(NULL == dc->job_queue); |
2871 | dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); | 2899 | dc->task = GNUNET_SCHEDULER_add_now(&GNUNET_FS_download_start_task_, dc); |
2872 | return; | 2900 | return; |
2873 | cleanup: | 2901 | cleanup: |
2874 | GNUNET_free_non_null (uris); | 2902 | GNUNET_free_non_null(uris); |
2875 | GNUNET_free_non_null (emsg); | 2903 | GNUNET_free_non_null(emsg); |
2876 | free_download_context (dc); | 2904 | free_download_context(dc); |
2877 | } | 2905 | } |
2878 | 2906 | ||
2879 | 2907 | ||
@@ -2884,7 +2912,7 @@ cleanup: | |||
2884 | * @param sc search being resumed | 2912 | * @param sc search being resumed |
2885 | */ | 2913 | */ |
2886 | static void | 2914 | static void |
2887 | signal_search_resume (struct GNUNET_FS_SearchContext *sc) | 2915 | signal_search_resume(struct GNUNET_FS_SearchContext *sc) |
2888 | { | 2916 | { |
2889 | struct GNUNET_FS_ProgressInfo pi; | 2917 | struct GNUNET_FS_ProgressInfo pi; |
2890 | 2918 | ||
@@ -2892,10 +2920,10 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc) | |||
2892 | pi.value.search.specifics.resume.message = sc->emsg; | 2920 | pi.value.search.specifics.resume.message = sc->emsg; |
2893 | pi.value.search.specifics.resume.is_paused = | 2921 | pi.value.search.specifics.resume.is_paused = |
2894 | (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO; | 2922 | (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO; |
2895 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 2923 | sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); |
2896 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 2924 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, |
2897 | &signal_result_resume, | 2925 | &signal_result_resume, |
2898 | sc); | 2926 | sc); |
2899 | } | 2927 | } |
2900 | 2928 | ||
2901 | 2929 | ||
@@ -2908,10 +2936,10 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc) | |||
2908 | * @param serialization name under which the search was serialized | 2936 | * @param serialization name under which the search was serialized |
2909 | */ | 2937 | */ |
2910 | static struct GNUNET_FS_SearchContext * | 2938 | static struct GNUNET_FS_SearchContext * |
2911 | deserialize_search (struct GNUNET_FS_Handle *h, | 2939 | deserialize_search(struct GNUNET_FS_Handle *h, |
2912 | struct GNUNET_BIO_ReadHandle *rh, | 2940 | struct GNUNET_BIO_ReadHandle *rh, |
2913 | struct GNUNET_FS_SearchResult *psearch_result, | 2941 | struct GNUNET_FS_SearchResult *psearch_result, |
2914 | const char *serialization) | 2942 | const char *serialization) |
2915 | { | 2943 | { |
2916 | struct GNUNET_FS_SearchContext *sc; | 2944 | struct GNUNET_FS_SearchContext *sc; |
2917 | char *emsg; | 2945 | char *emsg; |
@@ -2921,64 +2949,64 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2921 | char in_pause; | 2949 | char in_pause; |
2922 | 2950 | ||
2923 | if ((NULL != psearch_result) && (NULL != psearch_result->update_search)) | 2951 | if ((NULL != psearch_result) && (NULL != psearch_result->update_search)) |
2924 | { | 2952 | { |
2925 | GNUNET_break (0); | 2953 | GNUNET_break(0); |
2926 | return NULL; | 2954 | return NULL; |
2927 | } | 2955 | } |
2928 | uris = NULL; | 2956 | uris = NULL; |
2929 | emsg = NULL; | 2957 | emsg = NULL; |
2930 | sc = GNUNET_new (struct GNUNET_FS_SearchContext); | 2958 | sc = GNUNET_new(struct GNUNET_FS_SearchContext); |
2931 | if (NULL != psearch_result) | 2959 | if (NULL != psearch_result) |
2932 | { | 2960 | { |
2933 | sc->psearch_result = psearch_result; | 2961 | sc->psearch_result = psearch_result; |
2934 | psearch_result->update_search = sc; | 2962 | psearch_result->update_search = sc; |
2935 | } | 2963 | } |
2936 | sc->h = h; | 2964 | sc->h = h; |
2937 | sc->serialization = GNUNET_strdup (serialization); | 2965 | sc->serialization = GNUNET_strdup(serialization); |
2938 | if ((GNUNET_OK != | 2966 | if ((GNUNET_OK != |
2939 | GNUNET_BIO_read_string (rh, "search-uri", &uris, 10 * 1024)) || | 2967 | GNUNET_BIO_read_string(rh, "search-uri", &uris, 10 * 1024)) || |
2940 | (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || | 2968 | (NULL == (sc->uri = GNUNET_FS_uri_parse(uris, &emsg))) || |
2941 | ((GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) && | 2969 | ((GNUNET_YES != GNUNET_FS_uri_test_ksk(sc->uri)) && |
2942 | (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri))) || | 2970 | (GNUNET_YES != GNUNET_FS_uri_test_sks(sc->uri))) || |
2943 | (GNUNET_OK != read_start_time (rh, &sc->start_time)) || | 2971 | (GNUNET_OK != read_start_time(rh, &sc->start_time)) || |
2944 | (GNUNET_OK != | 2972 | (GNUNET_OK != |
2945 | GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) || | 2973 | GNUNET_BIO_read_string(rh, "search-emsg", &sc->emsg, 10 * 1024)) || |
2946 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 2974 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &options)) || |
2947 | (GNUNET_OK != | 2975 | (GNUNET_OK != |
2948 | GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) || | 2976 | GNUNET_BIO_read(rh, "search-pause", &in_pause, sizeof(in_pause))) || |
2949 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sc->anonymity))) | 2977 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sc->anonymity))) |
2950 | { | 2978 | { |
2951 | GNUNET_break (0); | 2979 | GNUNET_break(0); |
2952 | goto cleanup; | 2980 | goto cleanup; |
2953 | } | 2981 | } |
2954 | sc->options = (enum GNUNET_FS_SearchOptions) options; | 2982 | sc->options = (enum GNUNET_FS_SearchOptions)options; |
2955 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); | 2983 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create(16, GNUNET_NO); |
2956 | dn = get_serialization_file_name_in_dir (h, | 2984 | dn = get_serialization_file_name_in_dir(h, |
2957 | (NULL == sc->psearch_result) | 2985 | (NULL == sc->psearch_result) |
2958 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2986 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2959 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2987 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2960 | sc->serialization, | 2988 | sc->serialization, |
2961 | ""); | 2989 | ""); |
2962 | if (NULL != dn) | 2990 | if (NULL != dn) |
2963 | { | 2991 | { |
2964 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) | 2992 | if (GNUNET_YES == GNUNET_DISK_directory_test(dn, GNUNET_YES)) |
2965 | GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc); | 2993 | GNUNET_DISK_directory_scan(dn, &deserialize_search_result, sc); |
2966 | GNUNET_free (dn); | 2994 | GNUNET_free(dn); |
2967 | } | 2995 | } |
2968 | if (('\0' == in_pause) && | 2996 | if (('\0' == in_pause) && |
2969 | (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))) | 2997 | (GNUNET_OK != GNUNET_FS_search_start_searching_(sc))) |
2970 | { | 2998 | { |
2971 | GNUNET_log ( | 2999 | GNUNET_log( |
2972 | GNUNET_ERROR_TYPE_WARNING, | 3000 | GNUNET_ERROR_TYPE_WARNING, |
2973 | _ ("Could not resume running search, will resume as paused search\n")); | 3001 | _("Could not resume running search, will resume as paused search\n")); |
2974 | } | 3002 | } |
2975 | signal_search_resume (sc); | 3003 | signal_search_resume(sc); |
2976 | GNUNET_free (uris); | 3004 | GNUNET_free(uris); |
2977 | return sc; | 3005 | return sc; |
2978 | cleanup: | 3006 | cleanup: |
2979 | GNUNET_free_non_null (emsg); | 3007 | GNUNET_free_non_null(emsg); |
2980 | free_search_context (sc); | 3008 | free_search_context(sc); |
2981 | GNUNET_free_non_null (uris); | 3009 | GNUNET_free_non_null(uris); |
2982 | return NULL; | 3010 | return NULL; |
2983 | } | 3011 | } |
2984 | 3012 | ||
@@ -2992,7 +3020,7 @@ cleanup: | |||
2992 | * @return #GNUNET_OK (continue to iterate) | 3020 | * @return #GNUNET_OK (continue to iterate) |
2993 | */ | 3021 | */ |
2994 | static int | 3022 | static int |
2995 | deserialize_search_file (void *cls, const char *filename) | 3023 | deserialize_search_file(void *cls, const char *filename) |
2996 | { | 3024 | { |
2997 | struct GNUNET_FS_Handle *h = cls; | 3025 | struct GNUNET_FS_Handle *h = cls; |
2998 | char *ser; | 3026 | char *ser; |
@@ -3001,36 +3029,36 @@ deserialize_search_file (void *cls, const char *filename) | |||
3001 | struct GNUNET_FS_SearchContext *sc; | 3029 | struct GNUNET_FS_SearchContext *sc; |
3002 | struct stat buf; | 3030 | struct stat buf; |
3003 | 3031 | ||
3004 | if (0 != stat (filename, &buf)) | 3032 | if (0 != stat(filename, &buf)) |
3005 | { | 3033 | { |
3006 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | 3034 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
3007 | return GNUNET_OK; | 3035 | return GNUNET_OK; |
3008 | } | 3036 | } |
3009 | if (S_ISDIR (buf.st_mode)) | 3037 | if (S_ISDIR(buf.st_mode)) |
3010 | return GNUNET_OK; /* skip directories */ | 3038 | return GNUNET_OK; /* skip directories */ |
3011 | ser = get_serialization_short_name (filename); | 3039 | ser = get_serialization_short_name(filename); |
3012 | rh = GNUNET_BIO_read_open (filename); | 3040 | rh = GNUNET_BIO_read_open(filename); |
3013 | if (NULL == rh) | 3041 | if (NULL == rh) |
3014 | { | ||
3015 | if (NULL != ser) | ||
3016 | { | 3042 | { |
3017 | GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser); | 3043 | if (NULL != ser) |
3018 | GNUNET_free (ser); | 3044 | { |
3045 | GNUNET_FS_remove_sync_file_(h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser); | ||
3046 | GNUNET_free(ser); | ||
3047 | } | ||
3048 | return GNUNET_OK; | ||
3019 | } | 3049 | } |
3020 | return GNUNET_OK; | 3050 | sc = deserialize_search(h, rh, NULL, ser); |
3021 | } | ||
3022 | sc = deserialize_search (h, rh, NULL, ser); | ||
3023 | if (NULL != sc) | 3051 | if (NULL != sc) |
3024 | sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc); | 3052 | sc->top = GNUNET_FS_make_top(h, &GNUNET_FS_search_signal_suspend_, sc); |
3025 | GNUNET_free (ser); | 3053 | GNUNET_free(ser); |
3026 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 3054 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
3027 | { | 3055 | { |
3028 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3056 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3029 | _ ("Failure while resuming search operation `%s': %s\n"), | 3057 | _("Failure while resuming search operation `%s': %s\n"), |
3030 | filename, | 3058 | filename, |
3031 | emsg); | 3059 | emsg); |
3032 | GNUNET_free (emsg); | 3060 | GNUNET_free(emsg); |
3033 | } | 3061 | } |
3034 | return GNUNET_OK; | 3062 | return GNUNET_OK; |
3035 | } | 3063 | } |
3036 | 3064 | ||
@@ -3044,32 +3072,32 @@ deserialize_search_file (void *cls, const char *filename) | |||
3044 | * @return #GNUNET_OK (continue to iterate) | 3072 | * @return #GNUNET_OK (continue to iterate) |
3045 | */ | 3073 | */ |
3046 | static int | 3074 | static int |
3047 | deserialize_download_file (void *cls, const char *filename) | 3075 | deserialize_download_file(void *cls, const char *filename) |
3048 | { | 3076 | { |
3049 | struct GNUNET_FS_Handle *h = cls; | 3077 | struct GNUNET_FS_Handle *h = cls; |
3050 | char *ser; | 3078 | char *ser; |
3051 | char *emsg; | 3079 | char *emsg; |
3052 | struct GNUNET_BIO_ReadHandle *rh; | 3080 | struct GNUNET_BIO_ReadHandle *rh; |
3053 | 3081 | ||
3054 | ser = get_serialization_short_name (filename); | 3082 | ser = get_serialization_short_name(filename); |
3055 | rh = GNUNET_BIO_read_open (filename); | 3083 | rh = GNUNET_BIO_read_open(filename); |
3056 | if (NULL == rh) | 3084 | if (NULL == rh) |
3057 | { | 3085 | { |
3058 | if (0 != unlink (filename)) | 3086 | if (0 != unlink(filename)) |
3059 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 3087 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
3060 | GNUNET_free (ser); | 3088 | GNUNET_free(ser); |
3061 | return GNUNET_OK; | 3089 | return GNUNET_OK; |
3062 | } | 3090 | } |
3063 | deserialize_download (h, rh, NULL, NULL, ser); | 3091 | deserialize_download(h, rh, NULL, NULL, ser); |
3064 | GNUNET_free (ser); | 3092 | GNUNET_free(ser); |
3065 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 3093 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
3066 | { | 3094 | { |
3067 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3095 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3068 | _ ("Failure while resuming download operation `%s': %s\n"), | 3096 | _("Failure while resuming download operation `%s': %s\n"), |
3069 | filename, | 3097 | filename, |
3070 | emsg); | 3098 | emsg); |
3071 | GNUNET_free (emsg); | 3099 | GNUNET_free(emsg); |
3072 | } | 3100 | } |
3073 | return GNUNET_OK; | 3101 | return GNUNET_OK; |
3074 | } | 3102 | } |
3075 | 3103 | ||
@@ -3082,18 +3110,18 @@ deserialize_download_file (void *cls, const char *filename) | |||
3082 | * @param h the `struct GNUNET_FS_Handle *` | 3110 | * @param h the `struct GNUNET_FS_Handle *` |
3083 | */ | 3111 | */ |
3084 | static void | 3112 | static void |
3085 | deserialization_master (const char *master_path, | 3113 | deserialization_master(const char *master_path, |
3086 | GNUNET_FileNameCallback proc, | 3114 | GNUNET_FileNameCallback proc, |
3087 | struct GNUNET_FS_Handle *h) | 3115 | struct GNUNET_FS_Handle *h) |
3088 | { | 3116 | { |
3089 | char *dn; | 3117 | char *dn; |
3090 | 3118 | ||
3091 | dn = get_serialization_file_name (h, master_path, ""); | 3119 | dn = get_serialization_file_name(h, master_path, ""); |
3092 | if (NULL == dn) | 3120 | if (NULL == dn) |
3093 | return; | 3121 | return; |
3094 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) | 3122 | if (GNUNET_YES == GNUNET_DISK_directory_test(dn, GNUNET_YES)) |
3095 | GNUNET_DISK_directory_scan (dn, proc, h); | 3123 | GNUNET_DISK_directory_scan(dn, proc, h); |
3096 | GNUNET_free (dn); | 3124 | GNUNET_free(dn); |
3097 | } | 3125 | } |
3098 | 3126 | ||
3099 | 3127 | ||
@@ -3109,20 +3137,20 @@ deserialization_master (const char *master_path, | |||
3109 | * @return NULL on error | 3137 | * @return NULL on error |
3110 | */ | 3138 | */ |
3111 | struct GNUNET_FS_Handle * | 3139 | struct GNUNET_FS_Handle * |
3112 | GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 3140 | GNUNET_FS_start(const struct GNUNET_CONFIGURATION_Handle *cfg, |
3113 | const char *client_name, | 3141 | const char *client_name, |
3114 | GNUNET_FS_ProgressCallback upcb, | 3142 | GNUNET_FS_ProgressCallback upcb, |
3115 | void *upcb_cls, | 3143 | void *upcb_cls, |
3116 | enum GNUNET_FS_Flags flags, | 3144 | enum GNUNET_FS_Flags flags, |
3117 | ...) | 3145 | ...) |
3118 | { | 3146 | { |
3119 | struct GNUNET_FS_Handle *ret; | 3147 | struct GNUNET_FS_Handle *ret; |
3120 | enum GNUNET_FS_OPTIONS opt; | 3148 | enum GNUNET_FS_OPTIONS opt; |
3121 | va_list ap; | 3149 | va_list ap; |
3122 | 3150 | ||
3123 | ret = GNUNET_new (struct GNUNET_FS_Handle); | 3151 | ret = GNUNET_new(struct GNUNET_FS_Handle); |
3124 | ret->cfg = cfg; | 3152 | ret->cfg = cfg; |
3125 | ret->client_name = GNUNET_strdup (client_name); | 3153 | ret->client_name = GNUNET_strdup(client_name); |
3126 | ret->upcb = upcb; | 3154 | ret->upcb = upcb; |
3127 | ret->upcb_cls = upcb_cls; | 3155 | ret->upcb_cls = upcb_cls; |
3128 | ret->flags = flags; | 3156 | ret->flags = flags; |
@@ -3130,44 +3158,46 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3130 | ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS; | 3158 | ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS; |
3131 | ret->avg_block_latency = | 3159 | ret->avg_block_latency = |
3132 | GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ | 3160 | GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ |
3133 | va_start (ap, flags); | 3161 | va_start(ap, flags); |
3134 | while (GNUNET_FS_OPTIONS_END != | 3162 | while (GNUNET_FS_OPTIONS_END != |
3135 | (opt = GNUNET_VA_ARG_ENUM (ap, GNUNET_FS_OPTIONS))) | 3163 | (opt = GNUNET_VA_ARG_ENUM(ap, GNUNET_FS_OPTIONS))) |
3136 | { | ||
3137 | switch (opt) | ||
3138 | { | 3164 | { |
3139 | case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM: | 3165 | switch (opt) |
3140 | ret->max_parallel_downloads = va_arg (ap, unsigned int); | 3166 | { |
3167 | case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM: | ||
3168 | ret->max_parallel_downloads = va_arg(ap, unsigned int); | ||
3141 | 3169 | ||
3142 | break; | 3170 | break; |
3143 | case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM: | ||
3144 | ret->max_parallel_requests = va_arg (ap, unsigned int); | ||
3145 | 3171 | ||
3146 | break; | 3172 | case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM: |
3147 | default: | 3173 | ret->max_parallel_requests = va_arg(ap, unsigned int); |
3148 | GNUNET_break (0); | 3174 | |
3149 | GNUNET_free (ret->client_name); | 3175 | break; |
3150 | GNUNET_free (ret); | 3176 | |
3151 | va_end (ap); | 3177 | default: |
3152 | return NULL; | 3178 | GNUNET_break(0); |
3179 | GNUNET_free(ret->client_name); | ||
3180 | GNUNET_free(ret); | ||
3181 | va_end(ap); | ||
3182 | return NULL; | ||
3183 | } | ||
3153 | } | 3184 | } |
3154 | } | 3185 | va_end(ap); |
3155 | va_end (ap); | ||
3156 | if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) | 3186 | if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) |
3157 | { | 3187 | { |
3158 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 3188 | deserialization_master(GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
3159 | &deserialize_publish_file, | 3189 | &deserialize_publish_file, |
3160 | ret); | 3190 | ret); |
3161 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | 3191 | deserialization_master(GNUNET_FS_SYNC_PATH_MASTER_SEARCH, |
3162 | &deserialize_search_file, | 3192 | &deserialize_search_file, |
3163 | ret); | 3193 | ret); |
3164 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 3194 | deserialization_master(GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
3165 | &deserialize_download_file, | 3195 | &deserialize_download_file, |
3166 | ret); | 3196 | ret); |
3167 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 3197 | deserialization_master(GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
3168 | &deserialize_unindex_file, | 3198 | &deserialize_unindex_file, |
3169 | ret); | 3199 | ret); |
3170 | } | 3200 | } |
3171 | return ret; | 3201 | return ret; |
3172 | } | 3202 | } |
3173 | 3203 | ||
@@ -3182,14 +3212,14 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3182 | * @param h handle that was returned from #GNUNET_FS_start() | 3212 | * @param h handle that was returned from #GNUNET_FS_start() |
3183 | */ | 3213 | */ |
3184 | void | 3214 | void |
3185 | GNUNET_FS_stop (struct GNUNET_FS_Handle *h) | 3215 | GNUNET_FS_stop(struct GNUNET_FS_Handle *h) |
3186 | { | 3216 | { |
3187 | while (NULL != h->top_head) | 3217 | while (NULL != h->top_head) |
3188 | h->top_head->ssf (h->top_head->ssf_cls); | 3218 | h->top_head->ssf(h->top_head->ssf_cls); |
3189 | if (NULL != h->queue_job) | 3219 | if (NULL != h->queue_job) |
3190 | GNUNET_SCHEDULER_cancel (h->queue_job); | 3220 | GNUNET_SCHEDULER_cancel(h->queue_job); |
3191 | GNUNET_free (h->client_name); | 3221 | GNUNET_free(h->client_name); |
3192 | GNUNET_free (h); | 3222 | GNUNET_free(h); |
3193 | } | 3223 | } |
3194 | 3224 | ||
3195 | 3225 | ||
diff --git a/src/fs/fs_api.h b/src/fs/fs_api.h index ad054ef06..dcc487eb1 100644 --- a/src/fs/fs_api.h +++ b/src/fs/fs_api.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_api.h | 22 | * @file fs/fs_api.h |
@@ -90,9 +90,7 @@ | |||
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 | { | ||
95 | |||
96 | /** | 94 | /** |
97 | * Total size of the file in bytes. (network byte order (!)) | 95 | * Total size of the file in bytes. (network byte order (!)) |
98 | */ | 96 | */ |
@@ -102,7 +100,6 @@ struct FileIdentifier | |||
102 | * Query and key of the top GNUNET_EC_IBlock. | 100 | * Query and key of the top GNUNET_EC_IBlock. |
103 | */ | 101 | */ |
104 | struct ContentHashKey chk; | 102 | struct ContentHashKey chk; |
105 | |||
106 | }; | 103 | }; |
107 | 104 | ||
108 | 105 | ||
@@ -110,8 +107,7 @@ struct FileIdentifier | |||
110 | * Information about a file and its location | 107 | * Information about a file and its location |
111 | * (peer claiming to share the file). | 108 | * (peer claiming to share the file). |
112 | */ | 109 | */ |
113 | struct Location | 110 | struct Location { |
114 | { | ||
115 | /** | 111 | /** |
116 | * Information about the shared file. | 112 | * Information about the shared file. |
117 | */ | 113 | */ |
@@ -132,14 +128,12 @@ struct Location | |||
132 | * peer identity and expiration time. | 128 | * peer identity and expiration time. |
133 | */ | 129 | */ |
134 | struct GNUNET_CRYPTO_EddsaSignature contentSignature; | 130 | struct GNUNET_CRYPTO_EddsaSignature contentSignature; |
135 | |||
136 | }; | 131 | }; |
137 | 132 | ||
138 | /** | 133 | /** |
139 | * Types of URIs. | 134 | * Types of URIs. |
140 | */ | 135 | */ |
141 | enum GNUNET_FS_UriType | 136 | enum GNUNET_FS_UriType { |
142 | { | ||
143 | /** | 137 | /** |
144 | * Content-hash-key (simple file). | 138 | * Content-hash-key (simple file). |
145 | */ | 139 | */ |
@@ -165,17 +159,14 @@ enum GNUNET_FS_UriType | |||
165 | /** | 159 | /** |
166 | * A Universal Resource Identifier (URI), opaque. | 160 | * A Universal Resource Identifier (URI), opaque. |
167 | */ | 161 | */ |
168 | struct GNUNET_FS_Uri | 162 | struct GNUNET_FS_Uri { |
169 | { | ||
170 | /** | 163 | /** |
171 | * Type of the URI. | 164 | * Type of the URI. |
172 | */ | 165 | */ |
173 | enum GNUNET_FS_UriType type; | 166 | enum GNUNET_FS_UriType type; |
174 | 167 | ||
175 | union | 168 | union { |
176 | { | 169 | struct { |
177 | struct | ||
178 | { | ||
179 | /** | 170 | /** |
180 | * Keywords start with a '+' if they are mandatory (in which | 171 | * Keywords start with a '+' if they are mandatory (in which |
181 | * case the '+' is NOT part of the keyword) and with a simple | 172 | * case the '+' is NOT part of the keyword) and with a simple |
@@ -193,8 +184,7 @@ struct GNUNET_FS_Uri | |||
193 | unsigned int keywordCount; | 184 | unsigned int keywordCount; |
194 | } ksk; | 185 | } ksk; |
195 | 186 | ||
196 | struct | 187 | struct { |
197 | { | ||
198 | /** | 188 | /** |
199 | * Identifier of the namespace. | 189 | * Identifier of the namespace. |
200 | */ | 190 | */ |
@@ -205,7 +195,6 @@ struct GNUNET_FS_Uri | |||
205 | * namespace. | 195 | * namespace. |
206 | */ | 196 | */ |
207 | char *identifier; | 197 | char *identifier; |
208 | |||
209 | } sks; | 198 | } sks; |
210 | 199 | ||
211 | /** | 200 | /** |
@@ -220,7 +209,6 @@ struct GNUNET_FS_Uri | |||
220 | */ | 209 | */ |
221 | struct Location loc; | 210 | struct Location loc; |
222 | } data; | 211 | } data; |
223 | |||
224 | }; | 212 | }; |
225 | 213 | ||
226 | 214 | ||
@@ -228,9 +216,7 @@ struct GNUNET_FS_Uri | |||
228 | * Information for a file or directory that is | 216 | * Information for a file or directory that is |
229 | * about to be published. | 217 | * about to be published. |
230 | */ | 218 | */ |
231 | struct GNUNET_FS_FileInformation | 219 | struct GNUNET_FS_FileInformation { |
232 | { | ||
233 | |||
234 | /** | 220 | /** |
235 | * Files in a directory are kept as a linked list. | 221 | * Files in a directory are kept as a linked list. |
236 | */ | 222 | */ |
@@ -309,15 +295,11 @@ struct GNUNET_FS_FileInformation | |||
309 | /** | 295 | /** |
310 | * Data describing either the file or the directory. | 296 | * Data describing either the file or the directory. |
311 | */ | 297 | */ |
312 | union | 298 | union { |
313 | { | ||
314 | |||
315 | /** | 299 | /** |
316 | * Data for a file. | 300 | * Data for a file. |
317 | */ | 301 | */ |
318 | struct | 302 | struct { |
319 | { | ||
320 | |||
321 | /** | 303 | /** |
322 | * Function that can be used to read the data for the file. | 304 | * Function that can be used to read the data for the file. |
323 | */ | 305 | */ |
@@ -356,15 +338,12 @@ struct GNUNET_FS_FileInformation | |||
356 | * #GNUNET_YES if this step has been completed. | 338 | * #GNUNET_YES if this step has been completed. |
357 | */ | 339 | */ |
358 | int index_start_confirmed; | 340 | int index_start_confirmed; |
359 | |||
360 | } file; | 341 | } file; |
361 | 342 | ||
362 | /** | 343 | /** |
363 | * Data for a directory. | 344 | * Data for a directory. |
364 | */ | 345 | */ |
365 | struct | 346 | struct { |
366 | { | ||
367 | |||
368 | /** | 347 | /** |
369 | * Linked list of entries in the directory. | 348 | * Linked list of entries in the directory. |
370 | */ | 349 | */ |
@@ -391,9 +370,7 @@ struct GNUNET_FS_FileInformation | |||
391 | * Sum of all of the sizes of all of the files in the directory. | 370 | * Sum of all of the sizes of all of the files in the directory. |
392 | */ | 371 | */ |
393 | uint64_t contents_size; | 372 | uint64_t contents_size; |
394 | |||
395 | } dir; | 373 | } dir; |
396 | |||
397 | } data; | 374 | } data; |
398 | 375 | ||
399 | /** | 376 | /** |
@@ -405,15 +382,13 @@ struct GNUNET_FS_FileInformation | |||
405 | * Are we done publishing this file? | 382 | * Are we done publishing this file? |
406 | */ | 383 | */ |
407 | int is_published; | 384 | int is_published; |
408 | |||
409 | }; | 385 | }; |
410 | 386 | ||
411 | 387 | ||
412 | /** | 388 | /** |
413 | * Priorities for the queue. | 389 | * Priorities for the queue. |
414 | */ | 390 | */ |
415 | enum GNUNET_FS_QueuePriority | 391 | enum GNUNET_FS_QueuePriority { |
416 | { | ||
417 | /** | 392 | /** |
418 | * This is a probe (low priority). | 393 | * This is a probe (low priority). |
419 | */ | 394 | */ |
@@ -429,8 +404,7 @@ enum GNUNET_FS_QueuePriority | |||
429 | /** | 404 | /** |
430 | * Entry in the job queue. | 405 | * Entry in the job queue. |
431 | */ | 406 | */ |
432 | struct GNUNET_FS_QueueEntry | 407 | struct GNUNET_FS_QueueEntry { |
433 | { | ||
434 | /** | 408 | /** |
435 | * This is a linked list. | 409 | * This is a linked list. |
436 | */ | 410 | */ |
@@ -501,16 +475,13 @@ struct GNUNET_FS_QueueEntry | |||
501 | * #GNUNET_YES if the job is active now. | 475 | * #GNUNET_YES if the job is active now. |
502 | */ | 476 | */ |
503 | int active; | 477 | int active; |
504 | |||
505 | }; | 478 | }; |
506 | 479 | ||
507 | 480 | ||
508 | /** | 481 | /** |
509 | * Information we store for each search result. | 482 | * Information we store for each search result. |
510 | */ | 483 | */ |
511 | struct GNUNET_FS_SearchResult | 484 | struct GNUNET_FS_SearchResult { |
512 | { | ||
513 | |||
514 | /** | 485 | /** |
515 | * File-sharing context this result belongs to. | 486 | * File-sharing context this result belongs to. |
516 | */ | 487 | */ |
@@ -625,7 +596,6 @@ struct GNUNET_FS_SearchResult | |||
625 | * search result. | 596 | * search result. |
626 | */ | 597 | */ |
627 | uint32_t availability_trials; | 598 | uint32_t availability_trials; |
628 | |||
629 | }; | 599 | }; |
630 | 600 | ||
631 | 601 | ||
@@ -641,12 +611,12 @@ struct GNUNET_FS_SearchResult | |||
641 | * @return queue handle | 611 | * @return queue handle |
642 | */ | 612 | */ |
643 | struct GNUNET_FS_QueueEntry * | 613 | struct GNUNET_FS_QueueEntry * |
644 | GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, | 614 | GNUNET_FS_queue_(struct GNUNET_FS_Handle *h, |
645 | GNUNET_SCHEDULER_TaskCallback start, | 615 | GNUNET_SCHEDULER_TaskCallback start, |
646 | GNUNET_SCHEDULER_TaskCallback stop, | 616 | GNUNET_SCHEDULER_TaskCallback stop, |
647 | void *cls, | 617 | void *cls, |
648 | unsigned int blocks, | 618 | unsigned int blocks, |
649 | enum GNUNET_FS_QueuePriority priority); | 619 | enum GNUNET_FS_QueuePriority priority); |
650 | 620 | ||
651 | 621 | ||
652 | /** | 622 | /** |
@@ -655,7 +625,7 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, | |||
655 | * @param qe handle for the job | 625 | * @param qe handle for the job |
656 | */ | 626 | */ |
657 | void | 627 | void |
658 | GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe); | 628 | GNUNET_FS_dequeue_(struct GNUNET_FS_QueueEntry *qe); |
659 | 629 | ||
660 | 630 | ||
661 | /** | 631 | /** |
@@ -675,11 +645,11 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe); | |||
675 | * @return number of bytes written, usually "max", 0 on error | 645 | * @return number of bytes written, usually "max", 0 on error |
676 | */ | 646 | */ |
677 | size_t | 647 | size_t |
678 | GNUNET_FS_data_reader_file_ (void *cls, | 648 | GNUNET_FS_data_reader_file_(void *cls, |
679 | uint64_t offset, | 649 | uint64_t offset, |
680 | size_t max, | 650 | size_t max, |
681 | void *buf, | 651 | void *buf, |
682 | char **emsg); | 652 | char **emsg); |
683 | 653 | ||
684 | 654 | ||
685 | /** | 655 | /** |
@@ -689,7 +659,7 @@ GNUNET_FS_data_reader_file_ (void *cls, | |||
689 | * @return closure to use | 659 | * @return closure to use |
690 | */ | 660 | */ |
691 | void * | 661 | void * |
692 | GNUNET_FS_make_file_reader_context_ (const char *filename); | 662 | GNUNET_FS_make_file_reader_context_(const char *filename); |
693 | 663 | ||
694 | 664 | ||
695 | 665 | ||
@@ -710,11 +680,11 @@ GNUNET_FS_make_file_reader_context_ (const char *filename); | |||
710 | * @return number of bytes written, usually @a max, 0 on error | 680 | * @return number of bytes written, usually @a max, 0 on error |
711 | */ | 681 | */ |
712 | size_t | 682 | size_t |
713 | GNUNET_FS_data_reader_copy_ (void *cls, | 683 | GNUNET_FS_data_reader_copy_(void *cls, |
714 | uint64_t offset, | 684 | uint64_t offset, |
715 | size_t max, | 685 | size_t max, |
716 | void *buf, | 686 | void *buf, |
717 | char **emsg); | 687 | char **emsg); |
718 | 688 | ||
719 | 689 | ||
720 | /** | 690 | /** |
@@ -733,8 +703,8 @@ GNUNET_FS_data_reader_copy_ (void *cls, | |||
733 | * field in the `struct GNUNET_FS_ProgressInfo`. | 703 | * field in the `struct GNUNET_FS_ProgressInfo`. |
734 | */ | 704 | */ |
735 | void * | 705 | void * |
736 | GNUNET_FS_search_probe_progress_ (void *cls, | 706 | GNUNET_FS_search_probe_progress_(void *cls, |
737 | const struct GNUNET_FS_ProgressInfo *info); | 707 | const struct GNUNET_FS_ProgressInfo *info); |
738 | 708 | ||
739 | 709 | ||
740 | /** | 710 | /** |
@@ -743,7 +713,7 @@ GNUNET_FS_search_probe_progress_ (void *cls, | |||
743 | * @param cls `struct GNUNET_FS_PublishContext` identifies the upload | 713 | * @param cls `struct GNUNET_FS_PublishContext` identifies the upload |
744 | */ | 714 | */ |
745 | void | 715 | void |
746 | GNUNET_FS_publish_main_ (void *cls); | 716 | GNUNET_FS_publish_main_(void *cls); |
747 | 717 | ||
748 | 718 | ||
749 | /** | 719 | /** |
@@ -754,8 +724,8 @@ GNUNET_FS_publish_main_ (void *cls); | |||
754 | * @param file_id computed hash, NULL on error | 724 | * @param file_id computed hash, NULL on error |
755 | */ | 725 | */ |
756 | void | 726 | void |
757 | GNUNET_FS_unindex_process_hash_ (void *cls, | 727 | GNUNET_FS_unindex_process_hash_(void *cls, |
758 | const struct GNUNET_HashCode *file_id); | 728 | const struct GNUNET_HashCode *file_id); |
759 | 729 | ||
760 | 730 | ||
761 | /** | 731 | /** |
@@ -764,7 +734,7 @@ GNUNET_FS_unindex_process_hash_ (void *cls, | |||
764 | * @param uc context for the unindex operation. | 734 | * @param uc context for the unindex operation. |
765 | */ | 735 | */ |
766 | void | 736 | void |
767 | GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc); | 737 | GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc); |
768 | 738 | ||
769 | 739 | ||
770 | /** | 740 | /** |
@@ -773,7 +743,7 @@ GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc); | |||
773 | * @param uc context for the unindex operation. | 743 | * @param uc context for the unindex operation. |
774 | */ | 744 | */ |
775 | void | 745 | void |
776 | GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc); | 746 | GNUNET_FS_unindex_do_remove_kblocks_(struct GNUNET_FS_UnindexContext *uc); |
777 | 747 | ||
778 | 748 | ||
779 | /** | 749 | /** |
@@ -787,10 +757,10 @@ GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc); | |||
787 | * @return value returned from callback | 757 | * @return value returned from callback |
788 | */ | 758 | */ |
789 | void * | 759 | void * |
790 | GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | 760 | GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi, |
791 | struct GNUNET_FS_PublishContext *pc, | 761 | struct GNUNET_FS_PublishContext *pc, |
792 | const struct GNUNET_FS_FileInformation *p, | 762 | const struct GNUNET_FS_FileInformation *p, |
793 | uint64_t offset); | 763 | uint64_t offset); |
794 | 764 | ||
795 | 765 | ||
796 | /** | 766 | /** |
@@ -801,8 +771,8 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
801 | * @param dc overall download context | 771 | * @param dc overall download context |
802 | */ | 772 | */ |
803 | void | 773 | void |
804 | GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | 774 | GNUNET_FS_download_make_status_(struct GNUNET_FS_ProgressInfo *pi, |
805 | struct GNUNET_FS_DownloadContext *dc); | 775 | struct GNUNET_FS_DownloadContext *dc); |
806 | 776 | ||
807 | 777 | ||
808 | /** | 778 | /** |
@@ -812,7 +782,7 @@ GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
812 | * @param cls the 'struct GNUNET_FS_DownloadContext' | 782 | * @param cls the 'struct GNUNET_FS_DownloadContext' |
813 | */ | 783 | */ |
814 | void | 784 | void |
815 | GNUNET_FS_download_start_task_ (void *cls); | 785 | GNUNET_FS_download_start_task_(void *cls); |
816 | 786 | ||
817 | 787 | ||
818 | 788 | ||
@@ -825,9 +795,9 @@ GNUNET_FS_download_start_task_ (void *cls); | |||
825 | * @param offset where we are in the file (for progress) | 795 | * @param offset where we are in the file (for progress) |
826 | */ | 796 | */ |
827 | void | 797 | void |
828 | GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | 798 | GNUNET_FS_unindex_make_status_(struct GNUNET_FS_ProgressInfo *pi, |
829 | struct GNUNET_FS_UnindexContext *uc, | 799 | struct GNUNET_FS_UnindexContext *uc, |
830 | uint64_t offset); | 800 | uint64_t offset); |
831 | 801 | ||
832 | /** | 802 | /** |
833 | * Fill in all of the generic fields for a search event and | 803 | * Fill in all of the generic fields for a search event and |
@@ -839,9 +809,9 @@ GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
839 | * @return value returned by the callback | 809 | * @return value returned by the callback |
840 | */ | 810 | */ |
841 | void * | 811 | void * |
842 | GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | 812 | GNUNET_FS_search_make_status_(struct GNUNET_FS_ProgressInfo *pi, |
843 | struct GNUNET_FS_Handle *h, | 813 | struct GNUNET_FS_Handle *h, |
844 | struct GNUNET_FS_SearchContext *sc); | 814 | struct GNUNET_FS_SearchContext *sc); |
845 | 815 | ||
846 | 816 | ||
847 | /** | 817 | /** |
@@ -850,7 +820,7 @@ GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
850 | * @param uc context for the unindex operation. | 820 | * @param uc context for the unindex operation. |
851 | */ | 821 | */ |
852 | void | 822 | void |
853 | GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc); | 823 | GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc); |
854 | 824 | ||
855 | /** | 825 | /** |
856 | * Build the request and actually initiate the search using the | 826 | * Build the request and actually initiate the search using the |
@@ -860,7 +830,7 @@ GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc); | |||
860 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 830 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
861 | */ | 831 | */ |
862 | int | 832 | int |
863 | GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc); | 833 | GNUNET_FS_search_start_searching_(struct GNUNET_FS_SearchContext *sc); |
864 | 834 | ||
865 | /** | 835 | /** |
866 | * Start the downloading process (by entering the queue). | 836 | * Start the downloading process (by entering the queue). |
@@ -868,7 +838,7 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc); | |||
868 | * @param dc our download context | 838 | * @param dc our download context |
869 | */ | 839 | */ |
870 | void | 840 | void |
871 | GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc); | 841 | GNUNET_FS_download_start_downloading_(struct GNUNET_FS_DownloadContext *dc); |
872 | 842 | ||
873 | 843 | ||
874 | /** | 844 | /** |
@@ -877,7 +847,7 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc); | |||
877 | * @param sr the search result | 847 | * @param sr the search result |
878 | */ | 848 | */ |
879 | void | 849 | void |
880 | GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr); | 850 | GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr); |
881 | 851 | ||
882 | 852 | ||
883 | /** | 853 | /** |
@@ -888,9 +858,9 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr); | |||
888 | * @param ent entity identifier | 858 | * @param ent entity identifier |
889 | */ | 859 | */ |
890 | void | 860 | void |
891 | GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, | 861 | GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, |
892 | const char *ext, | 862 | const char *ext, |
893 | const char *ent); | 863 | const char *ent); |
894 | 864 | ||
895 | 865 | ||
896 | /** | 866 | /** |
@@ -901,9 +871,9 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, | |||
901 | * @param uni unique name of parent | 871 | * @param uni unique name of parent |
902 | */ | 872 | */ |
903 | void | 873 | void |
904 | GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, | 874 | GNUNET_FS_remove_sync_dir_(struct GNUNET_FS_Handle *h, |
905 | const char *ext, | 875 | const char *ext, |
906 | const char *uni); | 876 | const char *uni); |
907 | 877 | ||
908 | 878 | ||
909 | /** | 879 | /** |
@@ -915,7 +885,7 @@ GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, | |||
915 | * @param fi the struct to sync | 885 | * @param fi the struct to sync |
916 | */ | 886 | */ |
917 | void | 887 | void |
918 | GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f); | 888 | GNUNET_FS_file_information_sync_(struct GNUNET_FS_FileInformation *f); |
919 | 889 | ||
920 | 890 | ||
921 | /** | 891 | /** |
@@ -927,7 +897,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f); | |||
927 | * @param pc the struct to sync | 897 | * @param pc the struct to sync |
928 | */ | 898 | */ |
929 | void | 899 | void |
930 | GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc); | 900 | GNUNET_FS_publish_sync_(struct GNUNET_FS_PublishContext *pc); |
931 | 901 | ||
932 | 902 | ||
933 | /** | 903 | /** |
@@ -939,7 +909,7 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc); | |||
939 | * @param uc the struct to sync | 909 | * @param uc the struct to sync |
940 | */ | 910 | */ |
941 | void | 911 | void |
942 | GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc); | 912 | GNUNET_FS_unindex_sync_(struct GNUNET_FS_UnindexContext *uc); |
943 | 913 | ||
944 | 914 | ||
945 | /** | 915 | /** |
@@ -951,7 +921,7 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc); | |||
951 | * @param sc the struct to sync | 921 | * @param sc the struct to sync |
952 | */ | 922 | */ |
953 | void | 923 | void |
954 | GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc); | 924 | GNUNET_FS_search_sync_(struct GNUNET_FS_SearchContext *sc); |
955 | 925 | ||
956 | 926 | ||
957 | /** | 927 | /** |
@@ -963,7 +933,7 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc); | |||
963 | * @param sr the struct to sync | 933 | * @param sr the struct to sync |
964 | */ | 934 | */ |
965 | void | 935 | void |
966 | GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr); | 936 | GNUNET_FS_search_result_sync_(struct GNUNET_FS_SearchResult *sr); |
967 | 937 | ||
968 | 938 | ||
969 | /** | 939 | /** |
@@ -975,7 +945,7 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr); | |||
975 | * @param dc the struct to sync | 945 | * @param dc the struct to sync |
976 | */ | 946 | */ |
977 | void | 947 | void |
978 | GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc); | 948 | GNUNET_FS_download_sync_(struct GNUNET_FS_DownloadContext *dc); |
979 | 949 | ||
980 | 950 | ||
981 | /** | 951 | /** |
@@ -985,7 +955,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc); | |||
985 | * @param cls the `struct GNUNET_FS_PublishContext` to signal for | 955 | * @param cls the `struct GNUNET_FS_PublishContext` to signal for |
986 | */ | 956 | */ |
987 | void | 957 | void |
988 | GNUNET_FS_publish_signal_suspend_ (void *cls); | 958 | GNUNET_FS_publish_signal_suspend_(void *cls); |
989 | 959 | ||
990 | 960 | ||
991 | /** | 961 | /** |
@@ -995,7 +965,7 @@ GNUNET_FS_publish_signal_suspend_ (void *cls); | |||
995 | * @param cls the 'struct GNUNET_FS_SearchContext' to signal for | 965 | * @param cls the 'struct GNUNET_FS_SearchContext' to signal for |
996 | */ | 966 | */ |
997 | void | 967 | void |
998 | GNUNET_FS_search_signal_suspend_ (void *cls); | 968 | GNUNET_FS_search_signal_suspend_(void *cls); |
999 | 969 | ||
1000 | 970 | ||
1001 | /** | 971 | /** |
@@ -1005,7 +975,7 @@ GNUNET_FS_search_signal_suspend_ (void *cls); | |||
1005 | * @param cls the `struct GNUNET_FS_DownloadContext` to signal for | 975 | * @param cls the `struct GNUNET_FS_DownloadContext` to signal for |
1006 | */ | 976 | */ |
1007 | void | 977 | void |
1008 | GNUNET_FS_download_signal_suspend_ (void *cls); | 978 | GNUNET_FS_download_signal_suspend_(void *cls); |
1009 | 979 | ||
1010 | 980 | ||
1011 | /** | 981 | /** |
@@ -1015,7 +985,7 @@ GNUNET_FS_download_signal_suspend_ (void *cls); | |||
1015 | * @param cls the `struct GNUNET_FS_UnindexContext` to signal for | 985 | * @param cls the `struct GNUNET_FS_UnindexContext` to signal for |
1016 | */ | 986 | */ |
1017 | void | 987 | void |
1018 | GNUNET_FS_unindex_signal_suspend_ (void *cls); | 988 | GNUNET_FS_unindex_signal_suspend_(void *cls); |
1019 | 989 | ||
1020 | 990 | ||
1021 | /** | 991 | /** |
@@ -1031,8 +1001,7 @@ typedef void (*SuspendSignalFunction) (void *cls); | |||
1031 | * We track all of the top-level activities of FS | 1001 | * We track all of the top-level activities of FS |
1032 | * so that we can signal 'suspend' on shutdown. | 1002 | * so that we can signal 'suspend' on shutdown. |
1033 | */ | 1003 | */ |
1034 | struct TopLevelActivity | 1004 | struct TopLevelActivity { |
1035 | { | ||
1036 | /** | 1005 | /** |
1037 | * This is a doubly-linked list. | 1006 | * This is a doubly-linked list. |
1038 | */ | 1007 | */ |
@@ -1064,9 +1033,9 @@ struct TopLevelActivity | |||
1064 | * @return fresh top-level activity handle | 1033 | * @return fresh top-level activity handle |
1065 | */ | 1034 | */ |
1066 | struct TopLevelActivity * | 1035 | struct TopLevelActivity * |
1067 | GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, | 1036 | GNUNET_FS_make_top(struct GNUNET_FS_Handle *h, |
1068 | SuspendSignalFunction ssf, | 1037 | SuspendSignalFunction ssf, |
1069 | void *ssf_cls); | 1038 | void *ssf_cls); |
1070 | 1039 | ||
1071 | 1040 | ||
1072 | /** | 1041 | /** |
@@ -1076,16 +1045,15 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, | |||
1076 | * @param top top level activity entry | 1045 | * @param top top level activity entry |
1077 | */ | 1046 | */ |
1078 | void | 1047 | void |
1079 | GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, | 1048 | GNUNET_FS_end_top(struct GNUNET_FS_Handle *h, |
1080 | struct TopLevelActivity *top); | 1049 | struct TopLevelActivity *top); |
1081 | 1050 | ||
1082 | 1051 | ||
1083 | 1052 | ||
1084 | /** | 1053 | /** |
1085 | * Master context for most FS operations. | 1054 | * Master context for most FS operations. |
1086 | */ | 1055 | */ |
1087 | struct GNUNET_FS_Handle | 1056 | struct GNUNET_FS_Handle { |
1088 | { | ||
1089 | /** | 1057 | /** |
1090 | * Configuration to use. | 1058 | * Configuration to use. |
1091 | */ | 1059 | */ |
@@ -1188,15 +1156,13 @@ struct GNUNET_FS_Handle | |||
1188 | * Maximum number of parallel requests. | 1156 | * Maximum number of parallel requests. |
1189 | */ | 1157 | */ |
1190 | unsigned int max_parallel_requests; | 1158 | unsigned int max_parallel_requests; |
1191 | |||
1192 | }; | 1159 | }; |
1193 | 1160 | ||
1194 | 1161 | ||
1195 | /** | 1162 | /** |
1196 | * Handle for controlling a publication process. | 1163 | * Handle for controlling a publication process. |
1197 | */ | 1164 | */ |
1198 | struct GNUNET_FS_PublishContext | 1165 | struct GNUNET_FS_PublishContext { |
1199 | { | ||
1200 | /** | 1166 | /** |
1201 | * Handle to the global fs context. | 1167 | * Handle to the global fs context. |
1202 | */ | 1168 | */ |
@@ -1322,8 +1288,7 @@ struct GNUNET_FS_PublishContext | |||
1322 | /** | 1288 | /** |
1323 | * Phases of unindex processing (state machine). | 1289 | * Phases of unindex processing (state machine). |
1324 | */ | 1290 | */ |
1325 | enum UnindexState | 1291 | enum UnindexState { |
1326 | { | ||
1327 | /** | 1292 | /** |
1328 | * We're currently hashing the file. | 1293 | * We're currently hashing the file. |
1329 | */ | 1294 | */ |
@@ -1366,9 +1331,7 @@ enum UnindexState | |||
1366 | /** | 1331 | /** |
1367 | * Handle for controlling an unindexing operation. | 1332 | * Handle for controlling an unindexing operation. |
1368 | */ | 1333 | */ |
1369 | struct GNUNET_FS_UnindexContext | 1334 | struct GNUNET_FS_UnindexContext { |
1370 | { | ||
1371 | |||
1372 | /** | 1335 | /** |
1373 | * The content hash key of the last block we processed, will in the | 1336 | * The content hash key of the last block we processed, will in the |
1374 | * end be set to the CHK from the URI. Used to remove the KBlocks. | 1337 | * end be set to the CHK from the URI. Used to remove the KBlocks. |
@@ -1482,16 +1445,13 @@ struct GNUNET_FS_UnindexContext | |||
1482 | * Current operatinonal phase. | 1445 | * Current operatinonal phase. |
1483 | */ | 1446 | */ |
1484 | enum UnindexState state; | 1447 | enum UnindexState state; |
1485 | |||
1486 | }; | 1448 | }; |
1487 | 1449 | ||
1488 | 1450 | ||
1489 | /** | 1451 | /** |
1490 | * Information we keep for each keyword in a keyword search. | 1452 | * Information we keep for each keyword in a keyword search. |
1491 | */ | 1453 | */ |
1492 | struct SearchRequestEntry | 1454 | struct SearchRequestEntry { |
1493 | { | ||
1494 | |||
1495 | /** | 1455 | /** |
1496 | * Hash of the public key, also known as the query. | 1456 | * Hash of the public key, also known as the query. |
1497 | */ | 1457 | */ |
@@ -1523,15 +1483,13 @@ struct SearchRequestEntry | |||
1523 | * (started with '+')? | 1483 | * (started with '+')? |
1524 | */ | 1484 | */ |
1525 | int mandatory; | 1485 | int mandatory; |
1526 | |||
1527 | }; | 1486 | }; |
1528 | 1487 | ||
1529 | 1488 | ||
1530 | /** | 1489 | /** |
1531 | * Handle for controlling a search. | 1490 | * Handle for controlling a search. |
1532 | */ | 1491 | */ |
1533 | struct GNUNET_FS_SearchContext | 1492 | struct GNUNET_FS_SearchContext { |
1534 | { | ||
1535 | /** | 1493 | /** |
1536 | * Handle to the global FS context. | 1494 | * Handle to the global FS context. |
1537 | */ | 1495 | */ |
@@ -1627,8 +1585,7 @@ struct GNUNET_FS_SearchContext | |||
1627 | * order of progression is linear through the states, alternatives | 1585 | * order of progression is linear through the states, alternatives |
1628 | * are documented in the comments. | 1586 | * are documented in the comments. |
1629 | */ | 1587 | */ |
1630 | enum BlockRequestState | 1588 | enum BlockRequestState { |
1631 | { | ||
1632 | /** | 1589 | /** |
1633 | * Initial state, block has only been allocated (since it is | 1590 | * Initial state, block has only been allocated (since it is |
1634 | * relevant to the overall download request). | 1591 | * relevant to the overall download request). |
@@ -1695,9 +1652,7 @@ enum BlockRequestState | |||
1695 | /** | 1652 | /** |
1696 | * Information about an active download request. | 1653 | * Information about an active download request. |
1697 | */ | 1654 | */ |
1698 | struct DownloadRequest | 1655 | struct DownloadRequest { |
1699 | { | ||
1700 | |||
1701 | /** | 1656 | /** |
1702 | * Parent in the CHK-tree. | 1657 | * Parent in the CHK-tree. |
1703 | */ | 1658 | */ |
@@ -1740,7 +1695,6 @@ struct DownloadRequest | |||
1740 | * State in the FSM. | 1695 | * State in the FSM. |
1741 | */ | 1696 | */ |
1742 | enum BlockRequestState state; | 1697 | enum BlockRequestState state; |
1743 | |||
1744 | }; | 1698 | }; |
1745 | 1699 | ||
1746 | 1700 | ||
@@ -1750,7 +1704,7 @@ struct DownloadRequest | |||
1750 | * @param dr request to free | 1704 | * @param dr request to free |
1751 | */ | 1705 | */ |
1752 | void | 1706 | void |
1753 | GNUNET_FS_free_download_request_ (struct DownloadRequest *dr); | 1707 | GNUNET_FS_free_download_request_(struct DownloadRequest *dr); |
1754 | 1708 | ||
1755 | 1709 | ||
1756 | /** | 1710 | /** |
@@ -1759,15 +1713,13 @@ GNUNET_FS_free_download_request_ (struct DownloadRequest *dr); | |||
1759 | * @param sr result to start pinging for. | 1713 | * @param sr result to start pinging for. |
1760 | */ | 1714 | */ |
1761 | void | 1715 | void |
1762 | GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr); | 1716 | GNUNET_FS_stop_probe_ping_task_(struct GNUNET_FS_SearchResult *sr); |
1763 | 1717 | ||
1764 | 1718 | ||
1765 | /** | 1719 | /** |
1766 | * Context for controlling a download. | 1720 | * Context for controlling a download. |
1767 | */ | 1721 | */ |
1768 | struct GNUNET_FS_DownloadContext | 1722 | struct GNUNET_FS_DownloadContext { |
1769 | { | ||
1770 | |||
1771 | /** | 1723 | /** |
1772 | * Global FS context. | 1724 | * Global FS context. |
1773 | */ | 1725 | */ |
@@ -1959,7 +1911,6 @@ struct GNUNET_FS_DownloadContext | |||
1959 | * Are we ready to issue requests (reconstructions are finished)? | 1911 | * Are we ready to issue requests (reconstructions are finished)? |
1960 | */ | 1912 | */ |
1961 | int issue_requests; | 1913 | int issue_requests; |
1962 | |||
1963 | }; | 1914 | }; |
1964 | 1915 | ||
1965 | 1916 | ||
diff --git a/src/fs/fs_directory.c b/src/fs/fs_directory.c index 2dadc4835..ae7727cf0 100644 --- a/src/fs/fs_directory.c +++ b/src/fs/fs_directory.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_directory.c | 22 | * @file fs/fs_directory.c |
@@ -51,18 +51,18 @@ | |||
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 GNUNET_CONTAINER_MetaData *md) |
55 | { | 55 | { |
56 | char *mime; | 56 | char *mime; |
57 | int ret; | 57 | int ret; |
58 | 58 | ||
59 | if (NULL == md) | 59 | if (NULL == md) |
60 | return GNUNET_SYSERR; | 60 | return GNUNET_SYSERR; |
61 | mime = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE); | 61 | mime = GNUNET_CONTAINER_meta_data_get_by_type(md, EXTRACTOR_METATYPE_MIMETYPE); |
62 | if (NULL == mime) | 62 | if (NULL == mime) |
63 | return GNUNET_SYSERR; | 63 | return GNUNET_SYSERR; |
64 | ret = (0 == strcasecmp (mime, GNUNET_FS_DIRECTORY_MIME)) ? GNUNET_YES : GNUNET_NO; | 64 | ret = (0 == strcasecmp(mime, GNUNET_FS_DIRECTORY_MIME)) ? GNUNET_YES : GNUNET_NO; |
65 | GNUNET_free (mime); | 65 | GNUNET_free(mime); |
66 | return ret; | 66 | return ret; |
67 | } | 67 | } |
68 | 68 | ||
@@ -74,32 +74,30 @@ GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData * | |||
74 | * @param md metadata to add mimetype to | 74 | * @param md metadata to add mimetype to |
75 | */ | 75 | */ |
76 | void | 76 | void |
77 | GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md) | 77 | GNUNET_FS_meta_data_make_directory(struct GNUNET_CONTAINER_MetaData *md) |
78 | { | 78 | { |
79 | char *mime; | 79 | char *mime; |
80 | 80 | ||
81 | mime = | 81 | mime = |
82 | GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE); | 82 | GNUNET_CONTAINER_meta_data_get_by_type(md, EXTRACTOR_METATYPE_MIMETYPE); |
83 | if (mime != NULL) | 83 | if (mime != NULL) |
84 | { | 84 | { |
85 | GNUNET_break (0 == strcmp (mime, GNUNET_FS_DIRECTORY_MIME)); | 85 | GNUNET_break(0 == strcmp(mime, GNUNET_FS_DIRECTORY_MIME)); |
86 | GNUNET_free (mime); | 86 | GNUNET_free(mime); |
87 | return; | 87 | return; |
88 | } | 88 | } |
89 | GNUNET_CONTAINER_meta_data_insert (md, "<gnunet>", | 89 | GNUNET_CONTAINER_meta_data_insert(md, "<gnunet>", |
90 | EXTRACTOR_METATYPE_MIMETYPE, | 90 | EXTRACTOR_METATYPE_MIMETYPE, |
91 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 91 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
92 | GNUNET_FS_DIRECTORY_MIME, | 92 | GNUNET_FS_DIRECTORY_MIME, |
93 | strlen (GNUNET_FS_DIRECTORY_MIME) + 1); | 93 | strlen(GNUNET_FS_DIRECTORY_MIME) + 1); |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | /** | 97 | /** |
98 | * Closure for 'find_full_data'. | 98 | * Closure for 'find_full_data'. |
99 | */ | 99 | */ |
100 | struct GetFullDataClosure | 100 | struct GetFullDataClosure { |
101 | { | ||
102 | |||
103 | /** | 101 | /** |
104 | * Extracted binary meta data. | 102 | * Extracted binary meta data. |
105 | */ | 103 | */ |
@@ -130,22 +128,22 @@ struct GetFullDataClosure | |||
130 | * @return 0 to continue extracting, 1 to abort | 128 | * @return 0 to continue extracting, 1 to abort |
131 | */ | 129 | */ |
132 | static int | 130 | static int |
133 | find_full_data (void *cls, const char *plugin_name, | 131 | find_full_data(void *cls, const char *plugin_name, |
134 | enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, | 132 | enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, |
135 | const char *data_mime_type, const char *data, size_t data_len) | 133 | const char *data_mime_type, const char *data, size_t data_len) |
136 | { | 134 | { |
137 | struct GetFullDataClosure *gfdc = cls; | 135 | struct GetFullDataClosure *gfdc = cls; |
138 | 136 | ||
139 | if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) | 137 | if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) |
140 | { | ||
141 | gfdc->size = data_len; | ||
142 | if (data_len > 0) | ||
143 | { | 138 | { |
144 | gfdc->data = GNUNET_malloc (data_len); | 139 | gfdc->size = data_len; |
145 | GNUNET_memcpy (gfdc->data, data, data_len); | 140 | if (data_len > 0) |
141 | { | ||
142 | gfdc->data = GNUNET_malloc(data_len); | ||
143 | GNUNET_memcpy(gfdc->data, data, data_len); | ||
144 | } | ||
145 | return 1; | ||
146 | } | 146 | } |
147 | return 1; | ||
148 | } | ||
149 | return 0; | 147 | return 0; |
150 | } | 148 | } |
151 | 149 | ||
@@ -176,11 +174,11 @@ find_full_data (void *cls, const char *plugin_name, | |||
176 | * #GNUNET_SYSERR if @a data does not represent a directory | 174 | * #GNUNET_SYSERR if @a data does not represent a directory |
177 | */ | 175 | */ |
178 | int | 176 | int |
179 | GNUNET_FS_directory_list_contents (size_t size, | 177 | GNUNET_FS_directory_list_contents(size_t size, |
180 | const void *data, | 178 | const void *data, |
181 | uint64_t offset, | 179 | uint64_t offset, |
182 | GNUNET_FS_DirectoryEntryProcessor dep, | 180 | GNUNET_FS_DirectoryEntryProcessor dep, |
183 | void *dep_cls) | 181 | void *dep_cls) |
184 | { | 182 | { |
185 | struct GetFullDataClosure full_data; | 183 | struct GetFullDataClosure full_data; |
186 | const char *cdata = data; | 184 | const char *cdata = data; |
@@ -194,132 +192,131 @@ GNUNET_FS_directory_list_contents (size_t size, | |||
194 | char *filename; | 192 | char *filename; |
195 | 193 | ||
196 | if ((offset == 0) && | 194 | if ((offset == 0) && |
197 | ((size < 8 + sizeof (uint32_t)) || | 195 | ((size < 8 + sizeof(uint32_t)) || |
198 | (0 != memcmp (cdata, | 196 | (0 != memcmp(cdata, |
199 | GNUNET_FS_DIRECTORY_MAGIC, | 197 | GNUNET_FS_DIRECTORY_MAGIC, |
200 | 8)))) | 198 | 8)))) |
201 | return GNUNET_SYSERR; | 199 | return GNUNET_SYSERR; |
202 | pos = offset; | 200 | pos = offset; |
203 | if (offset == 0) | 201 | if (offset == 0) |
204 | { | ||
205 | GNUNET_memcpy (&mdSize, | ||
206 | &cdata[8], | ||
207 | sizeof (uint32_t)); | ||
208 | mdSize = ntohl (mdSize); | ||
209 | if (mdSize > size - 8 - sizeof (uint32_t)) | ||
210 | { | 202 | { |
211 | /* invalid size */ | 203 | GNUNET_memcpy(&mdSize, |
212 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 204 | &cdata[8], |
213 | _("MAGIC mismatch. This is not a GNUnet directory.\n")); | 205 | sizeof(uint32_t)); |
214 | return GNUNET_SYSERR; | 206 | mdSize = ntohl(mdSize); |
215 | } | 207 | if (mdSize > size - 8 - sizeof(uint32_t)) |
216 | md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[8 + sizeof (uint32_t)], | 208 | { |
217 | mdSize); | 209 | /* invalid size */ |
218 | if (md == NULL) | 210 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
219 | { | 211 | _("MAGIC mismatch. This is not a GNUnet directory.\n")); |
220 | GNUNET_break (0); | 212 | return GNUNET_SYSERR; |
221 | return GNUNET_SYSERR; /* malformed ! */ | 213 | } |
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; | ||
222 | } | 229 | } |
223 | dep (dep_cls, | ||
224 | NULL, | ||
225 | NULL, | ||
226 | md, | ||
227 | 0, | ||
228 | NULL); | ||
229 | GNUNET_CONTAINER_meta_data_destroy (md); | ||
230 | pos = 8 + sizeof (uint32_t) + mdSize; | ||
231 | } | ||
232 | while (pos < size) | 230 | while (pos < size) |
233 | { | ||
234 | /* find end of URI */ | ||
235 | if (cdata[pos] == '\0') | ||
236 | { | ||
237 | /* URI is never empty, must be end of block, | ||
238 | * skip to next alignment */ | ||
239 | align = ((pos / DBLOCK_SIZE) + 1) * DBLOCK_SIZE; | ||
240 | if (align == pos) | ||
241 | { | ||
242 | /* if we were already aligned, still skip a block! */ | ||
243 | align += DBLOCK_SIZE; | ||
244 | } | ||
245 | pos = align; | ||
246 | if (pos >= size) | ||
247 | { | ||
248 | /* malformed - or partial download... */ | ||
249 | break; | ||
250 | } | ||
251 | } | ||
252 | epos = pos; | ||
253 | while ((epos < size) && (cdata[epos] != '\0')) | ||
254 | epos++; | ||
255 | if (epos >= size) | ||
256 | return GNUNET_NO; /* malformed - or partial download */ | ||
257 | |||
258 | uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg); | ||
259 | pos = epos + 1; | ||
260 | if (NULL == uri) | ||
261 | { | ||
262 | GNUNET_free (emsg); | ||
263 | pos--; /* go back to '\0' to force going to next alignment */ | ||
264 | continue; | ||
265 | } | ||
266 | if (GNUNET_FS_uri_test_ksk (uri)) | ||
267 | { | 231 | { |
268 | GNUNET_FS_uri_destroy (uri); | 232 | /* find end of URI */ |
269 | GNUNET_break (0); | 233 | if (cdata[pos] == '\0') |
270 | return GNUNET_NO; /* illegal in directory! */ | 234 | { |
271 | } | 235 | /* URI is never empty, must be end of block, |
236 | * skip to next alignment */ | ||
237 | align = ((pos / DBLOCK_SIZE) + 1) * DBLOCK_SIZE; | ||
238 | if (align == pos) | ||
239 | { | ||
240 | /* if we were already aligned, still skip a block! */ | ||
241 | align += DBLOCK_SIZE; | ||
242 | } | ||
243 | pos = align; | ||
244 | if (pos >= size) | ||
245 | { | ||
246 | /* malformed - or partial download... */ | ||
247 | break; | ||
248 | } | ||
249 | } | ||
250 | epos = pos; | ||
251 | while ((epos < size) && (cdata[epos] != '\0')) | ||
252 | epos++; | ||
253 | if (epos >= size) | ||
254 | return GNUNET_NO; /* malformed - or partial download */ | ||
255 | |||
256 | uri = GNUNET_FS_uri_parse(&cdata[pos], &emsg); | ||
257 | pos = epos + 1; | ||
258 | if (NULL == uri) | ||
259 | { | ||
260 | GNUNET_free(emsg); | ||
261 | pos--; /* go back to '\0' to force going to next alignment */ | ||
262 | continue; | ||
263 | } | ||
264 | if (GNUNET_FS_uri_test_ksk(uri)) | ||
265 | { | ||
266 | GNUNET_FS_uri_destroy(uri); | ||
267 | GNUNET_break(0); | ||
268 | return GNUNET_NO; /* illegal in directory! */ | ||
269 | } | ||
272 | 270 | ||
273 | GNUNET_memcpy (&mdSize, | 271 | GNUNET_memcpy(&mdSize, |
274 | &cdata[pos], | 272 | &cdata[pos], |
275 | sizeof (uint32_t)); | 273 | sizeof(uint32_t)); |
276 | mdSize = ntohl (mdSize); | 274 | mdSize = ntohl(mdSize); |
277 | pos += sizeof (uint32_t); | 275 | pos += sizeof(uint32_t); |
278 | if (pos + mdSize > size) | 276 | if (pos + mdSize > size) |
279 | { | 277 | { |
280 | GNUNET_FS_uri_destroy (uri); | 278 | GNUNET_FS_uri_destroy(uri); |
281 | return GNUNET_NO; /* malformed - or partial download */ | 279 | return GNUNET_NO; /* malformed - or partial download */ |
282 | } | 280 | } |
283 | 281 | ||
284 | md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], | 282 | md = GNUNET_CONTAINER_meta_data_deserialize(&cdata[pos], |
285 | mdSize); | 283 | mdSize); |
286 | if (NULL == md) | 284 | if (NULL == md) |
287 | { | 285 | { |
288 | GNUNET_FS_uri_destroy (uri); | 286 | GNUNET_FS_uri_destroy(uri); |
289 | GNUNET_break (0); | 287 | GNUNET_break(0); |
290 | return GNUNET_NO; /* malformed ! */ | 288 | return GNUNET_NO; /* malformed ! */ |
291 | } | 289 | } |
292 | pos += mdSize; | 290 | pos += mdSize; |
293 | filename = | 291 | filename = |
294 | GNUNET_CONTAINER_meta_data_get_by_type (md, | 292 | GNUNET_CONTAINER_meta_data_get_by_type(md, |
295 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 293 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); |
296 | full_data.size = 0; | 294 | full_data.size = 0; |
297 | full_data.data = NULL; | 295 | full_data.data = NULL; |
298 | GNUNET_CONTAINER_meta_data_iterate (md, | 296 | GNUNET_CONTAINER_meta_data_iterate(md, |
299 | &find_full_data, | 297 | &find_full_data, |
300 | &full_data); | 298 | &full_data); |
301 | if (NULL != dep) | 299 | if (NULL != dep) |
302 | { | 300 | { |
303 | dep (dep_cls, | 301 | dep(dep_cls, |
304 | filename, | 302 | filename, |
305 | uri, | 303 | uri, |
306 | md, | 304 | md, |
307 | full_data.size, | 305 | full_data.size, |
308 | full_data.data); | 306 | 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); | ||
309 | } | 312 | } |
310 | GNUNET_free_non_null (full_data.data); | ||
311 | GNUNET_free_non_null (filename); | ||
312 | GNUNET_CONTAINER_meta_data_destroy (md); | ||
313 | GNUNET_FS_uri_destroy (uri); | ||
314 | } | ||
315 | return GNUNET_OK; | 313 | return GNUNET_OK; |
316 | } | 314 | } |
317 | 315 | ||
318 | /** | 316 | /** |
319 | * Entries in the directory (builder). | 317 | * Entries in the directory (builder). |
320 | */ | 318 | */ |
321 | struct BuilderEntry | 319 | struct BuilderEntry { |
322 | { | ||
323 | /** | 320 | /** |
324 | * This is a linked list. | 321 | * This is a linked list. |
325 | */ | 322 | */ |
@@ -334,8 +331,7 @@ struct BuilderEntry | |||
334 | /** | 331 | /** |
335 | * Internal state of a directory builder. | 332 | * Internal state of a directory builder. |
336 | */ | 333 | */ |
337 | struct GNUNET_FS_DirectoryBuilder | 334 | struct GNUNET_FS_DirectoryBuilder { |
338 | { | ||
339 | /** | 335 | /** |
340 | * Meta-data for the directory itself. | 336 | * Meta-data for the directory itself. |
341 | */ | 337 | */ |
@@ -359,17 +355,17 @@ struct GNUNET_FS_DirectoryBuilder | |||
359 | * @param mdir metadata for the directory | 355 | * @param mdir metadata for the directory |
360 | */ | 356 | */ |
361 | struct GNUNET_FS_DirectoryBuilder * | 357 | struct GNUNET_FS_DirectoryBuilder * |
362 | GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData | 358 | GNUNET_FS_directory_builder_create(const struct GNUNET_CONTAINER_MetaData |
363 | *mdir) | 359 | *mdir) |
364 | { | 360 | { |
365 | struct GNUNET_FS_DirectoryBuilder *ret; | 361 | struct GNUNET_FS_DirectoryBuilder *ret; |
366 | 362 | ||
367 | ret = GNUNET_new (struct GNUNET_FS_DirectoryBuilder); | 363 | ret = GNUNET_new(struct GNUNET_FS_DirectoryBuilder); |
368 | if (mdir != NULL) | 364 | if (mdir != NULL) |
369 | ret->meta = GNUNET_CONTAINER_meta_data_duplicate (mdir); | 365 | ret->meta = GNUNET_CONTAINER_meta_data_duplicate(mdir); |
370 | else | 366 | else |
371 | ret->meta = GNUNET_CONTAINER_meta_data_create (); | 367 | ret->meta = GNUNET_CONTAINER_meta_data_create(); |
372 | GNUNET_FS_meta_data_make_directory (ret->meta); | 368 | GNUNET_FS_meta_data_make_directory(ret->meta); |
373 | return ret; | 369 | return ret; |
374 | } | 370 | } |
375 | 371 | ||
@@ -385,10 +381,10 @@ GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData | |||
385 | * by the uri which must be of type LOC or CHK | 381 | * by the uri which must be of type LOC or CHK |
386 | */ | 382 | */ |
387 | void | 383 | void |
388 | GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, | 384 | GNUNET_FS_directory_builder_add(struct GNUNET_FS_DirectoryBuilder *bld, |
389 | const struct GNUNET_FS_Uri *uri, | 385 | const struct GNUNET_FS_Uri *uri, |
390 | const struct GNUNET_CONTAINER_MetaData *md, | 386 | const struct GNUNET_CONTAINER_MetaData *md, |
391 | const void *data) | 387 | const void *data) |
392 | { | 388 | { |
393 | struct GNUNET_FS_Uri *curi; | 389 | struct GNUNET_FS_Uri *curi; |
394 | struct BuilderEntry *e; | 390 | struct BuilderEntry *e; |
@@ -404,71 +400,71 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, | |||
404 | struct GNUNET_CONTAINER_MetaData *meta; | 400 | struct GNUNET_CONTAINER_MetaData *meta; |
405 | const struct GNUNET_CONTAINER_MetaData *meta_use; | 401 | const struct GNUNET_CONTAINER_MetaData *meta_use; |
406 | 402 | ||
407 | GNUNET_assert (!GNUNET_FS_uri_test_ksk (uri)); | 403 | GNUNET_assert(!GNUNET_FS_uri_test_ksk(uri)); |
408 | if (NULL != data) | 404 | if (NULL != data) |
409 | { | ||
410 | GNUNET_assert (!GNUNET_FS_uri_test_sks (uri)); | ||
411 | if (GNUNET_FS_uri_test_chk (uri)) | ||
412 | { | 405 | { |
413 | fsize = GNUNET_FS_uri_chk_get_file_size (uri); | 406 | GNUNET_assert(!GNUNET_FS_uri_test_sks(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 | } | ||
414 | } | 418 | } |
415 | else | 419 | else |
416 | { | 420 | { |
417 | curi = GNUNET_FS_uri_loc_get_uri (uri); | 421 | fsize = 0; /* not given */ |
418 | GNUNET_assert (NULL != curi); | ||
419 | fsize = GNUNET_FS_uri_chk_get_file_size (curi); | ||
420 | GNUNET_FS_uri_destroy (curi); | ||
421 | } | 422 | } |
422 | } | ||
423 | else | ||
424 | { | ||
425 | fsize = 0; /* not given */ | ||
426 | } | ||
427 | if (fsize > MAX_INLINE_SIZE) | 423 | if (fsize > MAX_INLINE_SIZE) |
428 | fsize = 0; /* too large */ | 424 | fsize = 0; /* too large */ |
429 | uris = GNUNET_FS_uri_to_string (uri); | 425 | uris = GNUNET_FS_uri_to_string(uri); |
430 | slen = strlen (uris) + 1; | 426 | slen = strlen(uris) + 1; |
431 | mds = GNUNET_CONTAINER_meta_data_get_serialized_size (md); | 427 | mds = GNUNET_CONTAINER_meta_data_get_serialized_size(md); |
432 | meta_use = md; | 428 | meta_use = md; |
433 | meta = NULL; | 429 | meta = NULL; |
434 | if (fsize > 0) | 430 | if (fsize > 0) |
435 | { | ||
436 | meta = GNUNET_CONTAINER_meta_data_duplicate (md); | ||
437 | GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", | ||
438 | EXTRACTOR_METATYPE_GNUNET_FULL_DATA, | ||
439 | EXTRACTOR_METAFORMAT_BINARY, NULL, data, | ||
440 | fsize); | ||
441 | mdxs = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); | ||
442 | if ((slen + sizeof (uint32_t) + mdxs - 1) / DBLOCK_SIZE == | ||
443 | (slen + sizeof (uint32_t) + mds - 1) / DBLOCK_SIZE) | ||
444 | { | 431 | { |
445 | /* adding full data would not cause us to cross | 432 | meta = GNUNET_CONTAINER_meta_data_duplicate(md); |
446 | * additional blocks, so add it! */ | 433 | GNUNET_CONTAINER_meta_data_insert(meta, "<gnunet>", |
447 | meta_use = meta; | 434 | EXTRACTOR_METATYPE_GNUNET_FULL_DATA, |
448 | mds = mdxs; | 435 | EXTRACTOR_METAFORMAT_BINARY, NULL, data, |
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 | } | ||
449 | } | 446 | } |
450 | } | ||
451 | 447 | ||
452 | if (mds > GNUNET_MAX_MALLOC_CHECKED / 2) | 448 | if (mds > GNUNET_MAX_MALLOC_CHECKED / 2) |
453 | mds = GNUNET_MAX_MALLOC_CHECKED / 2; | 449 | mds = GNUNET_MAX_MALLOC_CHECKED / 2; |
454 | e = GNUNET_malloc (sizeof (struct BuilderEntry) + slen + mds + | 450 | e = GNUNET_malloc(sizeof(struct BuilderEntry) + slen + mds + |
455 | sizeof (uint32_t)); | 451 | sizeof(uint32_t)); |
456 | ser = (char *) &e[1]; | 452 | ser = (char *)&e[1]; |
457 | GNUNET_memcpy (ser, uris, slen); | 453 | GNUNET_memcpy(ser, uris, slen); |
458 | GNUNET_free (uris); | 454 | GNUNET_free(uris); |
459 | sptr = &ser[slen + sizeof (uint32_t)]; | 455 | sptr = &ser[slen + sizeof(uint32_t)]; |
460 | ret = | 456 | ret = |
461 | GNUNET_CONTAINER_meta_data_serialize (meta_use, &sptr, mds, | 457 | GNUNET_CONTAINER_meta_data_serialize(meta_use, &sptr, mds, |
462 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | 458 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); |
463 | if (NULL != meta) | 459 | if (NULL != meta) |
464 | GNUNET_CONTAINER_meta_data_destroy (meta); | 460 | GNUNET_CONTAINER_meta_data_destroy(meta); |
465 | if (ret == -1) | 461 | if (ret == -1) |
466 | mds = 0; | 462 | mds = 0; |
467 | else | 463 | else |
468 | mds = ret; | 464 | mds = ret; |
469 | big = htonl (mds); | 465 | big = htonl(mds); |
470 | GNUNET_memcpy (&ser[slen], &big, sizeof (uint32_t)); | 466 | GNUNET_memcpy(&ser[slen], &big, sizeof(uint32_t)); |
471 | e->len = slen + sizeof (uint32_t) + mds; | 467 | e->len = slen + sizeof(uint32_t) + mds; |
472 | e->next = bld->head; | 468 | e->next = bld->head; |
473 | bld->head = e; | 469 | bld->head = e; |
474 | bld->count++; | 470 | bld->count++; |
@@ -481,7 +477,7 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, | |||
481 | * after alignment to the DBLOCK_SIZE. | 477 | * after alignment to the DBLOCK_SIZE. |
482 | */ | 478 | */ |
483 | static size_t | 479 | static size_t |
484 | do_align (size_t start_position, size_t end_position) | 480 | do_align(size_t start_position, size_t end_position) |
485 | { | 481 | { |
486 | size_t align; | 482 | size_t align; |
487 | 483 | ||
@@ -502,8 +498,8 @@ do_align (size_t start_position, size_t end_position) | |||
502 | * @param perm the permutation of the blocks (updated) | 498 | * @param perm the permutation of the blocks (updated) |
503 | */ | 499 | */ |
504 | static void | 500 | static void |
505 | block_align (size_t start, unsigned int count, const size_t * sizes, | 501 | block_align(size_t start, unsigned int count, const size_t * sizes, |
506 | unsigned int *perm) | 502 | unsigned int *perm) |
507 | { | 503 | { |
508 | unsigned int i; | 504 | unsigned int i; |
509 | unsigned int j; | 505 | unsigned int j; |
@@ -517,46 +513,46 @@ block_align (size_t start, unsigned int count, const size_t * sizes, | |||
517 | 513 | ||
518 | cpos = start; | 514 | cpos = start; |
519 | for (i = 0; i < count; i++) | 515 | for (i = 0; i < count; i++) |
520 | { | ||
521 | start = cpos; | ||
522 | badness = 0x7FFFFFFF; | ||
523 | best = -1; | ||
524 | for (j = i; j < count; j++) | ||
525 | { | 516 | { |
526 | cval = perm[j]; | 517 | start = cpos; |
527 | cend = cpos + sizes[cval]; | 518 | badness = 0x7FFFFFFF; |
528 | if (cpos % DBLOCK_SIZE == 0) | 519 | best = -1; |
529 | { | 520 | for (j = i; j < count; j++) |
530 | /* prefer placing the largest blocks first */ | ||
531 | cbad = -(cend % DBLOCK_SIZE); | ||
532 | } | ||
533 | else | ||
534 | { | ||
535 | if (cpos / DBLOCK_SIZE == cend / DBLOCK_SIZE) | ||
536 | { | ||
537 | /* Data fits into the same block! Prefer small left-overs! */ | ||
538 | cbad = DBLOCK_SIZE - cend % DBLOCK_SIZE; | ||
539 | } | ||
540 | else | ||
541 | { | 521 | { |
542 | /* Would have to waste space to re-align, add big factor, this | 522 | cval = perm[j]; |
543 | * case is a real loss (proportional to space wasted)! */ | 523 | cend = cpos + sizes[cval]; |
544 | cbad = DBLOCK_SIZE * (DBLOCK_SIZE - cpos % DBLOCK_SIZE); | 524 | if (cpos % DBLOCK_SIZE == 0) |
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 | } | ||
545 | } | 548 | } |
546 | } | 549 | GNUNET_assert(best != -1); |
547 | if (cbad < badness) | 550 | tmp = perm[i]; |
548 | { | 551 | perm[i] = perm[best]; |
549 | best = j; | 552 | perm[best] = tmp; |
550 | badness = cbad; | 553 | cpos += sizes[perm[i]]; |
551 | } | 554 | cpos = do_align(start, cpos); |
552 | } | 555 | } |
553 | GNUNET_assert (best != -1); | ||
554 | tmp = perm[i]; | ||
555 | perm[i] = perm[best]; | ||
556 | perm[best] = tmp; | ||
557 | cpos += sizes[perm[i]]; | ||
558 | cpos = do_align (start, cpos); | ||
559 | } | ||
560 | } | 556 | } |
561 | 557 | ||
562 | 558 | ||
@@ -571,9 +567,9 @@ block_align (size_t start, unsigned int count, const size_t * sizes, | |||
571 | * @return #GNUNET_OK on success | 567 | * @return #GNUNET_OK on success |
572 | */ | 568 | */ |
573 | int | 569 | int |
574 | GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld, | 570 | GNUNET_FS_directory_builder_finish(struct GNUNET_FS_DirectoryBuilder *bld, |
575 | size_t * rsize, | 571 | size_t * rsize, |
576 | void **rdata) | 572 | void **rdata) |
577 | { | 573 | { |
578 | char *data; | 574 | char *data; |
579 | char *sptr; | 575 | char *sptr; |
@@ -589,82 +585,82 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld, | |||
589 | ssize_t ret; | 585 | ssize_t ret; |
590 | uint32_t big; | 586 | uint32_t big; |
591 | 587 | ||
592 | size = strlen (GNUNET_DIRECTORY_MAGIC) + sizeof (uint32_t); | 588 | size = strlen(GNUNET_DIRECTORY_MAGIC) + sizeof(uint32_t); |
593 | size += GNUNET_CONTAINER_meta_data_get_serialized_size (bld->meta); | 589 | size += GNUNET_CONTAINER_meta_data_get_serialized_size(bld->meta); |
594 | sizes = NULL; | 590 | sizes = NULL; |
595 | perm = NULL; | 591 | perm = NULL; |
596 | bes = NULL; | 592 | bes = NULL; |
597 | if (0 < bld->count) | 593 | if (0 < bld->count) |
598 | { | ||
599 | sizes = GNUNET_new_array (bld->count, | ||
600 | size_t); | ||
601 | perm = GNUNET_new_array (bld->count, | ||
602 | unsigned int); | ||
603 | bes = GNUNET_new_array (bld->count, | ||
604 | struct BuilderEntry *); | ||
605 | pos = bld->head; | ||
606 | for (i = 0; i < bld->count; i++) | ||
607 | { | ||
608 | perm[i] = i; | ||
609 | bes[i] = pos; | ||
610 | sizes[i] = pos->len; | ||
611 | pos = pos->next; | ||
612 | } | ||
613 | block_align (size, bld->count, sizes, perm); | ||
614 | /* compute final size with alignment */ | ||
615 | for (i = 0; i < bld->count; i++) | ||
616 | { | 594 | { |
617 | psize = size; | 595 | sizes = GNUNET_new_array(bld->count, |
618 | size += sizes[perm[i]]; | 596 | size_t); |
619 | size = do_align (psize, size); | 597 | perm = GNUNET_new_array(bld->count, |
598 | unsigned int); | ||
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 | } | ||
620 | } | 617 | } |
621 | } | ||
622 | *rsize = size; | 618 | *rsize = size; |
623 | data = GNUNET_malloc_large (size); | 619 | data = GNUNET_malloc_large(size); |
624 | if (data == NULL) | 620 | if (data == NULL) |
625 | { | 621 | { |
626 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 622 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, |
627 | "malloc"); | 623 | "malloc"); |
628 | *rsize = 0; | 624 | *rsize = 0; |
629 | *rdata = NULL; | 625 | *rdata = NULL; |
630 | GNUNET_free_non_null (sizes); | 626 | GNUNET_free_non_null(sizes); |
631 | GNUNET_free_non_null (perm); | 627 | GNUNET_free_non_null(perm); |
632 | GNUNET_free_non_null (bes); | 628 | GNUNET_free_non_null(bes); |
633 | return GNUNET_SYSERR; | 629 | return GNUNET_SYSERR; |
634 | } | 630 | } |
635 | *rdata = data; | 631 | *rdata = data; |
636 | GNUNET_memcpy (data, | 632 | GNUNET_memcpy(data, |
637 | GNUNET_DIRECTORY_MAGIC, | 633 | GNUNET_DIRECTORY_MAGIC, |
638 | strlen (GNUNET_DIRECTORY_MAGIC)); | 634 | strlen(GNUNET_DIRECTORY_MAGIC)); |
639 | off = strlen (GNUNET_DIRECTORY_MAGIC); | 635 | off = strlen(GNUNET_DIRECTORY_MAGIC); |
640 | 636 | ||
641 | sptr = &data[off + sizeof (uint32_t)]; | 637 | sptr = &data[off + sizeof(uint32_t)]; |
642 | ret = | 638 | ret = |
643 | GNUNET_CONTAINER_meta_data_serialize (bld->meta, | 639 | GNUNET_CONTAINER_meta_data_serialize(bld->meta, |
644 | &sptr, | 640 | &sptr, |
645 | size - off - sizeof (uint32_t), | 641 | size - off - sizeof(uint32_t), |
646 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); | 642 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); |
647 | GNUNET_assert (ret != -1); | 643 | GNUNET_assert(ret != -1); |
648 | big = htonl (ret); | 644 | big = htonl(ret); |
649 | GNUNET_memcpy (&data[off], | 645 | GNUNET_memcpy(&data[off], |
650 | &big, | 646 | &big, |
651 | sizeof (uint32_t)); | 647 | sizeof(uint32_t)); |
652 | off += sizeof (uint32_t) + ret; | 648 | off += sizeof(uint32_t) + ret; |
653 | for (j = 0; j < bld->count; j++) | 649 | for (j = 0; j < bld->count; j++) |
654 | { | 650 | { |
655 | i = perm[j]; | 651 | i = perm[j]; |
656 | psize = off; | 652 | psize = off; |
657 | off += sizes[i]; | 653 | off += sizes[i]; |
658 | off = do_align (psize, off); | 654 | off = do_align(psize, off); |
659 | GNUNET_memcpy (&data[off - sizes[i]], &(bes[i])[1], sizes[i]); | 655 | GNUNET_memcpy(&data[off - sizes[i]], &(bes[i])[1], sizes[i]); |
660 | GNUNET_free (bes[i]); | 656 | GNUNET_free(bes[i]); |
661 | } | 657 | } |
662 | GNUNET_free_non_null (sizes); | 658 | GNUNET_free_non_null(sizes); |
663 | GNUNET_free_non_null (perm); | 659 | GNUNET_free_non_null(perm); |
664 | GNUNET_free_non_null (bes); | 660 | GNUNET_free_non_null(bes); |
665 | GNUNET_assert (off == size); | 661 | GNUNET_assert(off == size); |
666 | GNUNET_CONTAINER_meta_data_destroy (bld->meta); | 662 | GNUNET_CONTAINER_meta_data_destroy(bld->meta); |
667 | GNUNET_free (bld); | 663 | GNUNET_free(bld); |
668 | return GNUNET_OK; | 664 | return GNUNET_OK; |
669 | } | 665 | } |
670 | 666 | ||
diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c index dd207e2c9..9202de5ab 100644 --- a/src/fs/fs_dirmetascan.c +++ b/src/fs/fs_dirmetascan.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_dirmetascan.c | 22 | * @file fs/fs_dirmetascan.c |
@@ -35,9 +35,7 @@ | |||
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 | { | ||
40 | |||
41 | /** | 39 | /** |
42 | * Helper process. | 40 | * Helper process. |
43 | */ | 41 | */ |
@@ -96,20 +94,20 @@ struct GNUNET_FS_DirScanner | |||
96 | * @param ds directory scanner structure | 94 | * @param ds directory scanner structure |
97 | */ | 95 | */ |
98 | void | 96 | void |
99 | GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds) | 97 | GNUNET_FS_directory_scan_abort(struct GNUNET_FS_DirScanner *ds) |
100 | { | 98 | { |
101 | /* terminate helper */ | 99 | /* terminate helper */ |
102 | if (NULL != ds->helper) | 100 | if (NULL != ds->helper) |
103 | GNUNET_HELPER_stop (ds->helper, GNUNET_NO); | 101 | GNUNET_HELPER_stop(ds->helper, GNUNET_NO); |
104 | 102 | ||
105 | /* free resources */ | 103 | /* free resources */ |
106 | if (NULL != ds->toplevel) | 104 | if (NULL != ds->toplevel) |
107 | GNUNET_FS_share_tree_free (ds->toplevel); | 105 | GNUNET_FS_share_tree_free(ds->toplevel); |
108 | if (NULL != ds->stop_task) | 106 | if (NULL != ds->stop_task) |
109 | GNUNET_SCHEDULER_cancel (ds->stop_task); | 107 | GNUNET_SCHEDULER_cancel(ds->stop_task); |
110 | GNUNET_free_non_null (ds->ex_arg); | 108 | GNUNET_free_non_null(ds->ex_arg); |
111 | GNUNET_free (ds->filename_expanded); | 109 | GNUNET_free(ds->filename_expanded); |
112 | GNUNET_free (ds); | 110 | GNUNET_free(ds); |
113 | } | 111 | } |
114 | 112 | ||
115 | 113 | ||
@@ -122,16 +120,16 @@ GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds) | |||
122 | * @return the results of the scan (a directory tree) | 120 | * @return the results of the scan (a directory tree) |
123 | */ | 121 | */ |
124 | struct GNUNET_FS_ShareTreeItem * | 122 | struct GNUNET_FS_ShareTreeItem * |
125 | GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds) | 123 | GNUNET_FS_directory_scan_get_result(struct GNUNET_FS_DirScanner *ds) |
126 | { | 124 | { |
127 | struct GNUNET_FS_ShareTreeItem *result; | 125 | struct GNUNET_FS_ShareTreeItem *result; |
128 | 126 | ||
129 | /* check that we're actually done */ | 127 | /* check that we're actually done */ |
130 | GNUNET_assert (NULL == ds->helper); | 128 | GNUNET_assert(NULL == ds->helper); |
131 | /* preserve result */ | 129 | /* preserve result */ |
132 | result = ds->toplevel; | 130 | result = ds->toplevel; |
133 | ds->toplevel = NULL; | 131 | ds->toplevel = NULL; |
134 | GNUNET_FS_directory_scan_abort (ds); | 132 | GNUNET_FS_directory_scan_abort(ds); |
135 | return result; | 133 | return result; |
136 | } | 134 | } |
137 | 135 | ||
@@ -144,35 +142,35 @@ GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds) | |||
144 | * @return next file, NULL for none | 142 | * @return next file, NULL for none |
145 | */ | 143 | */ |
146 | static struct GNUNET_FS_ShareTreeItem * | 144 | static struct GNUNET_FS_ShareTreeItem * |
147 | advance (struct GNUNET_FS_ShareTreeItem *pos) | 145 | advance(struct GNUNET_FS_ShareTreeItem *pos) |
148 | { | 146 | { |
149 | int moved; | 147 | int moved; |
150 | 148 | ||
151 | GNUNET_assert (NULL != pos); | 149 | GNUNET_assert(NULL != pos); |
152 | moved = 0; /* must not terminate, even on file, otherwise "normal" */ | 150 | moved = 0; /* must not terminate, even on file, otherwise "normal" */ |
153 | while ((pos->is_directory == GNUNET_YES) || (0 == moved)) | 151 | while ((pos->is_directory == GNUNET_YES) || (0 == moved)) |
154 | { | ||
155 | if ((moved != -1) && (NULL != pos->children_head)) | ||
156 | { | ||
157 | pos = pos->children_head; | ||
158 | moved = 1; /* can terminate if file */ | ||
159 | continue; | ||
160 | } | ||
161 | if (NULL != pos->next) | ||
162 | { | ||
163 | pos = pos->next; | ||
164 | moved = 1; /* can terminate if file */ | ||
165 | continue; | ||
166 | } | ||
167 | if (NULL != pos->parent) | ||
168 | { | 152 | { |
169 | pos = pos->parent; | 153 | if ((moved != -1) && (NULL != pos->children_head)) |
170 | moved = -1; /* force move to 'next' or 'parent' */ | 154 | { |
171 | continue; | 155 | pos = pos->children_head; |
156 | moved = 1; /* can terminate if file */ | ||
157 | continue; | ||
158 | } | ||
159 | if (NULL != pos->next) | ||
160 | { | ||
161 | pos = pos->next; | ||
162 | moved = 1; /* can terminate if file */ | ||
163 | continue; | ||
164 | } | ||
165 | if (NULL != pos->parent) | ||
166 | { | ||
167 | pos = pos->parent; | ||
168 | moved = -1; /* force move to 'next' or 'parent' */ | ||
169 | continue; | ||
170 | } | ||
171 | /* no more options, end of traversal */ | ||
172 | return NULL; | ||
172 | } | 173 | } |
173 | /* no more options, end of traversal */ | ||
174 | return NULL; | ||
175 | } | ||
176 | return pos; | 174 | return pos; |
177 | } | 175 | } |
178 | 176 | ||
@@ -186,30 +184,30 @@ advance (struct GNUNET_FS_ShareTreeItem *pos) | |||
186 | * @return new entry that was just created | 184 | * @return new entry that was just created |
187 | */ | 185 | */ |
188 | static struct GNUNET_FS_ShareTreeItem * | 186 | static struct GNUNET_FS_ShareTreeItem * |
189 | expand_tree (struct GNUNET_FS_ShareTreeItem *parent, | 187 | expand_tree(struct GNUNET_FS_ShareTreeItem *parent, |
190 | const char *filename, | 188 | const char *filename, |
191 | int is_directory) | 189 | int is_directory) |
192 | { | 190 | { |
193 | struct GNUNET_FS_ShareTreeItem *chld; | 191 | struct GNUNET_FS_ShareTreeItem *chld; |
194 | size_t slen; | 192 | size_t slen; |
195 | 193 | ||
196 | chld = GNUNET_new (struct GNUNET_FS_ShareTreeItem); | 194 | chld = GNUNET_new(struct GNUNET_FS_ShareTreeItem); |
197 | chld->parent = parent; | 195 | chld->parent = parent; |
198 | chld->filename = GNUNET_strdup (filename); | 196 | chld->filename = GNUNET_strdup(filename); |
199 | GNUNET_asprintf (&chld->short_filename, | 197 | GNUNET_asprintf(&chld->short_filename, |
200 | "%s%s", | 198 | "%s%s", |
201 | GNUNET_STRINGS_get_short_name (filename), | 199 | GNUNET_STRINGS_get_short_name(filename), |
202 | is_directory == GNUNET_YES ? "/" : ""); | 200 | is_directory == GNUNET_YES ? "/" : ""); |
203 | /* make sure we do not end with '//' */ | 201 | /* make sure we do not end with '//' */ |
204 | slen = strlen (chld->short_filename); | 202 | slen = strlen(chld->short_filename); |
205 | if ((slen >= 2) && (chld->short_filename[slen - 1] == '/') && | 203 | if ((slen >= 2) && (chld->short_filename[slen - 1] == '/') && |
206 | (chld->short_filename[slen - 2] == '/')) | 204 | (chld->short_filename[slen - 2] == '/')) |
207 | chld->short_filename[slen - 1] = '\0'; | 205 | chld->short_filename[slen - 1] = '\0'; |
208 | chld->is_directory = is_directory; | 206 | chld->is_directory = is_directory; |
209 | if (NULL != parent) | 207 | if (NULL != parent) |
210 | GNUNET_CONTAINER_DLL_insert (parent->children_head, | 208 | GNUNET_CONTAINER_DLL_insert(parent->children_head, |
211 | parent->children_tail, | 209 | parent->children_tail, |
212 | chld); | 210 | chld); |
213 | return chld; | 211 | return chld; |
214 | } | 212 | } |
215 | 213 | ||
@@ -220,20 +218,20 @@ expand_tree (struct GNUNET_FS_ShareTreeItem *parent, | |||
220 | * @param cls the 'struct GNUNET_FS_DirScanner' | 218 | * @param cls the 'struct GNUNET_FS_DirScanner' |
221 | */ | 219 | */ |
222 | static void | 220 | static void |
223 | finish_scan (void *cls) | 221 | finish_scan(void *cls) |
224 | { | 222 | { |
225 | struct GNUNET_FS_DirScanner *ds = cls; | 223 | struct GNUNET_FS_DirScanner *ds = cls; |
226 | 224 | ||
227 | ds->stop_task = NULL; | 225 | ds->stop_task = NULL; |
228 | if (NULL != ds->helper) | 226 | if (NULL != ds->helper) |
229 | { | 227 | { |
230 | GNUNET_HELPER_stop (ds->helper, GNUNET_NO); | 228 | GNUNET_HELPER_stop(ds->helper, GNUNET_NO); |
231 | ds->helper = NULL; | 229 | ds->helper = NULL; |
232 | } | 230 | } |
233 | ds->progress_callback (ds->progress_callback_cls, | 231 | ds->progress_callback(ds->progress_callback_cls, |
234 | NULL, | 232 | NULL, |
235 | GNUNET_SYSERR, | 233 | GNUNET_SYSERR, |
236 | GNUNET_FS_DIRSCANNER_FINISHED); | 234 | GNUNET_FS_DIRSCANNER_FINISHED); |
237 | } | 235 | } |
238 | 236 | ||
239 | 237 | ||
@@ -248,168 +246,175 @@ finish_scan (void *cls) | |||
248 | * #GNUNET_SYSERR to stop further processing with error | 246 | * #GNUNET_SYSERR to stop further processing with error |
249 | */ | 247 | */ |
250 | static int | 248 | static int |
251 | process_helper_msgs (void *cls, const struct GNUNET_MessageHeader *msg) | 249 | process_helper_msgs(void *cls, const struct GNUNET_MessageHeader *msg) |
252 | { | 250 | { |
253 | struct GNUNET_FS_DirScanner *ds = cls; | 251 | struct GNUNET_FS_DirScanner *ds = cls; |
254 | const char *filename; | 252 | const char *filename; |
255 | size_t left; | 253 | size_t left; |
256 | 254 | ||
257 | #if 0 | 255 | #if 0 |
258 | fprintf (stderr, | 256 | fprintf(stderr, |
259 | "DMS parses %u-byte message of type %u\n", | 257 | "DMS parses %u-byte message of type %u\n", |
260 | (unsigned int) ntohs (msg->size), | 258 | (unsigned int)ntohs(msg->size), |
261 | (unsigned int) ntohs (msg->type)); | 259 | (unsigned int)ntohs(msg->type)); |
262 | #endif | 260 | #endif |
263 | left = ntohs (msg->size) - sizeof (struct GNUNET_MessageHeader); | 261 | left = ntohs(msg->size) - sizeof(struct GNUNET_MessageHeader); |
264 | filename = (const char *) &msg[1]; | 262 | filename = (const char *)&msg[1]; |
265 | switch (ntohs (msg->type)) | 263 | switch (ntohs(msg->type)) |
266 | { | ||
267 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: | ||
268 | if (filename[left - 1] != '\0') | ||
269 | { | ||
270 | GNUNET_break (0); | ||
271 | break; | ||
272 | } | ||
273 | ds->progress_callback (ds->progress_callback_cls, | ||
274 | filename, | ||
275 | GNUNET_NO, | ||
276 | GNUNET_FS_DIRSCANNER_FILE_START); | ||
277 | if (NULL == ds->toplevel) | ||
278 | { | ||
279 | ds->toplevel = expand_tree (ds->pos, filename, GNUNET_NO); | ||
280 | } | ||
281 | else | ||
282 | { | 264 | { |
283 | GNUNET_assert (NULL != ds->pos); | 265 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: |
284 | (void) expand_tree (ds->pos, filename, GNUNET_NO); | 266 | if (filename[left - 1] != '\0') |
285 | } | 267 | { |
286 | return GNUNET_OK; | 268 | GNUNET_break(0); |
287 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: | 269 | break; |
288 | if (filename[left - 1] != '\0') | 270 | } |
289 | { | 271 | ds->progress_callback(ds->progress_callback_cls, |
290 | GNUNET_break (0); | 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: | ||
291 | break; | 312 | break; |
292 | } | 313 | |
293 | if (0 == strcmp ("..", filename)) | 314 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: |
294 | { | 315 | if ('\0' != filename[left - 1]) |
295 | if (NULL == ds->pos) | ||
296 | { | ||
297 | GNUNET_break (0); | ||
298 | break; | 316 | break; |
299 | } | 317 | ds->progress_callback(ds->progress_callback_cls, |
300 | ds->pos = ds->pos->parent; | 318 | filename, |
319 | GNUNET_SYSERR, | ||
320 | GNUNET_FS_DIRSCANNER_FILE_IGNORED); | ||
301 | return GNUNET_OK; | 321 | return GNUNET_OK; |
302 | } | 322 | |
303 | ds->progress_callback (ds->progress_callback_cls, | 323 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: |
304 | filename, | 324 | if (0 != left) |
305 | GNUNET_YES, | 325 | { |
306 | GNUNET_FS_DIRSCANNER_FILE_START); | 326 | GNUNET_break(0); |
307 | ds->pos = expand_tree (ds->pos, filename, GNUNET_YES); | 327 | break; |
308 | if (NULL == ds->toplevel) | 328 | } |
309 | ds->toplevel = ds->pos; | 329 | if (NULL == ds->toplevel) |
310 | return GNUNET_OK; | ||
311 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR: | ||
312 | break; | ||
313 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: | ||
314 | if ('\0' != filename[left - 1]) | ||
315 | break; | ||
316 | ds->progress_callback (ds->progress_callback_cls, | ||
317 | filename, | ||
318 | GNUNET_SYSERR, | ||
319 | GNUNET_FS_DIRSCANNER_FILE_IGNORED); | ||
320 | return GNUNET_OK; | ||
321 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: | ||
322 | if (0 != left) | ||
323 | { | ||
324 | GNUNET_break (0); | ||
325 | break; | ||
326 | } | ||
327 | if (NULL == ds->toplevel) | ||
328 | break; | ||
329 | ds->progress_callback (ds->progress_callback_cls, | ||
330 | NULL, | ||
331 | GNUNET_SYSERR, | ||
332 | GNUNET_FS_DIRSCANNER_ALL_COUNTED); | ||
333 | ds->pos = ds->toplevel; | ||
334 | if (GNUNET_YES == ds->pos->is_directory) | ||
335 | ds->pos = advance (ds->pos); | ||
336 | return GNUNET_OK; | ||
337 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: { | ||
338 | size_t nlen; | ||
339 | const char *end; | ||
340 | |||
341 | if (NULL == ds->pos) | ||
342 | { | ||
343 | GNUNET_break (0); | ||
344 | break; | ||
345 | } | ||
346 | end = memchr (filename, 0, left); | ||
347 | if (NULL == end) | ||
348 | { | ||
349 | GNUNET_break (0); | ||
350 | break; | ||
351 | } | ||
352 | end++; | ||
353 | nlen = end - filename; | ||
354 | left -= nlen; | ||
355 | if (0 != strcmp (filename, ds->pos->filename)) | ||
356 | { | ||
357 | GNUNET_break (0); | ||
358 | break; | ||
359 | } | ||
360 | ds->progress_callback (ds->progress_callback_cls, | ||
361 | filename, | ||
362 | GNUNET_YES, | ||
363 | GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); | ||
364 | if (0 < left) | ||
365 | { | ||
366 | ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, left); | ||
367 | if (NULL == ds->pos->meta) | ||
368 | { | ||
369 | GNUNET_break (0); | ||
370 | break; | 330 | break; |
371 | } | 331 | ds->progress_callback(ds->progress_callback_cls, |
372 | /* having full filenames is too dangerous; always make sure we clean them up */ | 332 | NULL, |
373 | GNUNET_CONTAINER_meta_data_delete (ds->pos->meta, | 333 | GNUNET_SYSERR, |
374 | EXTRACTOR_METATYPE_FILENAME, | 334 | GNUNET_FS_DIRSCANNER_ALL_COUNTED); |
375 | NULL, | 335 | ds->pos = ds->toplevel; |
376 | 0); | 336 | if (GNUNET_YES == ds->pos->is_directory) |
377 | /* instead, put in our 'safer' original filename */ | 337 | ds->pos = advance(ds->pos); |
378 | GNUNET_CONTAINER_meta_data_insert (ds->pos->meta, | 338 | return GNUNET_OK; |
379 | "<libgnunetfs>", | 339 | |
380 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | 340 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: { |
381 | EXTRACTOR_METAFORMAT_UTF8, | 341 | size_t nlen; |
382 | "text/plain", | 342 | const char *end; |
383 | ds->pos->short_filename, | 343 | |
384 | strlen (ds->pos->short_filename) + 1); | 344 | if (NULL == ds->pos) |
385 | } | 345 | { |
386 | ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (ds->pos->meta); | 346 | GNUNET_break(0); |
387 | ds->pos = advance (ds->pos); | 347 | break; |
388 | return GNUNET_OK; | 348 | } |
389 | } | 349 | end = memchr(filename, 0, left); |
390 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: | 350 | if (NULL == end) |
391 | if (NULL != ds->pos) | 351 | { |
392 | { | 352 | GNUNET_break(0); |
393 | GNUNET_break (0); | 353 | break; |
394 | break; | 354 | } |
355 | end++; | ||
356 | nlen = end - filename; | ||
357 | left -= nlen; | ||
358 | if (0 != strcmp(filename, ds->pos->filename)) | ||
359 | { | ||
360 | GNUNET_break(0); | ||
361 | break; | ||
362 | } | ||
363 | ds->progress_callback(ds->progress_callback_cls, | ||
364 | filename, | ||
365 | GNUNET_YES, | ||
366 | GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); | ||
367 | if (0 < left) | ||
368 | { | ||
369 | ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize(end, left); | ||
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; | ||
395 | } | 392 | } |
396 | if (0 != left) | 393 | |
397 | { | 394 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: |
398 | GNUNET_break (0); | 395 | if (NULL != ds->pos) |
396 | { | ||
397 | GNUNET_break(0); | ||
398 | break; | ||
399 | } | ||
400 | if (0 != left) | ||
401 | { | ||
402 | GNUNET_break(0); | ||
403 | break; | ||
404 | } | ||
405 | if (NULL == ds->toplevel) | ||
406 | break; | ||
407 | ds->stop_task = GNUNET_SCHEDULER_add_now(&finish_scan, ds); | ||
408 | return GNUNET_OK; | ||
409 | |||
410 | default: | ||
411 | GNUNET_break(0); | ||
399 | break; | 412 | break; |
400 | } | 413 | } |
401 | if (NULL == ds->toplevel) | 414 | ds->progress_callback(ds->progress_callback_cls, |
402 | break; | 415 | NULL, |
403 | ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan, ds); | 416 | GNUNET_SYSERR, |
404 | return GNUNET_OK; | 417 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); |
405 | default: | ||
406 | GNUNET_break (0); | ||
407 | break; | ||
408 | } | ||
409 | ds->progress_callback (ds->progress_callback_cls, | ||
410 | NULL, | ||
411 | GNUNET_SYSERR, | ||
412 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); | ||
413 | return GNUNET_OK; | 418 | return GNUNET_OK; |
414 | } | 419 | } |
415 | 420 | ||
@@ -420,17 +425,17 @@ process_helper_msgs (void *cls, const struct GNUNET_MessageHeader *msg) | |||
420 | * @param cls the 'struct GNUNET_FS_DirScanner' callback. | 425 | * @param cls the 'struct GNUNET_FS_DirScanner' callback. |
421 | */ | 426 | */ |
422 | static void | 427 | static void |
423 | helper_died_cb (void *cls) | 428 | helper_died_cb(void *cls) |
424 | { | 429 | { |
425 | struct GNUNET_FS_DirScanner *ds = cls; | 430 | struct GNUNET_FS_DirScanner *ds = cls; |
426 | 431 | ||
427 | ds->helper = NULL; | 432 | ds->helper = NULL; |
428 | if (NULL != ds->stop_task) | 433 | if (NULL != ds->stop_task) |
429 | return; /* normal death, was finished */ | 434 | return; /* normal death, was finished */ |
430 | ds->progress_callback (ds->progress_callback_cls, | 435 | ds->progress_callback(ds->progress_callback_cls, |
431 | NULL, | 436 | NULL, |
432 | GNUNET_SYSERR, | 437 | GNUNET_SYSERR, |
433 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); | 438 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); |
434 | } | 439 | } |
435 | 440 | ||
436 | 441 | ||
@@ -446,48 +451,48 @@ helper_died_cb (void *cls) | |||
446 | * @return directory scanner object to be used for controlling the scanner | 451 | * @return directory scanner object to be used for controlling the scanner |
447 | */ | 452 | */ |
448 | struct GNUNET_FS_DirScanner * | 453 | struct GNUNET_FS_DirScanner * |
449 | GNUNET_FS_directory_scan_start (const char *filename, | 454 | GNUNET_FS_directory_scan_start(const char *filename, |
450 | int disable_extractor, | 455 | int disable_extractor, |
451 | const char *ex, | 456 | const char *ex, |
452 | GNUNET_FS_DirScannerProgressCallback cb, | 457 | GNUNET_FS_DirScannerProgressCallback cb, |
453 | void *cb_cls) | 458 | void *cb_cls) |
454 | { | 459 | { |
455 | struct stat sbuf; | 460 | struct stat sbuf; |
456 | char *filename_expanded; | 461 | char *filename_expanded; |
457 | struct GNUNET_FS_DirScanner *ds; | 462 | struct GNUNET_FS_DirScanner *ds; |
458 | 463 | ||
459 | if (0 != stat (filename, &sbuf)) | 464 | if (0 != stat(filename, &sbuf)) |
460 | return NULL; | 465 | return NULL; |
461 | filename_expanded = GNUNET_STRINGS_filename_expand (filename); | 466 | filename_expanded = GNUNET_STRINGS_filename_expand(filename); |
462 | if (NULL == filename_expanded) | 467 | if (NULL == filename_expanded) |
463 | return NULL; | 468 | return NULL; |
464 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 469 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
465 | "Starting to scan directory `%s'\n", | 470 | "Starting to scan directory `%s'\n", |
466 | filename_expanded); | 471 | filename_expanded); |
467 | ds = GNUNET_new (struct GNUNET_FS_DirScanner); | 472 | ds = GNUNET_new(struct GNUNET_FS_DirScanner); |
468 | ds->progress_callback = cb; | 473 | ds->progress_callback = cb; |
469 | ds->progress_callback_cls = cb_cls; | 474 | ds->progress_callback_cls = cb_cls; |
470 | ds->filename_expanded = filename_expanded; | 475 | ds->filename_expanded = filename_expanded; |
471 | if (disable_extractor) | 476 | if (disable_extractor) |
472 | ds->ex_arg = GNUNET_strdup ("-"); | 477 | ds->ex_arg = GNUNET_strdup("-"); |
473 | else | 478 | else |
474 | ds->ex_arg = (NULL != ex) ? GNUNET_strdup (ex) : NULL; | 479 | ds->ex_arg = (NULL != ex) ? GNUNET_strdup(ex) : NULL; |
475 | ds->args[0] = "gnunet-helper-fs-publish"; | 480 | ds->args[0] = "gnunet-helper-fs-publish"; |
476 | ds->args[1] = ds->filename_expanded; | 481 | ds->args[1] = ds->filename_expanded; |
477 | ds->args[2] = ds->ex_arg; | 482 | ds->args[2] = ds->ex_arg; |
478 | ds->args[3] = NULL; | 483 | ds->args[3] = NULL; |
479 | ds->helper = GNUNET_HELPER_start (GNUNET_NO, | 484 | ds->helper = GNUNET_HELPER_start(GNUNET_NO, |
480 | "gnunet-helper-fs-publish", | 485 | "gnunet-helper-fs-publish", |
481 | ds->args, | 486 | ds->args, |
482 | &process_helper_msgs, | 487 | &process_helper_msgs, |
483 | &helper_died_cb, | 488 | &helper_died_cb, |
484 | ds); | 489 | ds); |
485 | if (NULL == ds->helper) | 490 | if (NULL == ds->helper) |
486 | { | 491 | { |
487 | GNUNET_free (filename_expanded); | 492 | GNUNET_free(filename_expanded); |
488 | GNUNET_free (ds); | 493 | GNUNET_free(ds); |
489 | return NULL; | 494 | return NULL; |
490 | } | 495 | } |
491 | return ds; | 496 | return ds; |
492 | } | 497 | } |
493 | 498 | ||
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 59821f8a5..de70c53a8 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/fs_download.c | 21 | * @file fs/fs_download.c |
22 | * @brief download methods | 22 | * @brief download methods |
@@ -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"? */ |
@@ -77,18 +77,18 @@ compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) | |||
77 | * to full DBLOCK_SIZE */ | 77 | * to full DBLOCK_SIZE */ |
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 | ||
94 | 94 | ||
@@ -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,26 +114,24 @@ 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 | { | ||
136 | |||
137 | /** | 135 | /** |
138 | * Hash of data. | 136 | * Hash of data. |
139 | */ | 137 | */ |
@@ -191,9 +189,9 @@ struct ProcessResultClosure | |||
191 | * @return #GNUNET_YES (we should continue to iterate); unless serious error | 189 | * @return #GNUNET_YES (we should continue to iterate); unless serious error |
192 | */ | 190 | */ |
193 | static int | 191 | static int |
194 | process_result_with_request (void *cls, | 192 | process_result_with_request(void *cls, |
195 | const struct GNUNET_HashCode *key, | 193 | const struct GNUNET_HashCode *key, |
196 | void *value); | 194 | void *value); |
197 | 195 | ||
198 | 196 | ||
199 | /** | 197 | /** |
@@ -210,12 +208,12 @@ process_result_with_request (void *cls, | |||
210 | * @return GNUNET_OK on success | 208 | * @return GNUNET_OK on success |
211 | */ | 209 | */ |
212 | static int | 210 | static int |
213 | encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, | 211 | encrypt_existing_match(struct GNUNET_FS_DownloadContext *dc, |
214 | const struct ContentHashKey *chk, | 212 | const struct ContentHashKey *chk, |
215 | struct DownloadRequest *dr, | 213 | struct DownloadRequest *dr, |
216 | const char *block, | 214 | const char *block, |
217 | size_t len, | 215 | size_t len, |
218 | int do_store) | 216 | int do_store) |
219 | { | 217 | { |
220 | struct ProcessResultClosure prc; | 218 | struct ProcessResultClosure prc; |
221 | char enc[len]; | 219 | char enc[len]; |
@@ -223,34 +221,34 @@ encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, | |||
223 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 221 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
224 | struct GNUNET_HashCode query; | 222 | struct GNUNET_HashCode query; |
225 | 223 | ||
226 | GNUNET_CRYPTO_hash_to_aes_key (&chk->key, &sk, &iv); | 224 | GNUNET_CRYPTO_hash_to_aes_key(&chk->key, &sk, &iv); |
227 | if (-1 == GNUNET_CRYPTO_symmetric_encrypt (block, len, &sk, &iv, enc)) | 225 | if (-1 == GNUNET_CRYPTO_symmetric_encrypt(block, len, &sk, &iv, enc)) |
228 | { | 226 | { |
229 | GNUNET_break (0); | 227 | GNUNET_break(0); |
230 | return GNUNET_SYSERR; | 228 | return GNUNET_SYSERR; |
231 | } | 229 | } |
232 | GNUNET_CRYPTO_hash (enc, len, &query); | 230 | GNUNET_CRYPTO_hash(enc, len, &query); |
233 | if (0 != memcmp (&query, &chk->query, sizeof (struct GNUNET_HashCode))) | 231 | if (0 != memcmp(&query, &chk->query, sizeof(struct GNUNET_HashCode))) |
234 | { | 232 | { |
235 | GNUNET_break_op (0); | 233 | GNUNET_break_op(0); |
236 | return GNUNET_SYSERR; | 234 | return GNUNET_SYSERR; |
237 | } | 235 | } |
238 | GNUNET_log ( | 236 | GNUNET_log( |
239 | GNUNET_ERROR_TYPE_DEBUG, | 237 | GNUNET_ERROR_TYPE_DEBUG, |
240 | "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n", | 238 | "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n", |
241 | (unsigned int) len, | 239 | (unsigned int)len, |
242 | dc->filename, | 240 | dc->filename, |
243 | (unsigned long long) dr->offset); | 241 | (unsigned long long)dr->offset); |
244 | /* already got it! */ | 242 | /* already got it! */ |
245 | prc.dc = dc; | 243 | prc.dc = dc; |
246 | prc.data = enc; | 244 | prc.data = enc; |
247 | prc.size = len; | 245 | prc.size = len; |
248 | prc.type = (0 == dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK | 246 | prc.type = (0 == dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK |
249 | : GNUNET_BLOCK_TYPE_FS_IBLOCK; | 247 | : GNUNET_BLOCK_TYPE_FS_IBLOCK; |
250 | prc.query = chk->query; | 248 | prc.query = chk->query; |
251 | prc.do_store = do_store; | 249 | prc.do_store = do_store; |
252 | prc.last_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; | 250 | prc.last_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; |
253 | process_result_with_request (&prc, &chk->key, dr); | 251 | process_result_with_request(&prc, &chk->key, dr); |
254 | return GNUNET_OK; | 252 | return GNUNET_OK; |
255 | } | 253 | } |
256 | 254 | ||
@@ -263,7 +261,7 @@ encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, | |||
263 | * @param dc download context that is having trouble | 261 | * @param dc download context that is having trouble |
264 | */ | 262 | */ |
265 | static void | 263 | static void |
266 | try_reconnect (struct GNUNET_FS_DownloadContext *dc); | 264 | try_reconnect(struct GNUNET_FS_DownloadContext *dc); |
267 | 265 | ||
268 | 266 | ||
269 | /** | 267 | /** |
@@ -278,12 +276,12 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc); | |||
278 | * @param data contents of the file (or NULL if they were not inlined) | 276 | * @param data contents of the file (or NULL if they were not inlined) |
279 | */ | 277 | */ |
280 | static void | 278 | static void |
281 | trigger_recursive_download (void *cls, | 279 | trigger_recursive_download(void *cls, |
282 | const char *filename, | 280 | const char *filename, |
283 | const struct GNUNET_FS_Uri *uri, | 281 | const struct GNUNET_FS_Uri *uri, |
284 | const struct GNUNET_CONTAINER_MetaData *meta, | 282 | const struct GNUNET_CONTAINER_MetaData *meta, |
285 | size_t length, | 283 | size_t length, |
286 | const void *data); | 284 | const void *data); |
287 | 285 | ||
288 | 286 | ||
289 | /** | 287 | /** |
@@ -293,7 +291,7 @@ trigger_recursive_download (void *cls, | |||
293 | * @param dc context of download that just completed | 291 | * @param dc context of download that just completed |
294 | */ | 292 | */ |
295 | static void | 293 | static void |
296 | full_recursive_download (struct GNUNET_FS_DownloadContext *dc) | 294 | full_recursive_download(struct GNUNET_FS_DownloadContext *dc) |
297 | { | 295 | { |
298 | size_t size; | 296 | size_t size; |
299 | uint64_t size64; | 297 | uint64_t size64; |
@@ -301,64 +299,64 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) | |||
301 | struct GNUNET_DISK_FileHandle *h; | 299 | struct GNUNET_DISK_FileHandle *h; |
302 | struct GNUNET_DISK_MapHandle *m; | 300 | struct GNUNET_DISK_MapHandle *m; |
303 | 301 | ||
304 | size64 = GNUNET_FS_uri_chk_get_file_size (dc->uri); | 302 | size64 = GNUNET_FS_uri_chk_get_file_size(dc->uri); |
305 | size = (size_t) size64; | 303 | size = (size_t)size64; |
306 | if (size64 != (uint64_t) size) | 304 | if (size64 != (uint64_t)size) |
307 | { | 305 | { |
308 | GNUNET_log ( | 306 | GNUNET_log( |
309 | GNUNET_ERROR_TYPE_ERROR, | 307 | GNUNET_ERROR_TYPE_ERROR, |
310 | _ ( | 308 | _( |
311 | "Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); | 309 | "Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); |
312 | return; | 310 | return; |
313 | } | 311 | } |
314 | if (NULL != dc->filename) | 312 | if (NULL != dc->filename) |
315 | { | 313 | { |
316 | h = GNUNET_DISK_file_open (dc->filename, | 314 | h = GNUNET_DISK_file_open(dc->filename, |
317 | GNUNET_DISK_OPEN_READ, | 315 | GNUNET_DISK_OPEN_READ, |
318 | GNUNET_DISK_PERM_NONE); | 316 | GNUNET_DISK_PERM_NONE); |
319 | } | 317 | } |
320 | else | 318 | else |
321 | { | 319 | { |
322 | GNUNET_assert (NULL != dc->temp_filename); | 320 | GNUNET_assert(NULL != dc->temp_filename); |
323 | h = GNUNET_DISK_file_open (dc->temp_filename, | 321 | h = GNUNET_DISK_file_open(dc->temp_filename, |
324 | GNUNET_DISK_OPEN_READ, | 322 | GNUNET_DISK_OPEN_READ, |
325 | GNUNET_DISK_PERM_NONE); | 323 | GNUNET_DISK_PERM_NONE); |
326 | } | 324 | } |
327 | if (NULL == h) | 325 | if (NULL == h) |
328 | return; /* oops */ | 326 | return; /* oops */ |
329 | data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size); | 327 | data = GNUNET_DISK_file_map(h, &m, GNUNET_DISK_MAP_TYPE_READ, size); |
330 | if (NULL == data) | 328 | if (NULL == data) |
331 | { | 329 | { |
332 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 330 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
333 | _ ("Directory too large for system address space\n")); | 331 | _("Directory too large for system address space\n")); |
334 | } | 332 | } |
335 | else | 333 | else |
336 | { | 334 | { |
337 | if (GNUNET_OK != | 335 | if (GNUNET_OK != |
338 | GNUNET_FS_directory_list_contents (size, | 336 | GNUNET_FS_directory_list_contents(size, |
339 | data, | 337 | data, |
340 | 0, | 338 | 0, |
341 | &trigger_recursive_download, | 339 | &trigger_recursive_download, |
342 | dc)) | 340 | dc)) |
343 | { | 341 | { |
344 | GNUNET_log ( | 342 | GNUNET_log( |
345 | GNUNET_ERROR_TYPE_WARNING, | 343 | GNUNET_ERROR_TYPE_WARNING, |
346 | _ ( | 344 | _( |
347 | "Failed to access full directroy contents of `%s' for recursive download\n"), | 345 | "Failed to access full directroy contents of `%s' for recursive download\n"), |
348 | dc->filename); | 346 | dc->filename); |
349 | } | 347 | } |
350 | GNUNET_DISK_file_unmap (m); | 348 | GNUNET_DISK_file_unmap(m); |
351 | } | 349 | } |
352 | GNUNET_DISK_file_close (h); | 350 | GNUNET_DISK_file_close(h); |
353 | if (NULL == dc->filename) | 351 | if (NULL == dc->filename) |
354 | { | 352 | { |
355 | if (0 != unlink (dc->temp_filename)) | 353 | if (0 != unlink(dc->temp_filename)) |
356 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 354 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, |
357 | "unlink", | 355 | "unlink", |
358 | dc->temp_filename); | 356 | dc->temp_filename); |
359 | GNUNET_free (dc->temp_filename); | 357 | GNUNET_free(dc->temp_filename); |
360 | dc->temp_filename = NULL; | 358 | dc->temp_filename = NULL; |
361 | } | 359 | } |
362 | } | 360 | } |
363 | 361 | ||
364 | 362 | ||
@@ -373,48 +371,48 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) | |||
373 | * @param dc download to check for completion of children | 371 | * @param dc download to check for completion of children |
374 | */ | 372 | */ |
375 | static void | 373 | static void |
376 | check_completed (struct GNUNET_FS_DownloadContext *dc) | 374 | check_completed(struct GNUNET_FS_DownloadContext *dc) |
377 | { | 375 | { |
378 | struct GNUNET_FS_ProgressInfo pi; | 376 | struct GNUNET_FS_ProgressInfo pi; |
379 | struct GNUNET_FS_DownloadContext *pos; | 377 | struct GNUNET_FS_DownloadContext *pos; |
380 | 378 | ||
381 | /* first, check if we need to download children */ | 379 | /* first, check if we need to download children */ |
382 | if (is_recursive_download (dc)) | 380 | if (is_recursive_download(dc)) |
383 | full_recursive_download (dc); | 381 | full_recursive_download(dc); |
384 | /* then, check if children are done already */ | 382 | /* then, check if children are done already */ |
385 | for (pos = dc->child_head; NULL != pos; pos = pos->next) | 383 | for (pos = dc->child_head; NULL != pos; pos = pos->next) |
386 | { | 384 | { |
387 | if ((NULL == pos->emsg) && (pos->completed < pos->length)) | 385 | if ((NULL == pos->emsg) && (pos->completed < pos->length)) |
388 | return; /* not done yet */ | 386 | return; /* not done yet */ |
389 | if ((NULL != pos->child_head) && (pos->has_finished != GNUNET_YES)) | 387 | if ((NULL != pos->child_head) && (pos->has_finished != GNUNET_YES)) |
390 | return; /* not transitively done yet */ | 388 | return; /* not transitively done yet */ |
391 | } | 389 | } |
392 | /* All of our children are done, so mark this download done */ | 390 | /* All of our children are done, so mark this download done */ |
393 | dc->has_finished = GNUNET_YES; | 391 | dc->has_finished = GNUNET_YES; |
394 | if (NULL != dc->job_queue) | 392 | if (NULL != dc->job_queue) |
395 | { | 393 | { |
396 | GNUNET_FS_dequeue_ (dc->job_queue); | 394 | GNUNET_FS_dequeue_(dc->job_queue); |
397 | dc->job_queue = NULL; | 395 | dc->job_queue = NULL; |
398 | } | 396 | } |
399 | if (NULL != dc->task) | 397 | if (NULL != dc->task) |
400 | { | 398 | { |
401 | GNUNET_SCHEDULER_cancel (dc->task); | 399 | GNUNET_SCHEDULER_cancel(dc->task); |
402 | dc->task = NULL; | 400 | dc->task = NULL; |
403 | } | 401 | } |
404 | if (NULL != dc->rfh) | 402 | if (NULL != dc->rfh) |
405 | { | 403 | { |
406 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh)); | 404 | GNUNET_break(GNUNET_OK == GNUNET_DISK_file_close(dc->rfh)); |
407 | dc->rfh = NULL; | 405 | dc->rfh = NULL; |
408 | } | 406 | } |
409 | GNUNET_FS_download_sync_ (dc); | 407 | GNUNET_FS_download_sync_(dc); |
410 | 408 | ||
411 | /* signal completion */ | 409 | /* signal completion */ |
412 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_COMPLETED; | 410 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_COMPLETED; |
413 | GNUNET_FS_download_make_status_ (&pi, dc); | 411 | GNUNET_FS_download_make_status_(&pi, dc); |
414 | 412 | ||
415 | /* let parent know */ | 413 | /* let parent know */ |
416 | if (NULL != dc->parent) | 414 | if (NULL != dc->parent) |
417 | check_completed (dc->parent); | 415 | check_completed(dc->parent); |
418 | } | 416 | } |
419 | 417 | ||
420 | 418 | ||
@@ -429,10 +427,10 @@ check_completed (struct GNUNET_FS_DownloadContext *dc) | |||
429 | * @param data_len number of bytes in data | 427 | * @param data_len number of bytes in data |
430 | */ | 428 | */ |
431 | static void | 429 | static void |
432 | try_match_block (struct GNUNET_FS_DownloadContext *dc, | 430 | try_match_block(struct GNUNET_FS_DownloadContext *dc, |
433 | struct DownloadRequest *dr, | 431 | struct DownloadRequest *dr, |
434 | const char *data, | 432 | const char *data, |
435 | size_t data_len) | 433 | size_t data_len) |
436 | { | 434 | { |
437 | struct GNUNET_FS_ProgressInfo pi; | 435 | struct GNUNET_FS_ProgressInfo pi; |
438 | unsigned int i; | 436 | unsigned int i; |
@@ -454,128 +452,130 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
454 | if (BRS_DOWNLOAD_UP == dr->state) | 452 | if (BRS_DOWNLOAD_UP == dr->state) |
455 | return; | 453 | return; |
456 | if (dr->depth > 0) | 454 | if (dr->depth > 0) |
457 | { | ||
458 | if ((dc->offset > 0) || | ||
459 | (dc->length < GNUNET_ntohll (dc->uri->data.chk.file_length))) | ||
460 | { | ||
461 | /* NOTE: this test is not tight, but should suffice; the issue | ||
462 | here is that 'dr->num_children' may inherently only specify a | ||
463 | smaller range than what is in the original file; | ||
464 | thus, reconstruction of (some) inner blocks will fail. | ||
465 | FIXME: we might eventually want to write a tighter test to | ||
466 | maximize the circumstances under which we do succeed with | ||
467 | IBlock reconstruction. (need good tests though). */ | ||
468 | return; | ||
469 | } | ||
470 | complete = GNUNET_YES; | ||
471 | for (i = 0; i < dr->num_children; i++) | ||
472 | { | 455 | { |
473 | drc = dr->children[i]; | 456 | if ((dc->offset > 0) || |
474 | try_match_block (dc, drc, data, data_len); | 457 | (dc->length < GNUNET_ntohll(dc->uri->data.chk.file_length))) |
475 | if (drc->state != BRS_RECONSTRUCT_META_UP) | 458 | { |
476 | complete = GNUNET_NO; | 459 | /* NOTE: this test is not tight, but should suffice; the issue |
477 | else | 460 | here is that 'dr->num_children' may inherently only specify a |
478 | chks[i] = drc->chk; | 461 | smaller range than what is in the original file; |
462 | thus, reconstruction of (some) inner blocks will fail. | ||
463 | FIXME: we might eventually want to write a tighter test to | ||
464 | maximize the circumstances under which we do succeed with | ||
465 | IBlock reconstruction. (need good tests though). */ | ||
466 | 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); | ||
479 | } | 482 | } |
480 | if (GNUNET_YES != complete) | ||
481 | return; | ||
482 | data = (const char *) chks; | ||
483 | dlen = dr->num_children * sizeof (struct ContentHashKey); | ||
484 | } | ||
485 | else | 483 | else |
486 | { | 484 | { |
487 | if (dr->offset > data_len) | 485 | if (dr->offset > data_len) |
488 | return; /* oops */ | 486 | return; /* oops */ |
489 | dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE); | 487 | dlen = GNUNET_MIN(data_len - dr->offset, DBLOCK_SIZE); |
490 | } | 488 | } |
491 | GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key); | 489 | GNUNET_CRYPTO_hash(&data[dr->offset], dlen, &in_chk.key); |
492 | GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv); | 490 | GNUNET_CRYPTO_hash_to_aes_key(&in_chk.key, &sk, &iv); |
493 | if (-1 == | 491 | if (-1 == |
494 | GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], dlen, &sk, &iv, enc)) | 492 | GNUNET_CRYPTO_symmetric_encrypt(&data[dr->offset], dlen, &sk, &iv, enc)) |
495 | { | 493 | { |
496 | GNUNET_break (0); | 494 | GNUNET_break(0); |
497 | return; | 495 | return; |
498 | } | 496 | } |
499 | GNUNET_CRYPTO_hash (enc, dlen, &in_chk.query); | 497 | GNUNET_CRYPTO_hash(enc, dlen, &in_chk.query); |
500 | switch (dr->state) | 498 | switch (dr->state) |
501 | { | 499 | { |
502 | case BRS_INIT: | 500 | case BRS_INIT: |
503 | dr->chk = in_chk; | 501 | dr->chk = in_chk; |
504 | dr->state = BRS_RECONSTRUCT_META_UP; | 502 | dr->state = BRS_RECONSTRUCT_META_UP; |
505 | break; | 503 | break; |
506 | case BRS_CHK_SET: | 504 | |
507 | if (0 != memcmp (&in_chk, &dr->chk, sizeof (struct ContentHashKey))) | 505 | case BRS_CHK_SET: |
508 | { | 506 | if (0 != memcmp(&in_chk, &dr->chk, sizeof(struct ContentHashKey))) |
509 | /* other peer provided bogus meta data */ | 507 | { |
510 | GNUNET_break_op (0); | 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 | |||
574 | default: | ||
575 | /* how did we get here? */ | ||
576 | GNUNET_break(0); | ||
511 | break; | 577 | break; |
512 | } | 578 | } |
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 | default: | ||
575 | /* how did we get here? */ | ||
576 | GNUNET_break (0); | ||
577 | break; | ||
578 | } | ||
579 | } | 579 | } |
580 | 580 | ||
581 | 581 | ||
@@ -598,27 +598,27 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
598 | * @return 0 to continue extracting, 1 to abort | 598 | * @return 0 to continue extracting, 1 to abort |
599 | */ | 599 | */ |
600 | static int | 600 | static int |
601 | match_full_data (void *cls, | 601 | match_full_data(void *cls, |
602 | const char *plugin_name, | 602 | const char *plugin_name, |
603 | enum EXTRACTOR_MetaType type, | 603 | enum EXTRACTOR_MetaType type, |
604 | enum EXTRACTOR_MetaFormat format, | 604 | enum EXTRACTOR_MetaFormat format, |
605 | const char *data_mime_type, | 605 | const char *data_mime_type, |
606 | const char *data, | 606 | const char *data, |
607 | size_t data_len) | 607 | size_t data_len) |
608 | { | 608 | { |
609 | struct GNUNET_FS_DownloadContext *dc = cls; | 609 | struct GNUNET_FS_DownloadContext *dc = cls; |
610 | 610 | ||
611 | if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type) | 611 | if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type) |
612 | return 0; | 612 | return 0; |
613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 613 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
614 | "Found %u bytes of FD!\n", | 614 | "Found %u bytes of FD!\n", |
615 | (unsigned int) data_len); | 615 | (unsigned int)data_len); |
616 | if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len) | 616 | if (GNUNET_FS_uri_chk_get_file_size(dc->uri) != data_len) |
617 | { | 617 | { |
618 | GNUNET_break_op (0); | 618 | GNUNET_break_op(0); |
619 | return 1; /* bogus meta data */ | 619 | return 1; /* bogus meta data */ |
620 | } | 620 | } |
621 | try_match_block (dc, dc->top_request, data, data_len); | 621 | try_match_block(dc, dc->top_request, data, data_len); |
622 | return 1; | 622 | return 1; |
623 | } | 623 | } |
624 | 624 | ||
@@ -630,20 +630,21 @@ match_full_data (void *cls, | |||
630 | * @param dr download request that is done | 630 | * @param dr download request that is done |
631 | */ | 631 | */ |
632 | static void | 632 | static void |
633 | propagate_up (struct DownloadRequest *dr) | 633 | propagate_up(struct DownloadRequest *dr) |
634 | { | 634 | { |
635 | unsigned int i; | 635 | unsigned int i; |
636 | 636 | ||
637 | do | 637 | do |
638 | { | 638 | { |
639 | dr->state = BRS_DOWNLOAD_UP; | 639 | dr->state = BRS_DOWNLOAD_UP; |
640 | dr = dr->parent; | 640 | dr = dr->parent; |
641 | if (NULL == dr) | 641 | if (NULL == dr) |
642 | break; | ||
643 | for (i = 0; i < dr->num_children; i++) | ||
644 | if (dr->children[i]->state != BRS_DOWNLOAD_UP) | ||
645 | break; | 642 | break; |
646 | } while (i == dr->num_children); | 643 | for (i = 0; i < dr->num_children; i++) |
644 | if (dr->children[i]->state != BRS_DOWNLOAD_UP) | ||
645 | break; | ||
646 | } | ||
647 | while (i == dr->num_children); | ||
647 | } | 648 | } |
648 | 649 | ||
649 | 650 | ||
@@ -658,8 +659,8 @@ propagate_up (struct DownloadRequest *dr) | |||
658 | * @param dr block to reconstruct | 659 | * @param dr block to reconstruct |
659 | */ | 660 | */ |
660 | static void | 661 | static void |
661 | try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, | 662 | try_top_down_reconstruction(struct GNUNET_FS_DownloadContext *dc, |
662 | struct DownloadRequest *dr) | 663 | struct DownloadRequest *dr) |
663 | { | 664 | { |
664 | uint64_t off; | 665 | uint64_t off; |
665 | char block[DBLOCK_SIZE]; | 666 | char block[DBLOCK_SIZE]; |
@@ -672,64 +673,64 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, | |||
672 | const struct ContentHashKey *chks; | 673 | const struct ContentHashKey *chks; |
673 | int up_done; | 674 | int up_done; |
674 | 675 | ||
675 | GNUNET_assert (NULL != dc->rfh); | 676 | GNUNET_assert(NULL != dc->rfh); |
676 | GNUNET_assert (BRS_CHK_SET == dr->state); | 677 | GNUNET_assert(BRS_CHK_SET == dr->state); |
677 | total = GNUNET_FS_uri_chk_get_file_size (dc->uri); | 678 | total = GNUNET_FS_uri_chk_get_file_size(dc->uri); |
678 | GNUNET_assert (dr->depth < dc->treedepth); | 679 | GNUNET_assert(dr->depth < dc->treedepth); |
679 | len = GNUNET_FS_tree_calculate_block_size (total, dr->offset, dr->depth); | 680 | len = GNUNET_FS_tree_calculate_block_size(total, dr->offset, dr->depth); |
680 | GNUNET_assert (len <= DBLOCK_SIZE); | 681 | GNUNET_assert(len <= DBLOCK_SIZE); |
681 | off = compute_disk_offset (total, dr->offset, dr->depth); | 682 | off = compute_disk_offset(total, dr->offset, dr->depth); |
682 | if (dc->old_file_size < off + len) | 683 | if (dc->old_file_size < off + len) |
683 | return; /* failure */ | 684 | return; /* failure */ |
684 | if (off != GNUNET_DISK_file_seek (dc->rfh, off, GNUNET_DISK_SEEK_SET)) | 685 | if (off != GNUNET_DISK_file_seek(dc->rfh, off, GNUNET_DISK_SEEK_SET)) |
685 | { | 686 | { |
686 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename); | 687 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename); |
687 | return; /* failure */ | 688 | return; /* failure */ |
688 | } | 689 | } |
689 | if (len != GNUNET_DISK_file_read (dc->rfh, block, len)) | 690 | if (len != GNUNET_DISK_file_read(dc->rfh, block, len)) |
690 | { | 691 | { |
691 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", dc->filename); | 692 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "read", dc->filename); |
692 | return; /* failure */ | 693 | return; /* failure */ |
693 | } | 694 | } |
694 | GNUNET_CRYPTO_hash (block, len, &key); | 695 | GNUNET_CRYPTO_hash(block, len, &key); |
695 | if (0 != memcmp (&key, &dr->chk.key, sizeof (struct GNUNET_HashCode))) | 696 | if (0 != memcmp(&key, &dr->chk.key, sizeof(struct GNUNET_HashCode))) |
696 | return; /* mismatch */ | 697 | return; /* mismatch */ |
697 | if (GNUNET_OK != | 698 | if (GNUNET_OK != |
698 | encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO)) | 699 | encrypt_existing_match(dc, &dr->chk, dr, block, len, GNUNET_NO)) |
699 | { | ||
700 | /* hash matches but encrypted block does not, really bad */ | ||
701 | dr->state = BRS_ERROR; | ||
702 | /* propagate up */ | ||
703 | while (NULL != dr->parent) | ||
704 | { | 700 | { |
705 | dr = dr->parent; | 701 | /* hash matches but encrypted block does not, really bad */ |
706 | dr->state = BRS_ERROR; | 702 | 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; | ||
707 | } | 710 | } |
708 | return; | ||
709 | } | ||
710 | /* block matches */ | 711 | /* block matches */ |
711 | dr->state = BRS_DOWNLOAD_DOWN; | 712 | dr->state = BRS_DOWNLOAD_DOWN; |
712 | 713 | ||
713 | /* set CHKs for children */ | 714 | /* set CHKs for children */ |
714 | up_done = GNUNET_YES; | 715 | up_done = GNUNET_YES; |
715 | chks = (const struct ContentHashKey *) block; | 716 | chks = (const struct ContentHashKey *)block; |
716 | for (i = 0; i < dr->num_children; i++) | 717 | for (i = 0; i < dr->num_children; i++) |
717 | { | 718 | { |
718 | drc = dr->children[i]; | 719 | drc = dr->children[i]; |
719 | GNUNET_assert (drc->offset >= dr->offset); | 720 | GNUNET_assert(drc->offset >= dr->offset); |
720 | child_block_size = GNUNET_FS_tree_compute_tree_size (drc->depth); | 721 | child_block_size = GNUNET_FS_tree_compute_tree_size(drc->depth); |
721 | GNUNET_assert (0 == (drc->offset - dr->offset) % child_block_size); | 722 | GNUNET_assert(0 == (drc->offset - dr->offset) % child_block_size); |
722 | if (BRS_INIT == drc->state) | 723 | if (BRS_INIT == drc->state) |
723 | { | 724 | { |
724 | drc->state = BRS_CHK_SET; | 725 | drc->state = BRS_CHK_SET; |
725 | drc->chk = chks[drc->chk_idx]; | 726 | drc->chk = chks[drc->chk_idx]; |
726 | try_top_down_reconstruction (dc, drc); | 727 | try_top_down_reconstruction(dc, drc); |
727 | } | 728 | } |
728 | if (BRS_DOWNLOAD_UP != drc->state) | 729 | if (BRS_DOWNLOAD_UP != drc->state) |
729 | up_done = GNUNET_NO; /* children not all done */ | 730 | up_done = GNUNET_NO; /* children not all done */ |
730 | } | 731 | } |
731 | if (GNUNET_YES == up_done) | 732 | if (GNUNET_YES == up_done) |
732 | propagate_up (dr); /* children all done (or no children...) */ | 733 | propagate_up(dr); /* children all done (or no children...) */ |
733 | } | 734 | } |
734 | 735 | ||
735 | 736 | ||
@@ -742,26 +743,26 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, | |||
742 | * @return #GNUNET_OK | 743 | * @return #GNUNET_OK |
743 | */ | 744 | */ |
744 | static int | 745 | static int |
745 | retry_entry (void *cls, const struct GNUNET_HashCode *key, void *entry) | 746 | retry_entry(void *cls, const struct GNUNET_HashCode *key, void *entry) |
746 | { | 747 | { |
747 | struct GNUNET_FS_DownloadContext *dc = cls; | 748 | struct GNUNET_FS_DownloadContext *dc = cls; |
748 | struct DownloadRequest *dr = entry; | 749 | struct DownloadRequest *dr = entry; |
749 | struct SearchMessage *sm; | 750 | struct SearchMessage *sm; |
750 | struct GNUNET_MQ_Envelope *env; | 751 | struct GNUNET_MQ_Envelope *env; |
751 | 752 | ||
752 | env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_FS_START_SEARCH); | 753 | env = GNUNET_MQ_msg(sm, GNUNET_MESSAGE_TYPE_FS_START_SEARCH); |
753 | if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY)) | 754 | if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY)) |
754 | sm->options = htonl (GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY); | 755 | sm->options = htonl(GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY); |
755 | else | 756 | else |
756 | sm->options = htonl (GNUNET_FS_SEARCH_OPTION_NONE); | 757 | sm->options = htonl(GNUNET_FS_SEARCH_OPTION_NONE); |
757 | if (0 == dr->depth) | 758 | if (0 == dr->depth) |
758 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_DBLOCK); | 759 | sm->type = htonl(GNUNET_BLOCK_TYPE_FS_DBLOCK); |
759 | else | 760 | else |
760 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_IBLOCK); | 761 | sm->type = htonl(GNUNET_BLOCK_TYPE_FS_IBLOCK); |
761 | sm->anonymity_level = htonl (dc->anonymity); | 762 | sm->anonymity_level = htonl(dc->anonymity); |
762 | sm->target = dc->target; | 763 | sm->target = dc->target; |
763 | sm->query = dr->chk.query; | 764 | sm->query = dr->chk.query; |
764 | GNUNET_MQ_send (dc->mq, env); | 765 | GNUNET_MQ_send(dc->mq, env); |
765 | return GNUNET_OK; | 766 | return GNUNET_OK; |
766 | } | 767 | } |
767 | 768 | ||
@@ -773,55 +774,62 @@ retry_entry (void *cls, const struct GNUNET_HashCode *key, void *entry) | |||
773 | * @param dr request to schedule | 774 | * @param dr request to schedule |
774 | */ | 775 | */ |
775 | static void | 776 | static void |
776 | schedule_block_download (struct GNUNET_FS_DownloadContext *dc, | 777 | schedule_block_download(struct GNUNET_FS_DownloadContext *dc, |
777 | struct DownloadRequest *dr) | 778 | struct DownloadRequest *dr) |
778 | { | 779 | { |
779 | unsigned int i; | 780 | unsigned int i; |
780 | 781 | ||
781 | switch (dr->state) | 782 | switch (dr->state) |
782 | { | 783 | { |
783 | case BRS_INIT: | 784 | case BRS_INIT: |
784 | GNUNET_assert (0); | 785 | GNUNET_assert(0); |
785 | break; | 786 | break; |
786 | case BRS_RECONSTRUCT_DOWN: | 787 | |
787 | GNUNET_assert (0); | 788 | case BRS_RECONSTRUCT_DOWN: |
788 | break; | 789 | GNUNET_assert(0); |
789 | case BRS_RECONSTRUCT_META_UP: | 790 | break; |
790 | GNUNET_assert (0); | 791 | |
791 | break; | 792 | case BRS_RECONSTRUCT_META_UP: |
792 | case BRS_RECONSTRUCT_UP: | 793 | GNUNET_assert(0); |
793 | GNUNET_assert (0); | 794 | break; |
794 | break; | 795 | |
795 | case BRS_CHK_SET: | 796 | case BRS_RECONSTRUCT_UP: |
796 | /* normal case, start download */ | 797 | GNUNET_assert(0); |
797 | break; | 798 | break; |
798 | case BRS_DOWNLOAD_DOWN: | 799 | |
799 | for (i = 0; i < dr->num_children; i++) | 800 | case BRS_CHK_SET: |
800 | schedule_block_download (dc, dr->children[i]); | 801 | /* normal case, start download */ |
801 | return; | 802 | break; |
802 | case BRS_DOWNLOAD_UP: | 803 | |
803 | /* We're done! */ | 804 | case BRS_DOWNLOAD_DOWN: |
804 | return; | 805 | for (i = 0; i < dr->num_children; i++) |
805 | case BRS_ERROR: | 806 | schedule_block_download(dc, dr->children[i]); |
806 | GNUNET_break (0); | 807 | return; |
807 | return; | 808 | |
808 | } | 809 | case BRS_DOWNLOAD_UP: |
809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 810 | /* We're done! */ |
810 | "Scheduling download at offset %llu and depth %u for `%s'\n", | 811 | return; |
811 | (unsigned long long) dr->offset, | 812 | |
812 | dr->depth, | 813 | case BRS_ERROR: |
813 | GNUNET_h2s (&dr->chk.query)); | 814 | GNUNET_break(0); |
814 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains_value (dc->active, | 815 | return; |
815 | &dr->chk.query, | 816 | } |
816 | dr)) | 817 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
818 | "Scheduling download at offset %llu and depth %u for `%s'\n", | ||
819 | (unsigned long long)dr->offset, | ||
820 | dr->depth, | ||
821 | GNUNET_h2s(&dr->chk.query)); | ||
822 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains_value(dc->active, | ||
823 | &dr->chk.query, | ||
824 | dr)) | ||
817 | return; /* already active */ | 825 | return; /* already active */ |
818 | GNUNET_CONTAINER_multihashmap_put (dc->active, | 826 | GNUNET_CONTAINER_multihashmap_put(dc->active, |
819 | &dr->chk.query, | 827 | &dr->chk.query, |
820 | dr, | 828 | dr, |
821 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 829 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
822 | if (NULL == dc->mq) | 830 | if (NULL == dc->mq) |
823 | return; /* download not active */ | 831 | return; /* download not active */ |
824 | retry_entry (dc, &dr->chk.query, dr); | 832 | retry_entry(dc, &dr->chk.query, dr); |
825 | } | 833 | } |
826 | 834 | ||
827 | 835 | ||
@@ -839,12 +847,12 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc, | |||
839 | * @param data contents of the file (or NULL if they were not inlined) | 847 | * @param data contents of the file (or NULL if they were not inlined) |
840 | */ | 848 | */ |
841 | static void | 849 | static void |
842 | trigger_recursive_download (void *cls, | 850 | trigger_recursive_download(void *cls, |
843 | const char *filename, | 851 | const char *filename, |
844 | const struct GNUNET_FS_Uri *uri, | 852 | const struct GNUNET_FS_Uri *uri, |
845 | const struct GNUNET_CONTAINER_MetaData *meta, | 853 | const struct GNUNET_CONTAINER_MetaData *meta, |
846 | size_t length, | 854 | size_t length, |
847 | const void *data) | 855 | const void *data) |
848 | { | 856 | { |
849 | struct GNUNET_FS_DownloadContext *dc = cls; | 857 | struct GNUNET_FS_DownloadContext *dc = cls; |
850 | struct GNUNET_FS_DownloadContext *cpos; | 858 | struct GNUNET_FS_DownloadContext *cpos; |
@@ -861,121 +869,121 @@ trigger_recursive_download (void *cls, | |||
861 | return; /* entry for the directory itself */ | 869 | return; /* entry for the directory itself */ |
862 | cpos = dc->child_head; | 870 | cpos = dc->child_head; |
863 | while (NULL != cpos) | 871 | while (NULL != cpos) |
864 | { | 872 | { |
865 | if ((GNUNET_FS_uri_test_equal (uri, cpos->uri)) || | 873 | if ((GNUNET_FS_uri_test_equal(uri, cpos->uri)) || |
866 | ((NULL != filename) && (0 == strcmp (cpos->filename, filename)))) | 874 | ((NULL != filename) && (0 == strcmp(cpos->filename, filename)))) |
867 | break; | 875 | break; |
868 | cpos = cpos->next; | 876 | cpos = cpos->next; |
869 | } | 877 | } |
870 | if (NULL != cpos) | 878 | if (NULL != cpos) |
871 | return; /* already exists */ | 879 | return; /* already exists */ |
872 | fn = NULL; | 880 | fn = NULL; |
873 | if (NULL == filename) | 881 | if (NULL == filename) |
874 | { | 882 | { |
875 | fn = GNUNET_FS_meta_data_suggest_filename (meta); | 883 | fn = GNUNET_FS_meta_data_suggest_filename(meta); |
876 | if (NULL == fn) | 884 | if (NULL == fn) |
877 | { | 885 | { |
878 | us = GNUNET_FS_uri_to_string (uri); | 886 | us = GNUNET_FS_uri_to_string(uri); |
879 | fn = GNUNET_strdup (&us[strlen (GNUNET_FS_URI_CHK_PREFIX)]); | 887 | fn = GNUNET_strdup(&us[strlen(GNUNET_FS_URI_CHK_PREFIX)]); |
880 | GNUNET_free (us); | 888 | GNUNET_free(us); |
881 | } | 889 | } |
882 | else if ('.' == fn[0]) | 890 | else if ('.' == fn[0]) |
883 | { | 891 | { |
884 | ext = fn; | 892 | ext = fn; |
885 | us = GNUNET_FS_uri_to_string (uri); | 893 | us = GNUNET_FS_uri_to_string(uri); |
886 | GNUNET_asprintf (&fn, | 894 | GNUNET_asprintf(&fn, |
887 | "%s%s", | 895 | "%s%s", |
888 | &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], | 896 | &us[strlen(GNUNET_FS_URI_CHK_PREFIX)], |
889 | ext); | 897 | ext); |
890 | GNUNET_free (ext); | 898 | GNUNET_free(ext); |
891 | GNUNET_free (us); | 899 | GNUNET_free(us); |
892 | } | 900 | } |
893 | /* change '\' to '/' (this should have happened | 901 | /* change '\' to '/' (this should have happened |
894 | * during insertion, but malicious peers may | 902 | * during insertion, but malicious peers may |
895 | * not have done this) */ | 903 | * not have done this) */ |
896 | while (NULL != (pos = strstr (fn, "\\"))) | 904 | while (NULL != (pos = strstr(fn, "\\"))) |
897 | *pos = '/'; | 905 | *pos = '/'; |
898 | /* remove '../' everywhere (again, well-behaved | 906 | /* remove '../' everywhere (again, well-behaved |
899 | * peers don't do this, but don't trust that | 907 | * peers don't do this, but don't trust that |
900 | * we did not get something nasty) */ | 908 | * we did not get something nasty) */ |
901 | while (NULL != (pos = strstr (fn, "../"))) | 909 | while (NULL != (pos = strstr(fn, "../"))) |
902 | { | 910 | { |
903 | pos[0] = '_'; | 911 | pos[0] = '_'; |
904 | pos[1] = '_'; | 912 | pos[1] = '_'; |
905 | pos[2] = '_'; | 913 | pos[2] = '_'; |
906 | } | 914 | } |
907 | filename = fn; | 915 | filename = fn; |
908 | } | 916 | } |
909 | if (NULL == dc->filename) | 917 | if (NULL == dc->filename) |
910 | { | 918 | { |
911 | full_name = NULL; | 919 | full_name = NULL; |
912 | } | 920 | } |
913 | else | 921 | else |
914 | { | 922 | { |
915 | dn = GNUNET_strdup (dc->filename); | 923 | dn = GNUNET_strdup(dc->filename); |
916 | GNUNET_break ( | 924 | GNUNET_break( |
917 | (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && | 925 | (strlen(dn) >= strlen(GNUNET_FS_DIRECTORY_EXT)) && |
918 | (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), | 926 | (NULL != strstr(dn + strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT), |
919 | GNUNET_FS_DIRECTORY_EXT))); | 927 | GNUNET_FS_DIRECTORY_EXT))); |
920 | sfn = GNUNET_strdup (filename); | 928 | sfn = GNUNET_strdup(filename); |
921 | while ((strlen (sfn) > 0) && ('/' == filename[strlen (sfn) - 1])) | 929 | while ((strlen(sfn) > 0) && ('/' == filename[strlen(sfn) - 1])) |
922 | sfn[strlen (sfn) - 1] = '\0'; | 930 | sfn[strlen(sfn) - 1] = '\0'; |
923 | if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && | 931 | if ((strlen(dn) >= strlen(GNUNET_FS_DIRECTORY_EXT)) && |
924 | (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), | 932 | (NULL != strstr(dn + strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT), |
925 | GNUNET_FS_DIRECTORY_EXT))) | 933 | GNUNET_FS_DIRECTORY_EXT))) |
926 | dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0'; | 934 | dn[strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT)] = '\0'; |
927 | if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) && | 935 | if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) && |
928 | ((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) || | 936 | ((strlen(filename) < strlen(GNUNET_FS_DIRECTORY_EXT)) || |
929 | (NULL == strstr (filename + strlen (filename) - | 937 | (NULL == strstr(filename + strlen(filename) - |
930 | strlen (GNUNET_FS_DIRECTORY_EXT), | 938 | strlen(GNUNET_FS_DIRECTORY_EXT), |
931 | GNUNET_FS_DIRECTORY_EXT)))) | 939 | GNUNET_FS_DIRECTORY_EXT)))) |
932 | { | 940 | { |
933 | GNUNET_asprintf (&full_name, | 941 | GNUNET_asprintf(&full_name, |
934 | "%s%s%s%s", | 942 | "%s%s%s%s", |
935 | dn, | 943 | dn, |
936 | DIR_SEPARATOR_STR, | 944 | DIR_SEPARATOR_STR, |
937 | sfn, | 945 | sfn, |
938 | GNUNET_FS_DIRECTORY_EXT); | 946 | GNUNET_FS_DIRECTORY_EXT); |
939 | } | 947 | } |
940 | else | 948 | else |
941 | { | 949 | { |
942 | GNUNET_asprintf (&full_name, "%s%s%s", dn, DIR_SEPARATOR_STR, sfn); | 950 | GNUNET_asprintf(&full_name, "%s%s%s", dn, DIR_SEPARATOR_STR, sfn); |
943 | } | 951 | } |
944 | GNUNET_free (sfn); | 952 | GNUNET_free(sfn); |
945 | GNUNET_free (dn); | 953 | GNUNET_free(dn); |
946 | } | 954 | } |
947 | if ((NULL != full_name) && | 955 | if ((NULL != full_name) && |
948 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name))) | 956 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file(full_name))) |
949 | { | 957 | { |
950 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 958 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
951 | _ ( | 959 | _( |
952 | "Failed to create directory for recursive download of `%s'\n"), | 960 | "Failed to create directory for recursive download of `%s'\n"), |
953 | full_name); | 961 | full_name); |
954 | GNUNET_free (full_name); | 962 | GNUNET_free(full_name); |
955 | GNUNET_free_non_null (fn); | 963 | GNUNET_free_non_null(fn); |
956 | return; | 964 | return; |
957 | } | 965 | } |
958 | 966 | ||
959 | temp_name = NULL; | 967 | temp_name = NULL; |
960 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 968 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
961 | "Triggering recursive download of size %llu with %u bytes MD\n", | 969 | "Triggering recursive download of size %llu with %u bytes MD\n", |
962 | (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri), | 970 | (unsigned long long)GNUNET_FS_uri_chk_get_file_size(uri), |
963 | (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size ( | 971 | (unsigned int)GNUNET_CONTAINER_meta_data_get_serialized_size( |
964 | meta)); | 972 | meta)); |
965 | GNUNET_FS_download_start (dc->h, | 973 | GNUNET_FS_download_start(dc->h, |
966 | uri, | 974 | uri, |
967 | meta, | 975 | meta, |
968 | full_name, | 976 | full_name, |
969 | temp_name, | 977 | temp_name, |
970 | 0, | 978 | 0, |
971 | GNUNET_FS_uri_chk_get_file_size (uri), | 979 | GNUNET_FS_uri_chk_get_file_size(uri), |
972 | dc->anonymity, | 980 | dc->anonymity, |
973 | dc->options, | 981 | dc->options, |
974 | NULL, | 982 | NULL, |
975 | dc); | 983 | dc); |
976 | GNUNET_free_non_null (full_name); | 984 | GNUNET_free_non_null(full_name); |
977 | GNUNET_free_non_null (temp_name); | 985 | GNUNET_free_non_null(temp_name); |
978 | GNUNET_free_non_null (fn); | 986 | GNUNET_free_non_null(fn); |
979 | } | 987 | } |
980 | 988 | ||
981 | 989 | ||
@@ -985,14 +993,14 @@ trigger_recursive_download (void *cls, | |||
985 | * @param dr request to free | 993 | * @param dr request to free |
986 | */ | 994 | */ |
987 | void | 995 | void |
988 | GNUNET_FS_free_download_request_ (struct DownloadRequest *dr) | 996 | GNUNET_FS_free_download_request_(struct DownloadRequest *dr) |
989 | { | 997 | { |
990 | if (NULL == dr) | 998 | if (NULL == dr) |
991 | return; | 999 | return; |
992 | for (unsigned int i = 0; i < dr->num_children; i++) | 1000 | for (unsigned int i = 0; i < dr->num_children; i++) |
993 | GNUNET_FS_free_download_request_ (dr->children[i]); | 1001 | GNUNET_FS_free_download_request_(dr->children[i]); |
994 | GNUNET_free_non_null (dr->children); | 1002 | GNUNET_free_non_null(dr->children); |
995 | GNUNET_free (dr); | 1003 | GNUNET_free(dr); |
996 | } | 1004 | } |
997 | 1005 | ||
998 | 1006 | ||
@@ -1006,9 +1014,9 @@ GNUNET_FS_free_download_request_ (struct DownloadRequest *dr) | |||
1006 | * @return #GNUNET_YES (we should continue to iterate); unless serious error | 1014 | * @return #GNUNET_YES (we should continue to iterate); unless serious error |
1007 | */ | 1015 | */ |
1008 | static int | 1016 | static int |
1009 | process_result_with_request (void *cls, | 1017 | process_result_with_request(void *cls, |
1010 | const struct GNUNET_HashCode *key, | 1018 | const struct GNUNET_HashCode *key, |
1011 | void *value) | 1019 | void *value) |
1012 | { | 1020 | { |
1013 | struct ProcessResultClosure *prc = cls; | 1021 | struct ProcessResultClosure *prc = cls; |
1014 | struct DownloadRequest *dr = value; | 1022 | struct DownloadRequest *dr = value; |
@@ -1025,132 +1033,132 @@ process_result_with_request (void *cls, | |||
1025 | int i; | 1033 | int i; |
1026 | struct ContentHashKey *chkarr; | 1034 | struct ContentHashKey *chkarr; |
1027 | 1035 | ||
1028 | GNUNET_log ( | 1036 | GNUNET_log( |
1029 | GNUNET_ERROR_TYPE_DEBUG, | 1037 | GNUNET_ERROR_TYPE_DEBUG, |
1030 | "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n", | 1038 | "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n", |
1031 | (unsigned int) prc->size, | 1039 | (unsigned int)prc->size, |
1032 | GNUNET_h2s (key), | 1040 | GNUNET_h2s(key), |
1033 | dr->depth, | 1041 | dr->depth, |
1034 | (unsigned long long) dr->offset, | 1042 | (unsigned long long)dr->offset, |
1035 | (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length)); | 1043 | (unsigned long long)GNUNET_ntohll(dc->uri->data.chk.file_length)); |
1036 | bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll ( | 1044 | bs = GNUNET_FS_tree_calculate_block_size(GNUNET_ntohll( |
1037 | dc->uri->data.chk.file_length), | 1045 | dc->uri->data.chk.file_length), |
1038 | dr->offset, | 1046 | dr->offset, |
1039 | dr->depth); | 1047 | dr->depth); |
1040 | if (prc->size != bs) | 1048 | if (prc->size != bs) |
1041 | { | ||
1042 | GNUNET_asprintf ( | ||
1043 | &dc->emsg, | ||
1044 | _ ( | ||
1045 | "Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"), | ||
1046 | bs, | ||
1047 | dr->depth, | ||
1048 | (unsigned long long) dr->offset, | ||
1049 | (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length), | ||
1050 | prc->size); | ||
1051 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", dc->emsg); | ||
1052 | while (NULL != dr->parent) | ||
1053 | { | 1049 | { |
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 | } | ||
1054 | dr->state = BRS_ERROR; | 1065 | dr->state = BRS_ERROR; |
1055 | dr = dr->parent; | 1066 | goto signal_error; |
1056 | } | 1067 | } |
1057 | dr->state = BRS_ERROR; | ||
1058 | goto signal_error; | ||
1059 | } | ||
1060 | 1068 | ||
1061 | (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, &prc->query, dr); | 1069 | (void)GNUNET_CONTAINER_multihashmap_remove(dc->active, &prc->query, dr); |
1062 | GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, &skey, &iv); | 1070 | GNUNET_CRYPTO_hash_to_aes_key(&dr->chk.key, &skey, &iv); |
1063 | if (-1 == | 1071 | if (-1 == |
1064 | GNUNET_CRYPTO_symmetric_decrypt (prc->data, prc->size, &skey, &iv, pt)) | 1072 | GNUNET_CRYPTO_symmetric_decrypt(prc->data, prc->size, &skey, &iv, pt)) |
1065 | { | 1073 | { |
1066 | GNUNET_break (0); | 1074 | GNUNET_break(0); |
1067 | dc->emsg = GNUNET_strdup (_ ("internal error decrypting content")); | 1075 | dc->emsg = GNUNET_strdup(_("internal error decrypting content")); |
1068 | goto signal_error; | 1076 | goto signal_error; |
1069 | } | 1077 | } |
1070 | off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length), | 1078 | off = compute_disk_offset(GNUNET_ntohll(dc->uri->data.chk.file_length), |
1071 | dr->offset, | 1079 | dr->offset, |
1072 | dr->depth); | 1080 | dr->depth); |
1073 | /* save to disk */ | 1081 | /* save to disk */ |
1074 | if ((GNUNET_YES == prc->do_store) && | 1082 | if ((GNUNET_YES == prc->do_store) && |
1075 | ((NULL != dc->filename) || (is_recursive_download (dc))) && | 1083 | ((NULL != dc->filename) || (is_recursive_download(dc))) && |
1076 | ((dr->depth == dc->treedepth) || | 1084 | ((dr->depth == dc->treedepth) || |
1077 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)))) | 1085 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)))) |
1078 | { | ||
1079 | fh = GNUNET_DISK_file_open (NULL != dc->filename ? dc->filename | ||
1080 | : dc->temp_filename, | ||
1081 | GNUNET_DISK_OPEN_READWRITE | | ||
1082 | GNUNET_DISK_OPEN_CREATE, | ||
1083 | GNUNET_DISK_PERM_USER_READ | | ||
1084 | GNUNET_DISK_PERM_USER_WRITE | | ||
1085 | GNUNET_DISK_PERM_GROUP_READ | | ||
1086 | GNUNET_DISK_PERM_OTHER_READ); | ||
1087 | if (NULL == fh) | ||
1088 | { | ||
1089 | GNUNET_asprintf (&dc->emsg, | ||
1090 | _ ("Download failed: could not open file `%s': %s"), | ||
1091 | dc->filename, | ||
1092 | strerror (errno)); | ||
1093 | goto signal_error; | ||
1094 | } | ||
1095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1096 | "Saving decrypted block to disk at offset %llu\n", | ||
1097 | (unsigned long long) off); | ||
1098 | if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET))) | ||
1099 | { | ||
1100 | GNUNET_asprintf (&dc->emsg, | ||
1101 | _ ("Failed to seek to offset %llu in file `%s': %s"), | ||
1102 | (unsigned long long) off, | ||
1103 | dc->filename, | ||
1104 | strerror (errno)); | ||
1105 | goto signal_error; | ||
1106 | } | ||
1107 | if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size)) | ||
1108 | { | 1086 | { |
1109 | GNUNET_asprintf ( | 1087 | fh = GNUNET_DISK_file_open(NULL != dc->filename ? dc->filename |
1110 | &dc->emsg, | 1088 | : dc->temp_filename, |
1111 | _ ("Failed to write block of %u bytes at offset %llu in file `%s': %s"), | 1089 | GNUNET_DISK_OPEN_READWRITE | |
1112 | (unsigned int) prc->size, | 1090 | GNUNET_DISK_OPEN_CREATE, |
1113 | (unsigned long long) off, | 1091 | GNUNET_DISK_PERM_USER_READ | |
1114 | dc->filename, | 1092 | GNUNET_DISK_PERM_USER_WRITE | |
1115 | strerror (errno)); | 1093 | GNUNET_DISK_PERM_GROUP_READ | |
1116 | goto signal_error; | 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; | ||
1117 | } | 1128 | } |
1118 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); | ||
1119 | fh = NULL; | ||
1120 | } | ||
1121 | 1129 | ||
1122 | if (0 == dr->depth) | 1130 | if (0 == dr->depth) |
1123 | { | 1131 | { |
1124 | /* DBLOCK, update progress and try recursion if applicable */ | 1132 | /* DBLOCK, update progress and try recursion if applicable */ |
1125 | app = prc->size; | 1133 | app = prc->size; |
1126 | if (dr->offset < dc->offset) | 1134 | if (dr->offset < dc->offset) |
1127 | { | 1135 | { |
1128 | /* starting offset begins in the middle of pt, | 1136 | /* starting offset begins in the middle of pt, |
1129 | * do not count first bytes as progress */ | 1137 | * do not count first bytes as progress */ |
1130 | GNUNET_assert (app > (dc->offset - dr->offset)); | 1138 | GNUNET_assert(app > (dc->offset - dr->offset)); |
1131 | app -= (dc->offset - dr->offset); | 1139 | app -= (dc->offset - dr->offset); |
1132 | } | 1140 | } |
1133 | if (dr->offset + prc->size > dc->offset + dc->length) | 1141 | if (dr->offset + prc->size > dc->offset + dc->length) |
1134 | { | 1142 | { |
1135 | /* end of block is after relevant range, | 1143 | /* end of block is after relevant range, |
1136 | * do not count last bytes as progress */ | 1144 | * do not count last bytes as progress */ |
1137 | GNUNET_assert (app > | 1145 | GNUNET_assert(app > |
1138 | (dr->offset + prc->size) - (dc->offset + dc->length)); | 1146 | (dr->offset + prc->size) - (dc->offset + dc->length)); |
1139 | app -= (dr->offset + prc->size) - (dc->offset + dc->length); | 1147 | app -= (dr->offset + prc->size) - (dc->offset + dc->length); |
1140 | } | 1148 | } |
1141 | dc->completed += app; | 1149 | dc->completed += app; |
1142 | 1150 | ||
1143 | /* do recursive download if option is set and either meta data | 1151 | /* do recursive download if option is set and either meta data |
1144 | * says it is a directory or if no meta data is given AND filename | 1152 | * says it is a directory or if no meta data is given AND filename |
1145 | * ends in '.gnd' (top-level case) */ | 1153 | * ends in '.gnd' (top-level case) */ |
1146 | if (is_recursive_download (dc)) | 1154 | if (is_recursive_download(dc)) |
1147 | GNUNET_FS_directory_list_contents (prc->size, | 1155 | GNUNET_FS_directory_list_contents(prc->size, |
1148 | pt, | 1156 | pt, |
1149 | off, | 1157 | off, |
1150 | &trigger_recursive_download, | 1158 | &trigger_recursive_download, |
1151 | dc); | 1159 | dc); |
1152 | } | 1160 | } |
1153 | GNUNET_assert (dc->completed <= dc->length); | 1161 | GNUNET_assert(dc->completed <= dc->length); |
1154 | dr->state = BRS_DOWNLOAD_DOWN; | 1162 | dr->state = BRS_DOWNLOAD_DOWN; |
1155 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; | 1163 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; |
1156 | pi.value.download.specifics.progress.data = pt; | 1164 | pi.value.download.specifics.progress.data = pt; |
@@ -1163,112 +1171,120 @@ process_result_with_request (void *cls, | |||
1163 | if (prc->last_transmission.abs_value_us != | 1171 | if (prc->last_transmission.abs_value_us != |
1164 | GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | 1172 | GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) |
1165 | pi.value.download.specifics.progress.block_download_duration = | 1173 | pi.value.download.specifics.progress.block_download_duration = |
1166 | GNUNET_TIME_absolute_get_duration (prc->last_transmission); | 1174 | GNUNET_TIME_absolute_get_duration(prc->last_transmission); |
1167 | else | 1175 | else |
1168 | pi.value.download.specifics.progress.block_download_duration = | 1176 | pi.value.download.specifics.progress.block_download_duration = |
1169 | GNUNET_TIME_UNIT_ZERO; /* found locally */ | 1177 | GNUNET_TIME_UNIT_ZERO; /* found locally */ |
1170 | GNUNET_FS_download_make_status_ (&pi, dc); | 1178 | GNUNET_FS_download_make_status_(&pi, dc); |
1171 | if (0 == dr->depth) | 1179 | if (0 == dr->depth) |
1172 | propagate_up (dr); | 1180 | propagate_up(dr); |
1173 | 1181 | ||
1174 | if (dc->completed == dc->length) | 1182 | if (dc->completed == dc->length) |
1175 | { | 1183 | { |
1176 | /* download completed, signal */ | 1184 | /* download completed, signal */ |
1177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1185 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1178 | "Download completed, truncating file to desired length %llu\n", | 1186 | "Download completed, truncating file to desired length %llu\n", |
1179 | (unsigned long long) GNUNET_ntohll ( | 1187 | (unsigned long long)GNUNET_ntohll( |
1180 | dc->uri->data.chk.file_length)); | 1188 | dc->uri->data.chk.file_length)); |
1181 | /* truncate file to size (since we store IBlocks at the end) */ | 1189 | /* truncate file to size (since we store IBlocks at the end) */ |
1182 | if (NULL != dc->filename) | 1190 | if (NULL != dc->filename) |
1183 | { | 1191 | { |
1184 | if (0 != truncate (dc->filename, | 1192 | if (0 != truncate(dc->filename, |
1185 | GNUNET_ntohll (dc->uri->data.chk.file_length))) | 1193 | GNUNET_ntohll(dc->uri->data.chk.file_length))) |
1186 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 1194 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, |
1187 | "truncate", | 1195 | "truncate", |
1188 | dc->filename); | 1196 | dc->filename); |
1189 | } | 1197 | } |
1190 | GNUNET_assert (0 == dr->depth); | 1198 | GNUNET_assert(0 == dr->depth); |
1191 | check_completed (dc); | 1199 | check_completed(dc); |
1192 | } | 1200 | } |
1193 | if (0 == dr->depth) | 1201 | if (0 == dr->depth) |
1194 | { | 1202 | { |
1195 | /* bottom of the tree, no child downloads possible, just sync */ | 1203 | /* bottom of the tree, no child downloads possible, just sync */ |
1196 | GNUNET_FS_download_sync_ (dc); | 1204 | GNUNET_FS_download_sync_(dc); |
1197 | return GNUNET_YES; | 1205 | return GNUNET_YES; |
1198 | } | 1206 | } |
1199 | 1207 | ||
1200 | GNUNET_log ( | 1208 | GNUNET_log( |
1201 | GNUNET_ERROR_TYPE_DEBUG, | 1209 | GNUNET_ERROR_TYPE_DEBUG, |
1202 | "Triggering downloads of children (this block was at depth %u and offset %llu)\n", | 1210 | "Triggering downloads of children (this block was at depth %u and offset %llu)\n", |
1203 | dr->depth, | 1211 | dr->depth, |
1204 | (unsigned long long) dr->offset); | 1212 | (unsigned long long)dr->offset); |
1205 | GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey))); | 1213 | GNUNET_assert(0 == (prc->size % sizeof(struct ContentHashKey))); |
1206 | chkarr = (struct ContentHashKey *) pt; | 1214 | chkarr = (struct ContentHashKey *)pt; |
1207 | for (i = dr->num_children - 1; i >= 0; i--) | 1215 | for (i = dr->num_children - 1; i >= 0; i--) |
1208 | { | ||
1209 | drc = dr->children[i]; | ||
1210 | switch (drc->state) | ||
1211 | { | 1216 | { |
1212 | case BRS_INIT: | 1217 | drc = dr->children[i]; |
1213 | if ((drc->chk_idx + 1) * sizeof (struct ContentHashKey) > prc->size) | 1218 | switch (drc->state) |
1214 | { | 1219 | { |
1215 | /* 'chkarr' does not have enough space for this chk_idx; | 1220 | case BRS_INIT: |
1216 | internal error! */ | 1221 | if ((drc->chk_idx + 1) * sizeof(struct ContentHashKey) > prc->size) |
1217 | GNUNET_break (0); | 1222 | { |
1218 | GNUNET_assert (0); | 1223 | /* 'chkarr' does not have enough space for this chk_idx; |
1219 | dc->emsg = GNUNET_strdup (_ ("internal error decoding tree")); | 1224 | internal error! */ |
1220 | goto signal_error; | 1225 | GNUNET_break(0); |
1221 | } | 1226 | GNUNET_assert(0); |
1222 | drc->chk = chkarr[drc->chk_idx]; | 1227 | dc->emsg = GNUNET_strdup(_("internal error decoding tree")); |
1223 | drc->state = BRS_CHK_SET; | 1228 | goto signal_error; |
1224 | if (GNUNET_YES == dc->issue_requests) | 1229 | } |
1225 | schedule_block_download (dc, drc); | 1230 | drc->chk = chkarr[drc->chk_idx]; |
1226 | break; | 1231 | drc->state = BRS_CHK_SET; |
1227 | case BRS_RECONSTRUCT_DOWN: | 1232 | if (GNUNET_YES == dc->issue_requests) |
1228 | GNUNET_assert (0); | 1233 | schedule_block_download(dc, drc); |
1229 | break; | 1234 | break; |
1230 | case BRS_RECONSTRUCT_META_UP: | 1235 | |
1231 | GNUNET_assert (0); | 1236 | case BRS_RECONSTRUCT_DOWN: |
1232 | break; | 1237 | GNUNET_assert(0); |
1233 | case BRS_RECONSTRUCT_UP: | 1238 | break; |
1234 | GNUNET_assert (0); | 1239 | |
1235 | break; | 1240 | case BRS_RECONSTRUCT_META_UP: |
1236 | case BRS_CHK_SET: | 1241 | GNUNET_assert(0); |
1237 | GNUNET_assert (0); | 1242 | break; |
1238 | break; | 1243 | |
1239 | case BRS_DOWNLOAD_DOWN: | 1244 | case BRS_RECONSTRUCT_UP: |
1240 | GNUNET_assert (0); | 1245 | GNUNET_assert(0); |
1241 | break; | 1246 | break; |
1242 | case BRS_DOWNLOAD_UP: | 1247 | |
1243 | GNUNET_assert (0); | 1248 | case BRS_CHK_SET: |
1244 | break; | 1249 | GNUNET_assert(0); |
1245 | case BRS_ERROR: | 1250 | break; |
1246 | GNUNET_assert (0); | 1251 | |
1247 | break; | 1252 | case BRS_DOWNLOAD_DOWN: |
1248 | default: | 1253 | GNUNET_assert(0); |
1249 | GNUNET_assert (0); | 1254 | break; |
1250 | break; | 1255 | |
1256 | case BRS_DOWNLOAD_UP: | ||
1257 | GNUNET_assert(0); | ||
1258 | break; | ||
1259 | |||
1260 | case BRS_ERROR: | ||
1261 | GNUNET_assert(0); | ||
1262 | break; | ||
1263 | |||
1264 | default: | ||
1265 | GNUNET_assert(0); | ||
1266 | break; | ||
1267 | } | ||
1251 | } | 1268 | } |
1252 | } | 1269 | GNUNET_FS_download_sync_(dc); |
1253 | GNUNET_FS_download_sync_ (dc); | ||
1254 | return GNUNET_YES; | 1270 | return GNUNET_YES; |
1255 | 1271 | ||
1256 | signal_error: | 1272 | signal_error: |
1257 | if (NULL != fh) | 1273 | if (NULL != fh) |
1258 | GNUNET_DISK_file_close (fh); | 1274 | GNUNET_DISK_file_close(fh); |
1259 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; | 1275 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; |
1260 | pi.value.download.specifics.error.message = dc->emsg; | 1276 | pi.value.download.specifics.error.message = dc->emsg; |
1261 | GNUNET_FS_download_make_status_ (&pi, dc); | 1277 | GNUNET_FS_download_make_status_(&pi, dc); |
1262 | GNUNET_MQ_destroy (dc->mq); | 1278 | GNUNET_MQ_destroy(dc->mq); |
1263 | dc->mq = NULL; | 1279 | dc->mq = NULL; |
1264 | GNUNET_FS_free_download_request_ (dc->top_request); | 1280 | GNUNET_FS_free_download_request_(dc->top_request); |
1265 | dc->top_request = NULL; | 1281 | dc->top_request = NULL; |
1266 | if (NULL != dc->job_queue) | 1282 | if (NULL != dc->job_queue) |
1267 | { | 1283 | { |
1268 | GNUNET_FS_dequeue_ (dc->job_queue); | 1284 | GNUNET_FS_dequeue_(dc->job_queue); |
1269 | dc->job_queue = NULL; | 1285 | dc->job_queue = NULL; |
1270 | } | 1286 | } |
1271 | GNUNET_FS_download_sync_ (dc); | 1287 | GNUNET_FS_download_sync_(dc); |
1272 | return GNUNET_NO; | 1288 | return GNUNET_NO; |
1273 | } | 1289 | } |
1274 | 1290 | ||
@@ -1281,7 +1297,7 @@ signal_error: | |||
1281 | * @param msg message received | 1297 | * @param msg message received |
1282 | */ | 1298 | */ |
1283 | static int | 1299 | static int |
1284 | check_put (void *cls, const struct ClientPutMessage *cm) | 1300 | check_put(void *cls, const struct ClientPutMessage *cm) |
1285 | { | 1301 | { |
1286 | /* any varsize length is OK */ | 1302 | /* any varsize length is OK */ |
1287 | return GNUNET_OK; | 1303 | return GNUNET_OK; |
@@ -1296,28 +1312,28 @@ check_put (void *cls, const struct ClientPutMessage *cm) | |||
1296 | * @param msg message received | 1312 | * @param msg message received |
1297 | */ | 1313 | */ |
1298 | static void | 1314 | static void |
1299 | handle_put (void *cls, const struct ClientPutMessage *cm) | 1315 | handle_put(void *cls, const struct ClientPutMessage *cm) |
1300 | { | 1316 | { |
1301 | struct GNUNET_FS_DownloadContext *dc = cls; | 1317 | struct GNUNET_FS_DownloadContext *dc = cls; |
1302 | uint16_t msize = ntohs (cm->header.size) - sizeof (*cm); | 1318 | uint16_t msize = ntohs(cm->header.size) - sizeof(*cm); |
1303 | struct ProcessResultClosure prc; | 1319 | struct ProcessResultClosure prc; |
1304 | 1320 | ||
1305 | prc.dc = dc; | 1321 | prc.dc = dc; |
1306 | prc.data = &cm[1]; | 1322 | prc.data = &cm[1]; |
1307 | prc.last_transmission = GNUNET_TIME_absolute_ntoh (cm->last_transmission); | 1323 | prc.last_transmission = GNUNET_TIME_absolute_ntoh(cm->last_transmission); |
1308 | prc.size = msize; | 1324 | prc.size = msize; |
1309 | prc.type = ntohl (cm->type); | 1325 | prc.type = ntohl(cm->type); |
1310 | prc.do_store = GNUNET_YES; | 1326 | prc.do_store = GNUNET_YES; |
1311 | prc.respect_offered = ntohl (cm->respect_offered); | 1327 | prc.respect_offered = ntohl(cm->respect_offered); |
1312 | prc.num_transmissions = ntohl (cm->num_transmissions); | 1328 | prc.num_transmissions = ntohl(cm->num_transmissions); |
1313 | GNUNET_CRYPTO_hash (prc.data, msize, &prc.query); | 1329 | GNUNET_CRYPTO_hash(prc.data, msize, &prc.query); |
1314 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1330 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1315 | "Received result for query `%s' from FS service\n", | 1331 | "Received result for query `%s' from FS service\n", |
1316 | GNUNET_h2s (&prc.query)); | 1332 | GNUNET_h2s(&prc.query)); |
1317 | GNUNET_CONTAINER_multihashmap_get_multiple (dc->active, | 1333 | GNUNET_CONTAINER_multihashmap_get_multiple(dc->active, |
1318 | &prc.query, | 1334 | &prc.query, |
1319 | &process_result_with_request, | 1335 | &process_result_with_request, |
1320 | &prc); | 1336 | &prc); |
1321 | } | 1337 | } |
1322 | 1338 | ||
1323 | 1339 | ||
@@ -1330,18 +1346,18 @@ handle_put (void *cls, const struct ClientPutMessage *cm) | |||
1330 | * @param error error code | 1346 | * @param error error code |
1331 | */ | 1347 | */ |
1332 | static void | 1348 | static void |
1333 | download_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 1349 | download_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
1334 | { | 1350 | { |
1335 | struct GNUNET_FS_DownloadContext *dc = cls; | 1351 | struct GNUNET_FS_DownloadContext *dc = cls; |
1336 | 1352 | ||
1337 | if (NULL != dc->mq) | 1353 | if (NULL != dc->mq) |
1338 | { | 1354 | { |
1339 | GNUNET_MQ_destroy (dc->mq); | 1355 | GNUNET_MQ_destroy(dc->mq); |
1340 | dc->mq = NULL; | 1356 | dc->mq = NULL; |
1341 | } | 1357 | } |
1342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1358 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1343 | "Transmitting download request failed, trying to reconnect\n"); | 1359 | "Transmitting download request failed, trying to reconnect\n"); |
1344 | try_reconnect (dc); | 1360 | try_reconnect(dc); |
1345 | } | 1361 | } |
1346 | 1362 | ||
1347 | 1363 | ||
@@ -1351,31 +1367,31 @@ download_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
1351 | * @param cls our download context | 1367 | * @param cls our download context |
1352 | */ | 1368 | */ |
1353 | static void | 1369 | static void |
1354 | do_reconnect (void *cls) | 1370 | do_reconnect(void *cls) |
1355 | { | 1371 | { |
1356 | struct GNUNET_FS_DownloadContext *dc = cls; | 1372 | struct GNUNET_FS_DownloadContext *dc = cls; |
1357 | struct GNUNET_MQ_MessageHandler handlers[] = | 1373 | struct GNUNET_MQ_MessageHandler handlers[] = |
1358 | {GNUNET_MQ_hd_var_size (put, | 1374 | { GNUNET_MQ_hd_var_size(put, |
1359 | GNUNET_MESSAGE_TYPE_FS_PUT, | 1375 | GNUNET_MESSAGE_TYPE_FS_PUT, |
1360 | struct ClientPutMessage, | 1376 | struct ClientPutMessage, |
1361 | dc), | 1377 | dc), |
1362 | GNUNET_MQ_handler_end ()}; | 1378 | GNUNET_MQ_handler_end() }; |
1363 | 1379 | ||
1364 | dc->task = NULL; | 1380 | dc->task = NULL; |
1365 | dc->mq = GNUNET_CLIENT_connect (dc->h->cfg, | 1381 | dc->mq = GNUNET_CLIENT_connect(dc->h->cfg, |
1366 | "fs", | 1382 | "fs", |
1367 | handlers, | 1383 | handlers, |
1368 | &download_mq_error_handler, | 1384 | &download_mq_error_handler, |
1369 | dc); | 1385 | dc); |
1370 | if (NULL == dc->mq) | 1386 | if (NULL == dc->mq) |
1371 | { | 1387 | { |
1372 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1388 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1373 | "Connecting to `%s'-service failed, will try again.\n", | 1389 | "Connecting to `%s'-service failed, will try again.\n", |
1374 | "FS"); | 1390 | "FS"); |
1375 | try_reconnect (dc); | 1391 | try_reconnect(dc); |
1376 | return; | 1392 | return; |
1377 | } | 1393 | } |
1378 | GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc); | 1394 | GNUNET_CONTAINER_multihashmap_iterate(dc->active, &retry_entry, dc); |
1379 | } | 1395 | } |
1380 | 1396 | ||
1381 | 1397 | ||
@@ -1387,27 +1403,27 @@ do_reconnect (void *cls) | |||
1387 | * @param dc download context that is having trouble | 1403 | * @param dc download context that is having trouble |
1388 | */ | 1404 | */ |
1389 | static void | 1405 | static void |
1390 | try_reconnect (struct GNUNET_FS_DownloadContext *dc) | 1406 | try_reconnect(struct GNUNET_FS_DownloadContext *dc) |
1391 | { | 1407 | { |
1392 | if (NULL != dc->mq) | 1408 | if (NULL != dc->mq) |
1393 | { | 1409 | { |
1394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1410 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1395 | "Moving all requests back to pending list\n"); | 1411 | "Moving all requests back to pending list\n"); |
1396 | GNUNET_MQ_destroy (dc->mq); | 1412 | GNUNET_MQ_destroy(dc->mq); |
1397 | dc->mq = NULL; | 1413 | dc->mq = NULL; |
1398 | } | 1414 | } |
1399 | if (0 == dc->reconnect_backoff.rel_value_us) | 1415 | if (0 == dc->reconnect_backoff.rel_value_us) |
1400 | dc->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 1416 | dc->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
1401 | else | 1417 | else |
1402 | dc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (dc->reconnect_backoff); | 1418 | dc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF(dc->reconnect_backoff); |
1403 | 1419 | ||
1404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1420 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1405 | "Will try to reconnect in %s\n", | 1421 | "Will try to reconnect in %s\n", |
1406 | GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff, | 1422 | GNUNET_STRINGS_relative_time_to_string(dc->reconnect_backoff, |
1407 | GNUNET_YES)); | 1423 | GNUNET_YES)); |
1408 | GNUNET_break (NULL != dc->job_queue); | 1424 | GNUNET_break(NULL != dc->job_queue); |
1409 | dc->task = | 1425 | dc->task = |
1410 | GNUNET_SCHEDULER_add_delayed (dc->reconnect_backoff, &do_reconnect, dc); | 1426 | GNUNET_SCHEDULER_add_delayed(dc->reconnect_backoff, &do_reconnect, dc); |
1411 | } | 1427 | } |
1412 | 1428 | ||
1413 | 1429 | ||
@@ -1418,18 +1434,18 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc) | |||
1418 | * @param mq handle to use for communcation with FS (we must destroy it!) | 1434 | * @param mq handle to use for communcation with FS (we must destroy it!) |
1419 | */ | 1435 | */ |
1420 | static void | 1436 | static void |
1421 | activate_fs_download (void *cls) | 1437 | activate_fs_download(void *cls) |
1422 | { | 1438 | { |
1423 | struct GNUNET_FS_DownloadContext *dc = cls; | 1439 | struct GNUNET_FS_DownloadContext *dc = cls; |
1424 | struct GNUNET_FS_ProgressInfo pi; | 1440 | struct GNUNET_FS_ProgressInfo pi; |
1425 | 1441 | ||
1426 | GNUNET_assert (NULL == dc->mq); | 1442 | GNUNET_assert(NULL == dc->mq); |
1427 | GNUNET_assert (NULL != dc->active); | 1443 | GNUNET_assert(NULL != dc->active); |
1428 | do_reconnect (dc); | 1444 | do_reconnect(dc); |
1429 | if (NULL != dc->mq) | 1445 | if (NULL != dc->mq) |
1430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n"); | 1446 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download activated\n"); |
1431 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; | 1447 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; |
1432 | GNUNET_FS_download_make_status_ (&pi, dc); | 1448 | GNUNET_FS_download_make_status_(&pi, dc); |
1433 | } | 1449 | } |
1434 | 1450 | ||
1435 | 1451 | ||
@@ -1439,19 +1455,19 @@ activate_fs_download (void *cls) | |||
1439 | * @param cls the `struct GNUNET_FS_DownloadContext` | 1455 | * @param cls the `struct GNUNET_FS_DownloadContext` |
1440 | */ | 1456 | */ |
1441 | static void | 1457 | static void |
1442 | deactivate_fs_download (void *cls) | 1458 | deactivate_fs_download(void *cls) |
1443 | { | 1459 | { |
1444 | struct GNUNET_FS_DownloadContext *dc = cls; | 1460 | struct GNUNET_FS_DownloadContext *dc = cls; |
1445 | struct GNUNET_FS_ProgressInfo pi; | 1461 | struct GNUNET_FS_ProgressInfo pi; |
1446 | 1462 | ||
1447 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n"); | 1463 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n"); |
1448 | if (NULL != dc->mq) | 1464 | if (NULL != dc->mq) |
1449 | { | 1465 | { |
1450 | GNUNET_MQ_destroy (dc->mq); | 1466 | GNUNET_MQ_destroy(dc->mq); |
1451 | dc->mq = NULL; | 1467 | dc->mq = NULL; |
1452 | } | 1468 | } |
1453 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE; | 1469 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE; |
1454 | GNUNET_FS_download_make_status_ (&pi, dc); | 1470 | GNUNET_FS_download_make_status_(&pi, dc); |
1455 | } | 1471 | } |
1456 | 1472 | ||
1457 | 1473 | ||
@@ -1475,38 +1491,38 @@ deactivate_fs_download (void *cls) | |||
1475 | * the specified depth | 1491 | * the specified depth |
1476 | */ | 1492 | */ |
1477 | static struct DownloadRequest * | 1493 | static struct DownloadRequest * |
1478 | create_download_request (struct DownloadRequest *parent, | 1494 | create_download_request(struct DownloadRequest *parent, |
1479 | unsigned int chk_idx, | 1495 | unsigned int chk_idx, |
1480 | unsigned int depth, | 1496 | unsigned int depth, |
1481 | uint64_t dr_offset, | 1497 | uint64_t dr_offset, |
1482 | uint64_t file_start_offset, | 1498 | uint64_t file_start_offset, |
1483 | uint64_t desired_length) | 1499 | uint64_t desired_length) |
1484 | { | 1500 | { |
1485 | struct DownloadRequest *dr; | 1501 | struct DownloadRequest *dr; |
1486 | unsigned int i; | 1502 | unsigned int i; |
1487 | unsigned int head_skip; | 1503 | unsigned int head_skip; |
1488 | uint64_t child_block_size; | 1504 | uint64_t child_block_size; |
1489 | 1505 | ||
1490 | dr = GNUNET_new (struct DownloadRequest); | 1506 | dr = GNUNET_new(struct DownloadRequest); |
1491 | dr->parent = parent; | 1507 | dr->parent = parent; |
1492 | dr->depth = depth; | 1508 | dr->depth = depth; |
1493 | dr->offset = dr_offset; | 1509 | dr->offset = dr_offset; |
1494 | dr->chk_idx = chk_idx; | 1510 | dr->chk_idx = chk_idx; |
1495 | if (0 == depth) | 1511 | if (0 == depth) |
1496 | return dr; | 1512 | return dr; |
1497 | child_block_size = GNUNET_FS_tree_compute_tree_size (depth - 1); | 1513 | child_block_size = GNUNET_FS_tree_compute_tree_size(depth - 1); |
1498 | 1514 | ||
1499 | /* calculate how many blocks at this level are not interesting | 1515 | /* calculate how many blocks at this level are not interesting |
1500 | * from the start (rounded down), either because of the requested | 1516 | * from the start (rounded down), either because of the requested |
1501 | * file offset or because this IBlock is further along */ | 1517 | * file offset or because this IBlock is further along */ |
1502 | if (dr_offset < file_start_offset) | 1518 | if (dr_offset < file_start_offset) |
1503 | { | 1519 | { |
1504 | head_skip = (file_start_offset - dr_offset) / child_block_size; | 1520 | head_skip = (file_start_offset - dr_offset) / child_block_size; |
1505 | } | 1521 | } |
1506 | else | 1522 | else |
1507 | { | 1523 | { |
1508 | head_skip = 0; | 1524 | head_skip = 0; |
1509 | } | 1525 | } |
1510 | 1526 | ||
1511 | /* calculate index of last block at this level that is interesting (rounded up) */ | 1527 | /* calculate index of last block at this level that is interesting (rounded up) */ |
1512 | dr->num_children = | 1528 | dr->num_children = |
@@ -1514,32 +1530,32 @@ create_download_request (struct DownloadRequest *parent, | |||
1514 | if (dr->num_children * child_block_size < | 1530 | if (dr->num_children * child_block_size < |
1515 | file_start_offset + desired_length - dr_offset) | 1531 | file_start_offset + desired_length - dr_offset) |
1516 | dr->num_children++; /* round up */ | 1532 | dr->num_children++; /* round up */ |
1517 | GNUNET_assert (dr->num_children > head_skip); | 1533 | GNUNET_assert(dr->num_children > head_skip); |
1518 | dr->num_children -= head_skip; | 1534 | dr->num_children -= head_skip; |
1519 | if (dr->num_children > CHK_PER_INODE) | 1535 | if (dr->num_children > CHK_PER_INODE) |
1520 | dr->num_children = CHK_PER_INODE; /* cap at max */ | 1536 | dr->num_children = CHK_PER_INODE; /* cap at max */ |
1521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1537 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1522 | "Block at offset %llu and depth %u has %u children\n", | 1538 | "Block at offset %llu and depth %u has %u children\n", |
1523 | (unsigned long long) dr_offset, | 1539 | (unsigned long long)dr_offset, |
1524 | depth, | 1540 | depth, |
1525 | dr->num_children); | 1541 | dr->num_children); |
1526 | 1542 | ||
1527 | /* now we can get the total number of *interesting* children for this block */ | 1543 | /* now we can get the total number of *interesting* children for this block */ |
1528 | 1544 | ||
1529 | /* why else would we have gotten here to begin with? (that'd be a bad logic error) */ | 1545 | /* why else would we have gotten here to begin with? (that'd be a bad logic error) */ |
1530 | GNUNET_assert (dr->num_children > 0); | 1546 | GNUNET_assert(dr->num_children > 0); |
1531 | 1547 | ||
1532 | dr->children = GNUNET_new_array (dr->num_children, struct DownloadRequest *); | 1548 | dr->children = GNUNET_new_array(dr->num_children, struct DownloadRequest *); |
1533 | for (i = 0; i < dr->num_children; i++) | 1549 | for (i = 0; i < dr->num_children; i++) |
1534 | { | 1550 | { |
1535 | dr->children[i] = | 1551 | dr->children[i] = |
1536 | create_download_request (dr, | 1552 | create_download_request(dr, |
1537 | i + head_skip, | 1553 | i + head_skip, |
1538 | depth - 1, | 1554 | depth - 1, |
1539 | dr_offset + (i + head_skip) * child_block_size, | 1555 | dr_offset + (i + head_skip) * child_block_size, |
1540 | file_start_offset, | 1556 | file_start_offset, |
1541 | desired_length); | 1557 | desired_length); |
1542 | } | 1558 | } |
1543 | return dr; | 1559 | return dr; |
1544 | } | 1560 | } |
1545 | 1561 | ||
@@ -1551,25 +1567,25 @@ create_download_request (struct DownloadRequest *parent, | |||
1551 | * @param cls the 'struct ReconstructContext' | 1567 | * @param cls the 'struct ReconstructContext' |
1552 | */ | 1568 | */ |
1553 | static void | 1569 | static void |
1554 | reconstruct_cont (void *cls) | 1570 | reconstruct_cont(void *cls) |
1555 | { | 1571 | { |
1556 | struct GNUNET_FS_DownloadContext *dc = cls; | 1572 | struct GNUNET_FS_DownloadContext *dc = cls; |
1557 | 1573 | ||
1558 | /* clean up state from tree encoder */ | 1574 | /* clean up state from tree encoder */ |
1559 | if (NULL != dc->task) | 1575 | if (NULL != dc->task) |
1560 | { | 1576 | { |
1561 | GNUNET_SCHEDULER_cancel (dc->task); | 1577 | GNUNET_SCHEDULER_cancel(dc->task); |
1562 | dc->task = NULL; | 1578 | dc->task = NULL; |
1563 | } | 1579 | } |
1564 | if (NULL != dc->rfh) | 1580 | if (NULL != dc->rfh) |
1565 | { | 1581 | { |
1566 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh)); | 1582 | GNUNET_break(GNUNET_OK == GNUNET_DISK_file_close(dc->rfh)); |
1567 | dc->rfh = NULL; | 1583 | dc->rfh = NULL; |
1568 | } | 1584 | } |
1569 | /* start "normal" download */ | 1585 | /* start "normal" download */ |
1570 | dc->issue_requests = GNUNET_YES; | 1586 | dc->issue_requests = GNUNET_YES; |
1571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting normal download\n"); | 1587 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting normal download\n"); |
1572 | schedule_block_download (dc, dc->top_request); | 1588 | schedule_block_download(dc, dc->top_request); |
1573 | } | 1589 | } |
1574 | 1590 | ||
1575 | 1591 | ||
@@ -1579,12 +1595,12 @@ reconstruct_cont (void *cls) | |||
1579 | * @param cls the 'struct GNUJNET_FS_DownloadContext' we're processing | 1595 | * @param cls the 'struct GNUJNET_FS_DownloadContext' we're processing |
1580 | */ | 1596 | */ |
1581 | static void | 1597 | static void |
1582 | get_next_block (void *cls) | 1598 | get_next_block(void *cls) |
1583 | { | 1599 | { |
1584 | struct GNUNET_FS_DownloadContext *dc = cls; | 1600 | struct GNUNET_FS_DownloadContext *dc = cls; |
1585 | 1601 | ||
1586 | dc->task = NULL; | 1602 | dc->task = NULL; |
1587 | GNUNET_FS_tree_encoder_next (dc->te); | 1603 | GNUNET_FS_tree_encoder_next(dc->te); |
1588 | } | 1604 | } |
1589 | 1605 | ||
1590 | 1606 | ||
@@ -1606,13 +1622,13 @@ get_next_block (void *cls) | |||
1606 | * @param block_size size of block (in bytes) | 1622 | * @param block_size size of block (in bytes) |
1607 | */ | 1623 | */ |
1608 | static void | 1624 | static void |
1609 | reconstruct_cb (void *cls, | 1625 | reconstruct_cb(void *cls, |
1610 | const struct ContentHashKey *chk, | 1626 | const struct ContentHashKey *chk, |
1611 | uint64_t offset, | 1627 | uint64_t offset, |
1612 | unsigned int depth, | 1628 | unsigned int depth, |
1613 | enum GNUNET_BLOCK_Type type, | 1629 | enum GNUNET_BLOCK_Type type, |
1614 | const void *block, | 1630 | const void *block, |
1615 | uint16_t block_size) | 1631 | uint16_t block_size) |
1616 | { | 1632 | { |
1617 | struct GNUNET_FS_DownloadContext *dc = cls; | 1633 | struct GNUNET_FS_DownloadContext *dc = cls; |
1618 | struct GNUNET_FS_ProgressInfo pi; | 1634 | struct GNUNET_FS_ProgressInfo pi; |
@@ -1623,117 +1639,125 @@ reconstruct_cb (void *cls, | |||
1623 | /* find corresponding request entry */ | 1639 | /* find corresponding request entry */ |
1624 | dr = dc->top_request; | 1640 | dr = dc->top_request; |
1625 | while (dr->depth > depth) | 1641 | while (dr->depth > depth) |
1626 | { | 1642 | { |
1627 | GNUNET_assert (dr->num_children > 0); | 1643 | GNUNET_assert(dr->num_children > 0); |
1628 | blen = GNUNET_FS_tree_compute_tree_size (dr->depth - 1); | 1644 | blen = GNUNET_FS_tree_compute_tree_size(dr->depth - 1); |
1629 | chld = (offset - dr->offset) / blen; | 1645 | chld = (offset - dr->offset) / blen; |
1630 | if (chld < dr->children[0]->chk_idx) | 1646 | if (chld < dr->children[0]->chk_idx) |
1631 | { | 1647 | { |
1632 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1648 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1633 | "Block %u < %u irrelevant for our range\n", | 1649 | "Block %u < %u irrelevant for our range\n", |
1634 | chld, | 1650 | chld, |
1635 | dr->children[0]->chk_idx); | 1651 | dr->children[0]->chk_idx); |
1636 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); | 1652 | dc->task = GNUNET_SCHEDULER_add_now(&get_next_block, dc); |
1637 | return; /* irrelevant block */ | 1653 | return; /* irrelevant block */ |
1638 | } | 1654 | } |
1639 | if (chld > dr->children[dr->num_children - 1]->chk_idx) | 1655 | if (chld > dr->children[dr->num_children - 1]->chk_idx) |
1640 | { | 1656 | { |
1641 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1657 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1642 | "Block %u > %u irrelevant for our range\n", | 1658 | "Block %u > %u irrelevant for our range\n", |
1643 | chld, | 1659 | chld, |
1644 | dr->children[dr->num_children - 1]->chk_idx); | 1660 | dr->children[dr->num_children - 1]->chk_idx); |
1645 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); | 1661 | dc->task = GNUNET_SCHEDULER_add_now(&get_next_block, dc); |
1646 | return; /* irrelevant block */ | 1662 | return; /* irrelevant block */ |
1647 | } | 1663 | } |
1648 | dr = dr->children[chld - dr->children[0]->chk_idx]; | 1664 | dr = dr->children[chld - dr->children[0]->chk_idx]; |
1649 | } | 1665 | } |
1650 | GNUNET_log ( | 1666 | GNUNET_log( |
1651 | GNUNET_ERROR_TYPE_DEBUG, | 1667 | GNUNET_ERROR_TYPE_DEBUG, |
1652 | "Matched TE block with request at offset %llu and depth %u in state %d\n", | 1668 | "Matched TE block with request at offset %llu and depth %u in state %d\n", |
1653 | (unsigned long long) dr->offset, | 1669 | (unsigned long long)dr->offset, |
1654 | dr->depth, | 1670 | dr->depth, |
1655 | dr->state); | 1671 | dr->state); |
1656 | /* FIXME: this code needs more testing and might | 1672 | /* FIXME: this code needs more testing and might |
1657 | need to handle more states... */ | 1673 | need to handle more states... */ |
1658 | switch (dr->state) | 1674 | switch (dr->state) |
1659 | { | 1675 | { |
1660 | case BRS_INIT: | 1676 | case BRS_INIT: |
1661 | break; | 1677 | break; |
1662 | case BRS_RECONSTRUCT_DOWN: | 1678 | |
1663 | break; | 1679 | case BRS_RECONSTRUCT_DOWN: |
1664 | case BRS_RECONSTRUCT_META_UP: | 1680 | break; |
1665 | break; | 1681 | |
1666 | case BRS_RECONSTRUCT_UP: | 1682 | case BRS_RECONSTRUCT_META_UP: |
1667 | break; | 1683 | break; |
1668 | case BRS_CHK_SET: | 1684 | |
1669 | if (0 == memcmp (chk, &dr->chk, sizeof (struct ContentHashKey))) | 1685 | case BRS_RECONSTRUCT_UP: |
1670 | { | 1686 | break; |
1671 | GNUNET_log ( | 1687 | |
1672 | GNUNET_ERROR_TYPE_DEBUG, | 1688 | case BRS_CHK_SET: |
1673 | "Reconstruction succeeded, can use block at offset %llu, depth %u\n", | 1689 | if (0 == memcmp(chk, &dr->chk, sizeof(struct ContentHashKey))) |
1674 | (unsigned long long) offset, | ||
1675 | depth); | ||
1676 | /* block matches, hence tree below matches; | ||
1677 | * this request is done! */ | ||
1678 | dr->state = BRS_DOWNLOAD_UP; | ||
1679 | (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, | ||
1680 | &dr->chk.query, | ||
1681 | dr); | ||
1682 | /* calculate how many bytes of payload this block | ||
1683 | * corresponds to */ | ||
1684 | blen = GNUNET_FS_tree_compute_tree_size (dr->depth); | ||
1685 | /* how many of those bytes are in the requested range? */ | ||
1686 | blen = GNUNET_MIN (blen, dc->length + dc->offset - dr->offset); | ||
1687 | /* signal progress */ | ||
1688 | dc->completed += blen; | ||
1689 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; | ||
1690 | pi.value.download.specifics.progress.data = NULL; | ||
1691 | pi.value.download.specifics.progress.offset = offset; | ||
1692 | pi.value.download.specifics.progress.data_len = 0; | ||
1693 | pi.value.download.specifics.progress.depth = 0; | ||
1694 | pi.value.download.specifics.progress.respect_offered = 0; | ||
1695 | pi.value.download.specifics.progress.block_download_duration = | ||
1696 | GNUNET_TIME_UNIT_ZERO; | ||
1697 | GNUNET_FS_download_make_status_ (&pi, dc); | ||
1698 | /* FIXME: duplicated code from 'process_result_with_request - refactor */ | ||
1699 | if (dc->completed == dc->length) | ||
1700 | { | ||
1701 | /* download completed, signal */ | ||
1702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1703 | "Download completed, truncating file to desired length %llu\n", | ||
1704 | (unsigned long long) GNUNET_ntohll ( | ||
1705 | dc->uri->data.chk.file_length)); | ||
1706 | /* truncate file to size (since we store IBlocks at the end) */ | ||
1707 | if (NULL != dc->filename) | ||
1708 | { | 1690 | { |
1709 | if (0 != truncate (dc->filename, | 1691 | GNUNET_log( |
1710 | GNUNET_ntohll (dc->uri->data.chk.file_length))) | 1692 | GNUNET_ERROR_TYPE_DEBUG, |
1711 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 1693 | "Reconstruction succeeded, can use block at offset %llu, depth %u\n", |
1712 | "truncate", | 1694 | (unsigned long long)offset, |
1713 | dc->filename); | 1695 | depth); |
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 | } | ||
1714 | } | 1736 | } |
1715 | } | 1737 | else |
1738 | GNUNET_log( | ||
1739 | GNUNET_ERROR_TYPE_DEBUG, | ||
1740 | "Reconstruction failed, need to download block at offset %llu, depth %u\n", | ||
1741 | (unsigned long long)offset, | ||
1742 | depth); | ||
1743 | break; | ||
1744 | |||
1745 | case BRS_DOWNLOAD_DOWN: | ||
1746 | break; | ||
1747 | |||
1748 | case BRS_DOWNLOAD_UP: | ||
1749 | break; | ||
1750 | |||
1751 | case BRS_ERROR: | ||
1752 | break; | ||
1753 | |||
1754 | default: | ||
1755 | GNUNET_assert(0); | ||
1756 | break; | ||
1716 | } | 1757 | } |
1717 | else | 1758 | dc->task = GNUNET_SCHEDULER_add_now(&get_next_block, dc); |
1718 | GNUNET_log ( | ||
1719 | GNUNET_ERROR_TYPE_DEBUG, | ||
1720 | "Reconstruction failed, need to download block at offset %llu, depth %u\n", | ||
1721 | (unsigned long long) offset, | ||
1722 | depth); | ||
1723 | break; | ||
1724 | case BRS_DOWNLOAD_DOWN: | ||
1725 | break; | ||
1726 | case BRS_DOWNLOAD_UP: | ||
1727 | break; | ||
1728 | case BRS_ERROR: | ||
1729 | break; | ||
1730 | default: | ||
1731 | GNUNET_assert (0); | ||
1732 | break; | ||
1733 | } | ||
1734 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); | ||
1735 | if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP)) | 1759 | if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP)) |
1736 | check_completed (dc); | 1760 | check_completed(dc); |
1737 | } | 1761 | } |
1738 | 1762 | ||
1739 | 1763 | ||
@@ -1750,7 +1774,7 @@ reconstruct_cb (void *cls, | |||
1750 | * @return number of bytes copied to buf, 0 on error | 1774 | * @return number of bytes copied to buf, 0 on error |
1751 | */ | 1775 | */ |
1752 | static size_t | 1776 | static size_t |
1753 | fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) | 1777 | fh_reader(void *cls, uint64_t offset, size_t max, void *buf, char **emsg) |
1754 | { | 1778 | { |
1755 | struct GNUNET_FS_DownloadContext *dc = cls; | 1779 | struct GNUNET_FS_DownloadContext *dc = cls; |
1756 | struct GNUNET_DISK_FileHandle *fh = dc->rfh; | 1780 | struct GNUNET_DISK_FileHandle *fh = dc->rfh; |
@@ -1758,19 +1782,19 @@ fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) | |||
1758 | 1782 | ||
1759 | if (NULL != emsg) | 1783 | if (NULL != emsg) |
1760 | *emsg = NULL; | 1784 | *emsg = NULL; |
1761 | if (offset != GNUNET_DISK_file_seek (fh, offset, GNUNET_DISK_SEEK_SET)) | 1785 | if (offset != GNUNET_DISK_file_seek(fh, offset, GNUNET_DISK_SEEK_SET)) |
1762 | { | 1786 | { |
1763 | if (NULL != emsg) | 1787 | if (NULL != emsg) |
1764 | *emsg = GNUNET_strdup (strerror (errno)); | 1788 | *emsg = GNUNET_strdup(strerror(errno)); |
1765 | return 0; | 1789 | return 0; |
1766 | } | 1790 | } |
1767 | ret = GNUNET_DISK_file_read (fh, buf, max); | 1791 | ret = GNUNET_DISK_file_read(fh, buf, max); |
1768 | if (ret < 0) | 1792 | if (ret < 0) |
1769 | { | 1793 | { |
1770 | if (NULL != emsg) | 1794 | if (NULL != emsg) |
1771 | *emsg = GNUNET_strdup (strerror (errno)); | 1795 | *emsg = GNUNET_strdup(strerror(errno)); |
1772 | return 0; | 1796 | return 0; |
1773 | } | 1797 | } |
1774 | return ret; | 1798 | return ret; |
1775 | } | 1799 | } |
1776 | 1800 | ||
@@ -1782,151 +1806,155 @@ fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) | |||
1782 | * @param cls the 'struct GNUNET_FS_DownloadContext' | 1806 | * @param cls the 'struct GNUNET_FS_DownloadContext' |
1783 | */ | 1807 | */ |
1784 | void | 1808 | void |
1785 | GNUNET_FS_download_start_task_ (void *cls) | 1809 | GNUNET_FS_download_start_task_(void *cls) |
1786 | { | 1810 | { |
1787 | struct GNUNET_FS_DownloadContext *dc = cls; | 1811 | struct GNUNET_FS_DownloadContext *dc = cls; |
1788 | struct GNUNET_FS_ProgressInfo pi; | 1812 | struct GNUNET_FS_ProgressInfo pi; |
1789 | struct GNUNET_DISK_FileHandle *fh; | 1813 | struct GNUNET_DISK_FileHandle *fh; |
1790 | 1814 | ||
1791 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n"); | 1815 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n"); |
1792 | dc->task = NULL; | 1816 | dc->task = NULL; |
1793 | if (0 == dc->length) | 1817 | if (0 == dc->length) |
1794 | { | 1818 | { |
1795 | /* no bytes required! */ | 1819 | /* no bytes required! */ |
1796 | if (NULL != dc->filename) | 1820 | if (NULL != dc->filename) |
1797 | { | 1821 | { |
1798 | fh = GNUNET_DISK_file_open (dc->filename, | 1822 | fh = GNUNET_DISK_file_open(dc->filename, |
1799 | GNUNET_DISK_OPEN_READWRITE | | 1823 | GNUNET_DISK_OPEN_READWRITE | |
1800 | GNUNET_DISK_OPEN_CREATE | | 1824 | GNUNET_DISK_OPEN_CREATE | |
1801 | ((0 == | 1825 | ((0 == |
1802 | GNUNET_FS_uri_chk_get_file_size (dc->uri)) | 1826 | GNUNET_FS_uri_chk_get_file_size(dc->uri)) |
1803 | ? GNUNET_DISK_OPEN_TRUNCATE | 1827 | ? GNUNET_DISK_OPEN_TRUNCATE |
1804 | : 0), | 1828 | : 0), |
1805 | GNUNET_DISK_PERM_USER_READ | | 1829 | GNUNET_DISK_PERM_USER_READ | |
1806 | GNUNET_DISK_PERM_USER_WRITE | | 1830 | GNUNET_DISK_PERM_USER_WRITE | |
1807 | GNUNET_DISK_PERM_GROUP_READ | | 1831 | GNUNET_DISK_PERM_GROUP_READ | |
1808 | GNUNET_DISK_PERM_OTHER_READ); | 1832 | GNUNET_DISK_PERM_OTHER_READ); |
1809 | GNUNET_DISK_file_close (fh); | 1833 | GNUNET_DISK_file_close(fh); |
1810 | } | 1834 | } |
1811 | GNUNET_FS_download_sync_ (dc); | 1835 | GNUNET_FS_download_sync_(dc); |
1812 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; | 1836 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; |
1813 | pi.value.download.specifics.start.meta = dc->meta; | 1837 | pi.value.download.specifics.start.meta = dc->meta; |
1814 | GNUNET_FS_download_make_status_ (&pi, dc); | 1838 | GNUNET_FS_download_make_status_(&pi, dc); |
1815 | check_completed (dc); | 1839 | check_completed(dc); |
1816 | return; | 1840 | return; |
1817 | } | 1841 | } |
1818 | if (NULL != dc->emsg) | 1842 | if (NULL != dc->emsg) |
1819 | return; | 1843 | return; |
1820 | if (NULL == dc->top_request) | 1844 | if (NULL == dc->top_request) |
1821 | { | 1845 | { |
1822 | dc->top_request = create_download_request (NULL, | 1846 | dc->top_request = create_download_request(NULL, |
1823 | 0, | 1847 | 0, |
1824 | dc->treedepth - 1, | 1848 | dc->treedepth - 1, |
1825 | 0, | 1849 | 0, |
1826 | dc->offset, | 1850 | dc->offset, |
1827 | dc->length); | 1851 | dc->length); |
1828 | dc->top_request->state = BRS_CHK_SET; | 1852 | dc->top_request->state = BRS_CHK_SET; |
1829 | dc->top_request->chk = (dc->uri->type == GNUNET_FS_URI_CHK) | 1853 | dc->top_request->chk = (dc->uri->type == GNUNET_FS_URI_CHK) |
1830 | ? dc->uri->data.chk.chk | 1854 | ? dc->uri->data.chk.chk |
1831 | : dc->uri->data.loc.fi.chk; | 1855 | : dc->uri->data.loc.fi.chk; |
1832 | /* signal start */ | 1856 | /* signal start */ |
1833 | GNUNET_FS_download_sync_ (dc); | 1857 | GNUNET_FS_download_sync_(dc); |
1834 | if (NULL != dc->search) | 1858 | if (NULL != dc->search) |
1835 | GNUNET_FS_search_result_sync_ (dc->search); | 1859 | GNUNET_FS_search_result_sync_(dc->search); |
1836 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; | 1860 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; |
1837 | pi.value.download.specifics.start.meta = dc->meta; | 1861 | pi.value.download.specifics.start.meta = dc->meta; |
1838 | GNUNET_FS_download_make_status_ (&pi, dc); | 1862 | GNUNET_FS_download_make_status_(&pi, dc); |
1839 | } | 1863 | } |
1840 | GNUNET_FS_download_start_downloading_ (dc); | 1864 | GNUNET_FS_download_start_downloading_(dc); |
1841 | /* attempt reconstruction from disk */ | 1865 | /* attempt reconstruction from disk */ |
1842 | if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename)) | 1866 | if (GNUNET_YES == GNUNET_DISK_file_test(dc->filename)) |
1843 | dc->rfh = GNUNET_DISK_file_open (dc->filename, | 1867 | dc->rfh = GNUNET_DISK_file_open(dc->filename, |
1844 | GNUNET_DISK_OPEN_READ, | 1868 | GNUNET_DISK_OPEN_READ, |
1845 | GNUNET_DISK_PERM_NONE); | 1869 | GNUNET_DISK_PERM_NONE); |
1846 | if (dc->top_request->state == BRS_CHK_SET) | 1870 | if (dc->top_request->state == BRS_CHK_SET) |
1847 | { | 1871 | { |
1848 | if (NULL != dc->rfh) | 1872 | if (NULL != dc->rfh) |
1849 | { | ||
1850 | /* first, try top-down */ | ||
1851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1852 | "Trying top-down reconstruction for `%s'\n", | ||
1853 | dc->filename); | ||
1854 | try_top_down_reconstruction (dc, dc->top_request); | ||
1855 | switch (dc->top_request->state) | ||
1856 | { | ||
1857 | case BRS_CHK_SET: | ||
1858 | break; /* normal */ | ||
1859 | case BRS_DOWNLOAD_DOWN: | ||
1860 | break; /* normal, some blocks already down */ | ||
1861 | case BRS_DOWNLOAD_UP: | ||
1862 | /* already done entirely, party! */ | ||
1863 | if (NULL != dc->rfh) | ||
1864 | { | 1873 | { |
1865 | /* avoid hanging on to file handle longer than | 1874 | /* first, try top-down */ |
1866 | * necessary */ | 1875 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1867 | GNUNET_DISK_file_close (dc->rfh); | 1876 | "Trying top-down reconstruction for `%s'\n", |
1868 | dc->rfh = NULL; | 1877 | dc->filename); |
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 | } | ||
1869 | } | 1910 | } |
1870 | return; | ||
1871 | case BRS_ERROR: | ||
1872 | GNUNET_asprintf (&dc->emsg, _ ("Invalid URI")); | ||
1873 | GNUNET_FS_download_sync_ (dc); | ||
1874 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; | ||
1875 | pi.value.download.specifics.error.message = dc->emsg; | ||
1876 | GNUNET_FS_download_make_status_ (&pi, dc); | ||
1877 | return; | ||
1878 | default: | ||
1879 | GNUNET_assert (0); | ||
1880 | break; | ||
1881 | } | ||
1882 | } | 1911 | } |
1883 | } | ||
1884 | /* attempt reconstruction from meta data */ | 1912 | /* attempt reconstruction from meta data */ |
1885 | if ((GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) && | 1913 | if ((GNUNET_FS_uri_chk_get_file_size(dc->uri) <= MAX_INLINE_SIZE) && |
1886 | (NULL != dc->meta)) | 1914 | (NULL != dc->meta)) |
1887 | { | ||
1888 | GNUNET_log ( | ||
1889 | GNUNET_ERROR_TYPE_DEBUG, | ||
1890 | "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", | ||
1891 | (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri), | ||
1892 | (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta)); | ||
1893 | GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc); | ||
1894 | if (BRS_DOWNLOAD_UP == dc->top_request->state) | ||
1895 | { | 1915 | { |
1896 | if (NULL != dc->rfh) | 1916 | GNUNET_log( |
1897 | { | 1917 | GNUNET_ERROR_TYPE_DEBUG, |
1898 | /* avoid hanging on to file handle longer than | 1918 | "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", |
1899 | * necessary */ | 1919 | (unsigned long long)GNUNET_FS_uri_chk_get_file_size(dc->uri), |
1900 | GNUNET_DISK_file_close (dc->rfh); | 1920 | (unsigned int)GNUNET_CONTAINER_meta_data_get_serialized_size(dc->meta)); |
1901 | dc->rfh = NULL; | 1921 | GNUNET_CONTAINER_meta_data_iterate(dc->meta, &match_full_data, dc); |
1902 | } | 1922 | if (BRS_DOWNLOAD_UP == dc->top_request->state) |
1903 | return; /* finished, status update was already done for us */ | 1923 | { |
1904 | } | 1924 | if (NULL != dc->rfh) |
1905 | } | 1925 | { |
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 | } | ||
1906 | if (NULL != dc->rfh) | 1934 | if (NULL != dc->rfh) |
1907 | { | 1935 | { |
1908 | /* finally, actually run bottom-up */ | 1936 | /* finally, actually run bottom-up */ |
1909 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1937 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1910 | "Trying bottom-up reconstruction of file `%s'\n", | 1938 | "Trying bottom-up reconstruction of file `%s'\n", |
1911 | dc->filename); | 1939 | dc->filename); |
1912 | dc->te = | 1940 | dc->te = |
1913 | GNUNET_FS_tree_encoder_create (dc->h, | 1941 | GNUNET_FS_tree_encoder_create(dc->h, |
1914 | GNUNET_FS_uri_chk_get_file_size (dc->uri), | 1942 | GNUNET_FS_uri_chk_get_file_size(dc->uri), |
1915 | dc, | 1943 | dc, |
1916 | &fh_reader, | 1944 | &fh_reader, |
1917 | &reconstruct_cb, | 1945 | &reconstruct_cb, |
1918 | NULL, | 1946 | NULL, |
1919 | &reconstruct_cont); | 1947 | &reconstruct_cont); |
1920 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); | 1948 | dc->task = GNUNET_SCHEDULER_add_now(&get_next_block, dc); |
1921 | } | 1949 | } |
1922 | else | 1950 | else |
1923 | { | 1951 | { |
1924 | /* simple, top-level download */ | 1952 | /* simple, top-level download */ |
1925 | dc->issue_requests = GNUNET_YES; | 1953 | dc->issue_requests = GNUNET_YES; |
1926 | schedule_block_download (dc, dc->top_request); | 1954 | schedule_block_download(dc, dc->top_request); |
1927 | } | 1955 | } |
1928 | if (BRS_DOWNLOAD_UP == dc->top_request->state) | 1956 | if (BRS_DOWNLOAD_UP == dc->top_request->state) |
1929 | check_completed (dc); | 1957 | check_completed(dc); |
1930 | } | 1958 | } |
1931 | 1959 | ||
1932 | 1960 | ||
@@ -1937,59 +1965,59 @@ GNUNET_FS_download_start_task_ (void *cls) | |||
1937 | * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for | 1965 | * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for |
1938 | */ | 1966 | */ |
1939 | void | 1967 | void |
1940 | GNUNET_FS_download_signal_suspend_ (void *cls) | 1968 | GNUNET_FS_download_signal_suspend_(void *cls) |
1941 | { | 1969 | { |
1942 | struct GNUNET_FS_DownloadContext *dc = cls; | 1970 | struct GNUNET_FS_DownloadContext *dc = cls; |
1943 | struct GNUNET_FS_ProgressInfo pi; | 1971 | struct GNUNET_FS_ProgressInfo pi; |
1944 | 1972 | ||
1945 | if (NULL != dc->top) | 1973 | if (NULL != dc->top) |
1946 | GNUNET_FS_end_top (dc->h, dc->top); | 1974 | GNUNET_FS_end_top(dc->h, dc->top); |
1947 | while (NULL != dc->child_head) | 1975 | while (NULL != dc->child_head) |
1948 | GNUNET_FS_download_signal_suspend_ (dc->child_head); | 1976 | GNUNET_FS_download_signal_suspend_(dc->child_head); |
1949 | if (NULL != dc->search) | 1977 | if (NULL != dc->search) |
1950 | { | 1978 | { |
1951 | dc->search->download = NULL; | 1979 | dc->search->download = NULL; |
1952 | dc->search = NULL; | 1980 | dc->search = NULL; |
1953 | } | 1981 | } |
1954 | if (NULL != dc->job_queue) | 1982 | if (NULL != dc->job_queue) |
1955 | { | 1983 | { |
1956 | GNUNET_FS_dequeue_ (dc->job_queue); | 1984 | GNUNET_FS_dequeue_(dc->job_queue); |
1957 | dc->job_queue = NULL; | 1985 | dc->job_queue = NULL; |
1958 | } | 1986 | } |
1959 | if (NULL != dc->parent) | 1987 | if (NULL != dc->parent) |
1960 | GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, | 1988 | GNUNET_CONTAINER_DLL_remove(dc->parent->child_head, |
1961 | dc->parent->child_tail, | 1989 | dc->parent->child_tail, |
1962 | dc); | 1990 | dc); |
1963 | if (NULL != dc->task) | 1991 | if (NULL != dc->task) |
1964 | { | 1992 | { |
1965 | GNUNET_SCHEDULER_cancel (dc->task); | 1993 | GNUNET_SCHEDULER_cancel(dc->task); |
1966 | dc->task = NULL; | 1994 | dc->task = NULL; |
1967 | } | 1995 | } |
1968 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND; | 1996 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND; |
1969 | GNUNET_FS_download_make_status_ (&pi, dc); | 1997 | GNUNET_FS_download_make_status_(&pi, dc); |
1970 | if (NULL != dc->te) | 1998 | if (NULL != dc->te) |
1971 | { | 1999 | { |
1972 | GNUNET_FS_tree_encoder_finish (dc->te, NULL); | 2000 | GNUNET_FS_tree_encoder_finish(dc->te, NULL); |
1973 | dc->te = NULL; | 2001 | dc->te = NULL; |
1974 | } | 2002 | } |
1975 | if (NULL != dc->rfh) | 2003 | if (NULL != dc->rfh) |
1976 | { | 2004 | { |
1977 | GNUNET_DISK_file_close (dc->rfh); | 2005 | GNUNET_DISK_file_close(dc->rfh); |
1978 | dc->rfh = NULL; | 2006 | dc->rfh = NULL; |
1979 | } | 2007 | } |
1980 | GNUNET_FS_free_download_request_ (dc->top_request); | 2008 | GNUNET_FS_free_download_request_(dc->top_request); |
1981 | if (NULL != dc->active) | 2009 | if (NULL != dc->active) |
1982 | { | 2010 | { |
1983 | GNUNET_CONTAINER_multihashmap_destroy (dc->active); | 2011 | GNUNET_CONTAINER_multihashmap_destroy(dc->active); |
1984 | dc->active = NULL; | 2012 | dc->active = NULL; |
1985 | } | 2013 | } |
1986 | GNUNET_free_non_null (dc->filename); | 2014 | GNUNET_free_non_null(dc->filename); |
1987 | GNUNET_CONTAINER_meta_data_destroy (dc->meta); | 2015 | GNUNET_CONTAINER_meta_data_destroy(dc->meta); |
1988 | GNUNET_FS_uri_destroy (dc->uri); | 2016 | GNUNET_FS_uri_destroy(dc->uri); |
1989 | GNUNET_free_non_null (dc->temp_filename); | 2017 | GNUNET_free_non_null(dc->temp_filename); |
1990 | GNUNET_free_non_null (dc->serialization); | 2018 | GNUNET_free_non_null(dc->serialization); |
1991 | GNUNET_assert (NULL == dc->job_queue); | 2019 | GNUNET_assert(NULL == dc->job_queue); |
1992 | GNUNET_free (dc); | 2020 | GNUNET_free(dc); |
1993 | } | 2021 | } |
1994 | 2022 | ||
1995 | 2023 | ||
@@ -2013,72 +2041,72 @@ GNUNET_FS_download_signal_suspend_ (void *cls) | |||
2013 | * @return context that can be used to control this download | 2041 | * @return context that can be used to control this download |
2014 | */ | 2042 | */ |
2015 | struct GNUNET_FS_DownloadContext * | 2043 | struct GNUNET_FS_DownloadContext * |
2016 | create_download_context (struct GNUNET_FS_Handle *h, | 2044 | create_download_context(struct GNUNET_FS_Handle *h, |
2017 | const struct GNUNET_FS_Uri *uri, | 2045 | const struct GNUNET_FS_Uri *uri, |
2018 | const struct GNUNET_CONTAINER_MetaData *meta, | 2046 | const struct GNUNET_CONTAINER_MetaData *meta, |
2019 | const char *filename, | 2047 | const char *filename, |
2020 | const char *tempname, | 2048 | const char *tempname, |
2021 | uint64_t offset, | 2049 | uint64_t offset, |
2022 | uint64_t length, | 2050 | uint64_t length, |
2023 | uint32_t anonymity, | 2051 | uint32_t anonymity, |
2024 | enum GNUNET_FS_DownloadOptions options, | 2052 | enum GNUNET_FS_DownloadOptions options, |
2025 | void *cctx) | 2053 | void *cctx) |
2026 | { | 2054 | { |
2027 | struct GNUNET_FS_DownloadContext *dc; | 2055 | struct GNUNET_FS_DownloadContext *dc; |
2028 | 2056 | ||
2029 | GNUNET_assert (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)); | 2057 | GNUNET_assert(GNUNET_FS_uri_test_chk(uri) || GNUNET_FS_uri_test_loc(uri)); |
2030 | if ((offset + length < offset) || | 2058 | if ((offset + length < offset) || |
2031 | (offset + length > GNUNET_FS_uri_chk_get_file_size (uri))) | 2059 | (offset + length > GNUNET_FS_uri_chk_get_file_size(uri))) |
2032 | { | 2060 | { |
2033 | GNUNET_break (0); | 2061 | GNUNET_break(0); |
2034 | return NULL; | 2062 | return NULL; |
2035 | } | 2063 | } |
2036 | dc = GNUNET_new (struct GNUNET_FS_DownloadContext); | 2064 | dc = GNUNET_new(struct GNUNET_FS_DownloadContext); |
2037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2065 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2038 | "Starting download %p, %u bytes at offset %llu\n", | 2066 | "Starting download %p, %u bytes at offset %llu\n", |
2039 | dc, | 2067 | dc, |
2040 | (unsigned int) length, | 2068 | (unsigned int)length, |
2041 | (unsigned long long) offset); | 2069 | (unsigned long long)offset); |
2042 | dc->h = h; | 2070 | dc->h = h; |
2043 | dc->uri = GNUNET_FS_uri_dup (uri); | 2071 | dc->uri = GNUNET_FS_uri_dup(uri); |
2044 | dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 2072 | dc->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); |
2045 | dc->client_info = cctx; | 2073 | dc->client_info = cctx; |
2046 | dc->start_time = GNUNET_TIME_absolute_get (); | 2074 | dc->start_time = GNUNET_TIME_absolute_get(); |
2047 | if (NULL != filename) | 2075 | if (NULL != filename) |
2048 | { | 2076 | { |
2049 | dc->filename = GNUNET_strdup (filename); | 2077 | dc->filename = GNUNET_strdup(filename); |
2050 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | 2078 | if (GNUNET_YES == GNUNET_DISK_file_test(filename)) |
2051 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (filename, | 2079 | GNUNET_break(GNUNET_OK == GNUNET_DISK_file_size(filename, |
2052 | &dc->old_file_size, | 2080 | &dc->old_file_size, |
2053 | GNUNET_YES, | 2081 | GNUNET_YES, |
2054 | GNUNET_YES)); | 2082 | GNUNET_YES)); |
2055 | } | 2083 | } |
2056 | if (GNUNET_FS_uri_test_loc (dc->uri)) | 2084 | if (GNUNET_FS_uri_test_loc(dc->uri)) |
2057 | GNUNET_assert (GNUNET_OK == | 2085 | GNUNET_assert(GNUNET_OK == |
2058 | GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target)); | 2086 | GNUNET_FS_uri_loc_get_peer_identity(dc->uri, &dc->target)); |
2059 | dc->offset = offset; | 2087 | dc->offset = offset; |
2060 | dc->length = length; | 2088 | dc->length = length; |
2061 | dc->anonymity = anonymity; | 2089 | dc->anonymity = anonymity; |
2062 | dc->options = options; | 2090 | dc->options = options; |
2063 | dc->active = | 2091 | dc->active = |
2064 | GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE), | 2092 | GNUNET_CONTAINER_multihashmap_create(1 + 2 * (length / DBLOCK_SIZE), |
2065 | GNUNET_NO); | 2093 | GNUNET_NO); |
2066 | dc->treedepth = | 2094 | dc->treedepth = |
2067 | GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); | 2095 | GNUNET_FS_compute_depth(GNUNET_FS_uri_chk_get_file_size(dc->uri)); |
2068 | if ((NULL == filename) && (is_recursive_download (dc))) | 2096 | if ((NULL == filename) && (is_recursive_download(dc))) |
2069 | { | 2097 | { |
2070 | if (NULL != tempname) | 2098 | if (NULL != tempname) |
2071 | dc->temp_filename = GNUNET_strdup (tempname); | 2099 | dc->temp_filename = GNUNET_strdup(tempname); |
2072 | else | 2100 | else |
2073 | dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp"); | 2101 | dc->temp_filename = GNUNET_DISK_mktemp("gnunet-directory-download-tmp"); |
2074 | } | 2102 | } |
2075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2103 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2076 | "Starting download `%s' of %llu bytes with tree depth %u\n", | 2104 | "Starting download `%s' of %llu bytes with tree depth %u\n", |
2077 | filename, | 2105 | filename, |
2078 | (unsigned long long) length, | 2106 | (unsigned long long)length, |
2079 | dc->treedepth); | 2107 | dc->treedepth); |
2080 | GNUNET_assert (NULL == dc->job_queue); | 2108 | GNUNET_assert(NULL == dc->job_queue); |
2081 | dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); | 2109 | dc->task = GNUNET_SCHEDULER_add_now(&GNUNET_FS_download_start_task_, dc); |
2082 | return dc; | 2110 | return dc; |
2083 | } | 2111 | } |
2084 | 2112 | ||
@@ -2114,38 +2142,38 @@ create_download_context (struct GNUNET_FS_Handle *h, | |||
2114 | * @return context that can be used to control this download | 2142 | * @return context that can be used to control this download |
2115 | */ | 2143 | */ |
2116 | struct GNUNET_FS_DownloadContext * | 2144 | struct GNUNET_FS_DownloadContext * |
2117 | GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, | 2145 | GNUNET_FS_download_start(struct GNUNET_FS_Handle *h, |
2118 | const struct GNUNET_FS_Uri *uri, | 2146 | const struct GNUNET_FS_Uri *uri, |
2119 | const struct GNUNET_CONTAINER_MetaData *meta, | 2147 | const struct GNUNET_CONTAINER_MetaData *meta, |
2120 | const char *filename, | 2148 | const char *filename, |
2121 | const char *tempname, | 2149 | const char *tempname, |
2122 | uint64_t offset, | 2150 | uint64_t offset, |
2123 | uint64_t length, | 2151 | uint64_t length, |
2124 | uint32_t anonymity, | 2152 | uint32_t anonymity, |
2125 | enum GNUNET_FS_DownloadOptions options, | 2153 | enum GNUNET_FS_DownloadOptions options, |
2126 | void *cctx, | 2154 | void *cctx, |
2127 | struct GNUNET_FS_DownloadContext *parent) | 2155 | struct GNUNET_FS_DownloadContext *parent) |
2128 | { | 2156 | { |
2129 | struct GNUNET_FS_DownloadContext *dc; | 2157 | struct GNUNET_FS_DownloadContext *dc; |
2130 | 2158 | ||
2131 | dc = create_download_context (h, | 2159 | dc = create_download_context(h, |
2132 | uri, | 2160 | uri, |
2133 | meta, | 2161 | meta, |
2134 | filename, | 2162 | filename, |
2135 | tempname, | 2163 | tempname, |
2136 | offset, | 2164 | offset, |
2137 | length, | 2165 | length, |
2138 | anonymity, | 2166 | anonymity, |
2139 | options, | 2167 | options, |
2140 | cctx); | 2168 | cctx); |
2141 | if (NULL == dc) | 2169 | if (NULL == dc) |
2142 | return NULL; | 2170 | return NULL; |
2143 | dc->parent = parent; | 2171 | dc->parent = parent; |
2144 | if (NULL != parent) | 2172 | if (NULL != parent) |
2145 | GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); | 2173 | GNUNET_CONTAINER_DLL_insert(parent->child_head, parent->child_tail, dc); |
2146 | else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options)) | 2174 | else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options)) |
2147 | dc->top = | 2175 | dc->top = |
2148 | GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); | 2176 | GNUNET_FS_make_top(dc->h, &GNUNET_FS_download_signal_suspend_, dc); |
2149 | return dc; | 2177 | return dc; |
2150 | } | 2178 | } |
2151 | 2179 | ||
@@ -2185,43 +2213,43 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, | |||
2185 | * @return context that can be used to control this download | 2213 | * @return context that can be used to control this download |
2186 | */ | 2214 | */ |
2187 | struct GNUNET_FS_DownloadContext * | 2215 | struct GNUNET_FS_DownloadContext * |
2188 | GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, | 2216 | GNUNET_FS_download_start_from_search(struct GNUNET_FS_Handle *h, |
2189 | struct GNUNET_FS_SearchResult *sr, | 2217 | struct GNUNET_FS_SearchResult *sr, |
2190 | const char *filename, | 2218 | const char *filename, |
2191 | const char *tempname, | 2219 | const char *tempname, |
2192 | uint64_t offset, | 2220 | uint64_t offset, |
2193 | uint64_t length, | 2221 | uint64_t length, |
2194 | uint32_t anonymity, | 2222 | uint32_t anonymity, |
2195 | enum GNUNET_FS_DownloadOptions options, | 2223 | enum GNUNET_FS_DownloadOptions options, |
2196 | void *cctx) | 2224 | void *cctx) |
2197 | { | 2225 | { |
2198 | struct GNUNET_FS_DownloadContext *dc; | 2226 | struct GNUNET_FS_DownloadContext *dc; |
2199 | 2227 | ||
2200 | if ((NULL == sr) || (NULL != sr->download)) | 2228 | if ((NULL == sr) || (NULL != sr->download)) |
2201 | { | 2229 | { |
2202 | GNUNET_break (0); | 2230 | GNUNET_break(0); |
2203 | return NULL; | 2231 | return NULL; |
2204 | } | 2232 | } |
2205 | dc = create_download_context (h, | 2233 | dc = create_download_context(h, |
2206 | sr->uri, | 2234 | sr->uri, |
2207 | sr->meta, | 2235 | sr->meta, |
2208 | filename, | 2236 | filename, |
2209 | tempname, | 2237 | tempname, |
2210 | offset, | 2238 | offset, |
2211 | length, | 2239 | length, |
2212 | anonymity, | 2240 | anonymity, |
2213 | options, | 2241 | options, |
2214 | cctx); | 2242 | cctx); |
2215 | if (NULL == dc) | 2243 | if (NULL == dc) |
2216 | return NULL; | 2244 | return NULL; |
2217 | dc->search = sr; | 2245 | dc->search = sr; |
2218 | sr->download = dc; | 2246 | sr->download = dc; |
2219 | if (NULL != sr->probe_ctx) | 2247 | if (NULL != sr->probe_ctx) |
2220 | { | 2248 | { |
2221 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); | 2249 | GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); |
2222 | sr->probe_ctx = NULL; | 2250 | sr->probe_ctx = NULL; |
2223 | GNUNET_FS_stop_probe_ping_task_ (sr); | 2251 | GNUNET_FS_stop_probe_ping_task_(sr); |
2224 | } | 2252 | } |
2225 | return dc; | 2253 | return dc; |
2226 | } | 2254 | } |
2227 | 2255 | ||
@@ -2232,28 +2260,28 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, | |||
2232 | * @param dc our download context | 2260 | * @param dc our download context |
2233 | */ | 2261 | */ |
2234 | void | 2262 | void |
2235 | GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc) | 2263 | GNUNET_FS_download_start_downloading_(struct GNUNET_FS_DownloadContext *dc) |
2236 | { | 2264 | { |
2237 | if (dc->completed == dc->length) | 2265 | if (dc->completed == dc->length) |
2238 | return; | 2266 | return; |
2239 | if (NULL != dc->mq) | 2267 | if (NULL != dc->mq) |
2240 | return; /* already running */ | 2268 | return; /* already running */ |
2241 | GNUNET_assert (NULL == dc->job_queue); | 2269 | GNUNET_assert(NULL == dc->job_queue); |
2242 | GNUNET_assert (NULL == dc->task); | 2270 | GNUNET_assert(NULL == dc->task); |
2243 | GNUNET_assert (NULL != dc->active); | 2271 | GNUNET_assert(NULL != dc->active); |
2244 | dc->job_queue = | 2272 | dc->job_queue = |
2245 | GNUNET_FS_queue_ (dc->h, | 2273 | GNUNET_FS_queue_(dc->h, |
2246 | &activate_fs_download, | 2274 | &activate_fs_download, |
2247 | &deactivate_fs_download, | 2275 | &deactivate_fs_download, |
2248 | dc, | 2276 | dc, |
2249 | (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, | 2277 | (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, |
2250 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) | 2278 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) |
2251 | ? GNUNET_FS_QUEUE_PRIORITY_NORMAL | 2279 | ? GNUNET_FS_QUEUE_PRIORITY_NORMAL |
2252 | : GNUNET_FS_QUEUE_PRIORITY_PROBE); | 2280 | : GNUNET_FS_QUEUE_PRIORITY_PROBE); |
2253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2281 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2254 | "Download %p put into queue as job %p\n", | 2282 | "Download %p put into queue as job %p\n", |
2255 | dc, | 2283 | dc, |
2256 | dc->job_queue); | 2284 | dc->job_queue); |
2257 | } | 2285 | } |
2258 | 2286 | ||
2259 | /** | 2287 | /** |
@@ -2262,9 +2290,9 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc) | |||
2262 | * @param dc handle for the download | 2290 | * @param dc handle for the download |
2263 | */ | 2291 | */ |
2264 | void | 2292 | void |
2265 | GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc) | 2293 | GNUNET_FS_download_suspend(struct GNUNET_FS_DownloadContext *dc) |
2266 | { | 2294 | { |
2267 | deactivate_fs_download (dc); | 2295 | deactivate_fs_download(dc); |
2268 | } | 2296 | } |
2269 | 2297 | ||
2270 | 2298 | ||
@@ -2274,23 +2302,23 @@ GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc) | |||
2274 | * @param dc handle for the download | 2302 | * @param dc handle for the download |
2275 | */ | 2303 | */ |
2276 | void | 2304 | void |
2277 | GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc) | 2305 | GNUNET_FS_download_resume(struct GNUNET_FS_DownloadContext *dc) |
2278 | { | 2306 | { |
2279 | struct GNUNET_FS_ProgressInfo pi; | 2307 | struct GNUNET_FS_ProgressInfo pi; |
2280 | 2308 | ||
2281 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; | 2309 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; |
2282 | GNUNET_FS_download_make_status_ (&pi, dc); | 2310 | GNUNET_FS_download_make_status_(&pi, dc); |
2283 | 2311 | ||
2284 | GNUNET_assert (NULL == dc->task); | 2312 | GNUNET_assert(NULL == dc->task); |
2285 | dc->job_queue = | 2313 | dc->job_queue = |
2286 | GNUNET_FS_queue_ (dc->h, | 2314 | GNUNET_FS_queue_(dc->h, |
2287 | &activate_fs_download, | 2315 | &activate_fs_download, |
2288 | &deactivate_fs_download, | 2316 | &deactivate_fs_download, |
2289 | dc, | 2317 | dc, |
2290 | (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, | 2318 | (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, |
2291 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) | 2319 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) |
2292 | ? GNUNET_FS_QUEUE_PRIORITY_NORMAL | 2320 | ? GNUNET_FS_QUEUE_PRIORITY_NORMAL |
2293 | : GNUNET_FS_QUEUE_PRIORITY_PROBE); | 2321 | : GNUNET_FS_QUEUE_PRIORITY_PROBE); |
2294 | } | 2322 | } |
2295 | 2323 | ||
2296 | 2324 | ||
@@ -2301,88 +2329,88 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc) | |||
2301 | * @param do_delete delete files of incomplete downloads | 2329 | * @param do_delete delete files of incomplete downloads |
2302 | */ | 2330 | */ |
2303 | void | 2331 | void |
2304 | GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete) | 2332 | GNUNET_FS_download_stop(struct GNUNET_FS_DownloadContext *dc, int do_delete) |
2305 | { | 2333 | { |
2306 | struct GNUNET_FS_ProgressInfo pi; | 2334 | struct GNUNET_FS_ProgressInfo pi; |
2307 | int have_children; | 2335 | int have_children; |
2308 | int search_was_null; | 2336 | int search_was_null; |
2309 | 2337 | ||
2310 | if (NULL != dc->top) | 2338 | if (NULL != dc->top) |
2311 | GNUNET_FS_end_top (dc->h, dc->top); | 2339 | GNUNET_FS_end_top(dc->h, dc->top); |
2312 | if (NULL != dc->task) | 2340 | if (NULL != dc->task) |
2313 | { | 2341 | { |
2314 | GNUNET_SCHEDULER_cancel (dc->task); | 2342 | GNUNET_SCHEDULER_cancel(dc->task); |
2315 | dc->task = NULL; | 2343 | dc->task = NULL; |
2316 | } | 2344 | } |
2317 | search_was_null = (NULL == dc->search); | 2345 | search_was_null = (NULL == dc->search); |
2318 | if (NULL != dc->search) | 2346 | if (NULL != dc->search) |
2319 | { | 2347 | { |
2320 | dc->search->download = NULL; | 2348 | dc->search->download = NULL; |
2321 | GNUNET_FS_search_result_sync_ (dc->search); | 2349 | GNUNET_FS_search_result_sync_(dc->search); |
2322 | dc->search = NULL; | 2350 | dc->search = NULL; |
2323 | } | 2351 | } |
2324 | if (NULL != dc->job_queue) | 2352 | if (NULL != dc->job_queue) |
2325 | { | 2353 | { |
2326 | GNUNET_FS_dequeue_ (dc->job_queue); | 2354 | GNUNET_FS_dequeue_(dc->job_queue); |
2327 | dc->job_queue = NULL; | 2355 | dc->job_queue = NULL; |
2328 | } | 2356 | } |
2329 | if (NULL != dc->te) | 2357 | if (NULL != dc->te) |
2330 | { | 2358 | { |
2331 | GNUNET_FS_tree_encoder_finish (dc->te, NULL); | 2359 | GNUNET_FS_tree_encoder_finish(dc->te, NULL); |
2332 | dc->te = NULL; | 2360 | dc->te = NULL; |
2333 | } | 2361 | } |
2334 | have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO; | 2362 | have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO; |
2335 | while (NULL != dc->child_head) | 2363 | while (NULL != dc->child_head) |
2336 | GNUNET_FS_download_stop (dc->child_head, do_delete); | 2364 | GNUNET_FS_download_stop(dc->child_head, do_delete); |
2337 | if (NULL != dc->parent) | 2365 | if (NULL != dc->parent) |
2338 | GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, | 2366 | GNUNET_CONTAINER_DLL_remove(dc->parent->child_head, |
2339 | dc->parent->child_tail, | 2367 | dc->parent->child_tail, |
2340 | dc); | 2368 | dc); |
2341 | if (NULL != dc->serialization) | 2369 | if (NULL != dc->serialization) |
2342 | GNUNET_FS_remove_sync_file_ (dc->h, | 2370 | GNUNET_FS_remove_sync_file_(dc->h, |
2343 | ((NULL != dc->parent) || (! search_was_null)) | 2371 | ((NULL != dc->parent) || (!search_was_null)) |
2344 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD | 2372 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD |
2345 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 2373 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
2346 | dc->serialization); | ||
2347 | if ((GNUNET_YES == have_children) && (NULL == dc->parent)) | ||
2348 | GNUNET_FS_remove_sync_dir_ (dc->h, | ||
2349 | (! search_was_null) | ||
2350 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD | ||
2351 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | ||
2352 | dc->serialization); | 2374 | 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); | ||
2353 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED; | 2381 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED; |
2354 | GNUNET_FS_download_make_status_ (&pi, dc); | 2382 | GNUNET_FS_download_make_status_(&pi, dc); |
2355 | GNUNET_FS_free_download_request_ (dc->top_request); | 2383 | GNUNET_FS_free_download_request_(dc->top_request); |
2356 | dc->top_request = NULL; | 2384 | dc->top_request = NULL; |
2357 | if (NULL != dc->active) | 2385 | if (NULL != dc->active) |
2358 | { | 2386 | { |
2359 | GNUNET_CONTAINER_multihashmap_destroy (dc->active); | 2387 | GNUNET_CONTAINER_multihashmap_destroy(dc->active); |
2360 | dc->active = NULL; | 2388 | dc->active = NULL; |
2361 | } | 2389 | } |
2362 | if (NULL != dc->filename) | 2390 | if (NULL != dc->filename) |
2363 | { | 2391 | { |
2364 | if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) | 2392 | if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) |
2365 | { | 2393 | { |
2366 | if ((0 != unlink (dc->filename)) && (ENOENT != errno)) | 2394 | if ((0 != unlink(dc->filename)) && (ENOENT != errno)) |
2367 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 2395 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, |
2368 | "unlink", | 2396 | "unlink", |
2369 | dc->filename); | 2397 | dc->filename); |
2370 | } | 2398 | } |
2371 | GNUNET_free (dc->filename); | 2399 | GNUNET_free(dc->filename); |
2372 | } | 2400 | } |
2373 | GNUNET_CONTAINER_meta_data_destroy (dc->meta); | 2401 | GNUNET_CONTAINER_meta_data_destroy(dc->meta); |
2374 | GNUNET_FS_uri_destroy (dc->uri); | 2402 | GNUNET_FS_uri_destroy(dc->uri); |
2375 | if (NULL != dc->temp_filename) | 2403 | if (NULL != dc->temp_filename) |
2376 | { | 2404 | { |
2377 | if (0 != unlink (dc->temp_filename)) | 2405 | if (0 != unlink(dc->temp_filename)) |
2378 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 2406 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, |
2379 | "unlink", | 2407 | "unlink", |
2380 | dc->temp_filename); | 2408 | dc->temp_filename); |
2381 | GNUNET_free (dc->temp_filename); | 2409 | GNUNET_free(dc->temp_filename); |
2382 | } | 2410 | } |
2383 | GNUNET_free_non_null (dc->serialization); | 2411 | GNUNET_free_non_null(dc->serialization); |
2384 | GNUNET_assert (NULL == dc->job_queue); | 2412 | GNUNET_assert(NULL == dc->job_queue); |
2385 | GNUNET_free (dc); | 2413 | GNUNET_free(dc); |
2386 | } | 2414 | } |
2387 | 2415 | ||
2388 | /* end of fs_download.c */ | 2416 | /* end of fs_download.c */ |
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c index fbf3181ef..ccba1a8b4 100644 --- a/src/fs/fs_file_information.c +++ b/src/fs/fs_file_information.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_file_information.c | 22 | * @file 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, |
@@ -118,58 +118,58 @@ GNUNET_FS_file_information_create_from_file ( | |||
118 | 118 | ||
119 | /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */ | 119 | /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */ |
120 | if (GNUNET_OK != | 120 | if (GNUNET_OK != |
121 | GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)) | 121 | GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES)) |
122 | { | 122 | { |
123 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | 123 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
124 | return NULL; | 124 | return NULL; |
125 | } | 125 | } |
126 | fi = GNUNET_FS_make_file_reader_context_ (filename); | 126 | fi = GNUNET_FS_make_file_reader_context_(filename); |
127 | if (NULL == fi) | 127 | if (NULL == fi) |
128 | { | 128 | { |
129 | GNUNET_break (0); | 129 | GNUNET_break(0); |
130 | return NULL; | 130 | return NULL; |
131 | } | 131 | } |
132 | ret = | 132 | ret = |
133 | GNUNET_FS_file_information_create_from_reader (h, | 133 | GNUNET_FS_file_information_create_from_reader(h, |
134 | client_info, | 134 | client_info, |
135 | fsize, | 135 | fsize, |
136 | &GNUNET_FS_data_reader_file_, | 136 | &GNUNET_FS_data_reader_file_, |
137 | fi, | 137 | fi, |
138 | keywords, | 138 | keywords, |
139 | meta, | 139 | meta, |
140 | do_index, | 140 | do_index, |
141 | bo); | 141 | bo); |
142 | if (ret == NULL) | 142 | if (ret == NULL) |
143 | return NULL; | 143 | return NULL; |
144 | ret->h = h; | 144 | ret->h = h; |
145 | ret->filename = GNUNET_strdup (filename); | 145 | ret->filename = GNUNET_strdup(filename); |
146 | #if ! WINDOWS | 146 | #if !WINDOWS |
147 | fn = filename; | 147 | fn = filename; |
148 | #else | 148 | #else |
149 | plibc_conv_to_win_path (filename, fn_conv); | 149 | plibc_conv_to_win_path(filename, fn_conv); |
150 | fn = fn_conv; | 150 | fn = fn_conv; |
151 | #endif | 151 | #endif |
152 | while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) | 152 | while (NULL != (ss = strstr(fn, DIR_SEPARATOR_STR))) |
153 | fn = ss + 1; | 153 | fn = ss + 1; |
154 | /* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then | 154 | /* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then |
155 | * this should be changed to EXTRACTOR_METAFORMAT_UTF8 | 155 | * this should be changed to EXTRACTOR_METAFORMAT_UTF8 |
156 | */ | 156 | */ |
157 | #if ! WINDOWS | 157 | #if !WINDOWS |
158 | GNUNET_CONTAINER_meta_data_insert (ret->meta, | 158 | GNUNET_CONTAINER_meta_data_insert(ret->meta, |
159 | "<gnunet>", | 159 | "<gnunet>", |
160 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | 160 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, |
161 | EXTRACTOR_METAFORMAT_C_STRING, | 161 | EXTRACTOR_METAFORMAT_C_STRING, |
162 | "text/plain", | 162 | "text/plain", |
163 | fn, | 163 | fn, |
164 | strlen (fn) + 1); | 164 | strlen(fn) + 1); |
165 | #else | 165 | #else |
166 | GNUNET_CONTAINER_meta_data_insert (ret->meta, | 166 | GNUNET_CONTAINER_meta_data_insert(ret->meta, |
167 | "<gnunet>", | 167 | "<gnunet>", |
168 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | 168 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, |
169 | EXTRACTOR_METAFORMAT_UTF8, | 169 | EXTRACTOR_METAFORMAT_UTF8, |
170 | "text/plain", | 170 | "text/plain", |
171 | fn, | 171 | fn, |
172 | strlen (fn) + 1); | 172 | strlen(fn) + 1); |
173 | #endif | 173 | #endif |
174 | return ret; | 174 | return ret; |
175 | } | 175 | } |
@@ -192,7 +192,7 @@ GNUNET_FS_file_information_create_from_file ( | |||
192 | * @return publish structure entry for the file | 192 | * @return publish structure entry for the file |
193 | */ | 193 | */ |
194 | struct GNUNET_FS_FileInformation * | 194 | struct GNUNET_FS_FileInformation * |
195 | GNUNET_FS_file_information_create_from_data ( | 195 | GNUNET_FS_file_information_create_from_data( |
196 | struct GNUNET_FS_Handle *h, | 196 | struct GNUNET_FS_Handle *h, |
197 | void *client_info, | 197 | void *client_info, |
198 | uint64_t length, | 198 | uint64_t length, |
@@ -203,19 +203,19 @@ GNUNET_FS_file_information_create_from_data ( | |||
203 | const struct GNUNET_FS_BlockOptions *bo) | 203 | const struct GNUNET_FS_BlockOptions *bo) |
204 | { | 204 | { |
205 | if (GNUNET_YES == do_index) | 205 | if (GNUNET_YES == do_index) |
206 | { | 206 | { |
207 | GNUNET_break (0); | 207 | GNUNET_break(0); |
208 | return NULL; | 208 | return NULL; |
209 | } | 209 | } |
210 | return GNUNET_FS_file_information_create_from_reader (h, | 210 | return GNUNET_FS_file_information_create_from_reader(h, |
211 | client_info, | 211 | client_info, |
212 | length, | 212 | length, |
213 | &GNUNET_FS_data_reader_copy_, | 213 | &GNUNET_FS_data_reader_copy_, |
214 | data, | 214 | data, |
215 | keywords, | 215 | keywords, |
216 | meta, | 216 | meta, |
217 | do_index, | 217 | do_index, |
218 | bo); | 218 | bo); |
219 | } | 219 | } |
220 | 220 | ||
221 | 221 | ||
@@ -236,7 +236,7 @@ GNUNET_FS_file_information_create_from_data ( | |||
236 | * @return publish structure entry for the file | 236 | * @return publish structure entry for the file |
237 | */ | 237 | */ |
238 | struct GNUNET_FS_FileInformation * | 238 | struct GNUNET_FS_FileInformation * |
239 | GNUNET_FS_file_information_create_from_reader ( | 239 | GNUNET_FS_file_information_create_from_reader( |
240 | struct GNUNET_FS_Handle *h, | 240 | struct GNUNET_FS_Handle *h, |
241 | void *client_info, | 241 | void *client_info, |
242 | uint64_t length, | 242 | uint64_t length, |
@@ -250,17 +250,17 @@ GNUNET_FS_file_information_create_from_reader ( | |||
250 | struct GNUNET_FS_FileInformation *ret; | 250 | struct GNUNET_FS_FileInformation *ret; |
251 | 251 | ||
252 | if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_)) | 252 | if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_)) |
253 | { | 253 | { |
254 | GNUNET_break (0); | 254 | GNUNET_break(0); |
255 | return NULL; | 255 | return NULL; |
256 | } | 256 | } |
257 | ret = GNUNET_new (struct GNUNET_FS_FileInformation); | 257 | ret = GNUNET_new(struct GNUNET_FS_FileInformation); |
258 | ret->h = h; | 258 | ret->h = h; |
259 | ret->client_info = client_info; | 259 | ret->client_info = client_info; |
260 | ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 260 | ret->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); |
261 | if (ret->meta == NULL) | 261 | if (ret->meta == NULL) |
262 | ret->meta = GNUNET_CONTAINER_meta_data_create (); | 262 | ret->meta = GNUNET_CONTAINER_meta_data_create(); |
263 | ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords); | 263 | ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup(keywords); |
264 | ret->data.file.reader = reader; | 264 | ret->data.file.reader = reader; |
265 | ret->data.file.reader_cls = reader_cls; | 265 | ret->data.file.reader_cls = reader_cls; |
266 | ret->data.file.do_index = do_index; | 266 | ret->data.file.do_index = do_index; |
@@ -277,7 +277,7 @@ GNUNET_FS_file_information_create_from_reader ( | |||
277 | * @return #GNUNET_YES if so, #GNUNET_NO if not | 277 | * @return #GNUNET_YES if so, #GNUNET_NO if not |
278 | */ | 278 | */ |
279 | int | 279 | int |
280 | GNUNET_FS_file_information_is_directory ( | 280 | GNUNET_FS_file_information_is_directory( |
281 | const struct GNUNET_FS_FileInformation *ent) | 281 | const struct GNUNET_FS_FileInformation *ent) |
282 | { | 282 | { |
283 | return ent->is_directory; | 283 | return ent->is_directory; |
@@ -297,7 +297,7 @@ GNUNET_FS_file_information_is_directory ( | |||
297 | * @return publish structure entry for the directory , NULL on error | 297 | * @return publish structure entry for the directory , NULL on error |
298 | */ | 298 | */ |
299 | struct GNUNET_FS_FileInformation * | 299 | struct GNUNET_FS_FileInformation * |
300 | GNUNET_FS_file_information_create_empty_directory ( | 300 | GNUNET_FS_file_information_create_empty_directory( |
301 | struct GNUNET_FS_Handle *h, | 301 | struct GNUNET_FS_Handle *h, |
302 | void *client_info, | 302 | void *client_info, |
303 | const struct GNUNET_FS_Uri *keywords, | 303 | const struct GNUNET_FS_Uri *keywords, |
@@ -307,15 +307,15 @@ GNUNET_FS_file_information_create_empty_directory ( | |||
307 | { | 307 | { |
308 | struct GNUNET_FS_FileInformation *ret; | 308 | struct GNUNET_FS_FileInformation *ret; |
309 | 309 | ||
310 | ret = GNUNET_new (struct GNUNET_FS_FileInformation); | 310 | ret = GNUNET_new(struct GNUNET_FS_FileInformation); |
311 | ret->h = h; | 311 | ret->h = h; |
312 | ret->client_info = client_info; | 312 | ret->client_info = client_info; |
313 | ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 313 | ret->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); |
314 | ret->keywords = GNUNET_FS_uri_dup (keywords); | 314 | ret->keywords = GNUNET_FS_uri_dup(keywords); |
315 | ret->bo = *bo; | 315 | ret->bo = *bo; |
316 | ret->is_directory = GNUNET_YES; | 316 | ret->is_directory = GNUNET_YES; |
317 | if (filename != NULL) | 317 | if (filename != NULL) |
318 | ret->filename = GNUNET_strdup (filename); | 318 | ret->filename = GNUNET_strdup(filename); |
319 | return ret; | 319 | return ret; |
320 | } | 320 | } |
321 | 321 | ||
@@ -332,15 +332,15 @@ GNUNET_FS_file_information_create_empty_directory ( | |||
332 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 332 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
333 | */ | 333 | */ |
334 | int | 334 | int |
335 | GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, | 335 | GNUNET_FS_file_information_add(struct GNUNET_FS_FileInformation *dir, |
336 | struct GNUNET_FS_FileInformation *ent) | 336 | struct GNUNET_FS_FileInformation *ent) |
337 | { | 337 | { |
338 | if ((ent->dir != NULL) || (ent->next != NULL) || | 338 | if ((ent->dir != NULL) || (ent->next != NULL) || |
339 | (dir->is_directory != GNUNET_YES)) | 339 | (dir->is_directory != GNUNET_YES)) |
340 | { | 340 | { |
341 | GNUNET_break (0); | 341 | GNUNET_break(0); |
342 | return GNUNET_SYSERR; | 342 | return GNUNET_SYSERR; |
343 | } | 343 | } |
344 | ent->dir = dir; | 344 | ent->dir = dir; |
345 | ent->next = dir->data.dir.entries; | 345 | ent->next = dir->data.dir.entries; |
346 | dir->data.dir.entries = ent; | 346 | dir->data.dir.entries = ent; |
@@ -364,45 +364,45 @@ GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, | |||
364 | * @param proc_cls closure for @a proc | 364 | * @param proc_cls closure for @a proc |
365 | */ | 365 | */ |
366 | void | 366 | void |
367 | GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, | 367 | GNUNET_FS_file_information_inspect(struct GNUNET_FS_FileInformation *dir, |
368 | GNUNET_FS_FileInformationProcessor proc, | 368 | GNUNET_FS_FileInformationProcessor proc, |
369 | void *proc_cls) | 369 | void *proc_cls) |
370 | { | 370 | { |
371 | struct GNUNET_FS_FileInformation *pos; | 371 | struct GNUNET_FS_FileInformation *pos; |
372 | int no; | 372 | int no; |
373 | 373 | ||
374 | no = GNUNET_NO; | 374 | no = GNUNET_NO; |
375 | if (GNUNET_OK != | 375 | if (GNUNET_OK != |
376 | proc (proc_cls, | 376 | proc(proc_cls, |
377 | dir, | 377 | dir, |
378 | (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size | 378 | (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size |
379 | : dir->data.file.file_size, | 379 | : dir->data.file.file_size, |
380 | dir->meta, | 380 | dir->meta, |
381 | &dir->keywords, | 381 | &dir->keywords, |
382 | &dir->bo, | 382 | &dir->bo, |
383 | (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index, | 383 | (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index, |
384 | &dir->client_info)) | 384 | &dir->client_info)) |
385 | return; | 385 | return; |
386 | if (dir->is_directory != GNUNET_YES) | 386 | if (dir->is_directory != GNUNET_YES) |
387 | return; | 387 | return; |
388 | pos = dir->data.dir.entries; | 388 | pos = dir->data.dir.entries; |
389 | while (pos != NULL) | 389 | while (pos != NULL) |
390 | { | 390 | { |
391 | no = GNUNET_NO; | 391 | no = GNUNET_NO; |
392 | if (GNUNET_OK != | 392 | if (GNUNET_OK != |
393 | proc (proc_cls, | 393 | proc(proc_cls, |
394 | pos, | 394 | pos, |
395 | (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size | 395 | (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size |
396 | : pos->data.file.file_size, | 396 | : pos->data.file.file_size, |
397 | pos->meta, | 397 | pos->meta, |
398 | &pos->keywords, | 398 | &pos->keywords, |
399 | &pos->bo, | 399 | &pos->bo, |
400 | (pos->is_directory == GNUNET_YES) ? &no | 400 | (pos->is_directory == GNUNET_YES) ? &no |
401 | : &pos->data.file.do_index, | 401 | : &pos->data.file.do_index, |
402 | &pos->client_info)) | 402 | &pos->client_info)) |
403 | break; | 403 | break; |
404 | pos = pos->next; | 404 | pos = pos->next; |
405 | } | 405 | } |
406 | } | 406 | } |
407 | 407 | ||
408 | 408 | ||
@@ -417,75 +417,75 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, | |||
417 | * @param cleaner_cls closure for @a cleaner | 417 | * @param cleaner_cls closure for @a cleaner |
418 | */ | 418 | */ |
419 | void | 419 | void |
420 | GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, | 420 | GNUNET_FS_file_information_destroy(struct GNUNET_FS_FileInformation *fi, |
421 | GNUNET_FS_FileInformationProcessor cleaner, | 421 | GNUNET_FS_FileInformationProcessor cleaner, |
422 | void *cleaner_cls) | 422 | void *cleaner_cls) |
423 | { | 423 | { |
424 | struct GNUNET_FS_FileInformation *pos; | 424 | struct GNUNET_FS_FileInformation *pos; |
425 | int no; | 425 | int no; |
426 | 426 | ||
427 | no = GNUNET_NO; | 427 | no = GNUNET_NO; |
428 | if (GNUNET_YES == fi->is_directory) | 428 | if (GNUNET_YES == fi->is_directory) |
429 | { | ||
430 | /* clean up directory */ | ||
431 | while (NULL != (pos = fi->data.dir.entries)) | ||
432 | { | 429 | { |
433 | fi->data.dir.entries = pos->next; | 430 | /* clean up directory */ |
434 | GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls); | 431 | while (NULL != (pos = fi->data.dir.entries)) |
432 | { | ||
433 | fi->data.dir.entries = pos->next; | ||
434 | GNUNET_FS_file_information_destroy(pos, cleaner, cleaner_cls); | ||
435 | } | ||
436 | /* clean up client-info */ | ||
437 | if (NULL != cleaner) | ||
438 | cleaner(cleaner_cls, | ||
439 | fi, | ||
440 | fi->data.dir.dir_size, | ||
441 | fi->meta, | ||
442 | &fi->keywords, | ||
443 | &fi->bo, | ||
444 | &no, | ||
445 | &fi->client_info); | ||
446 | GNUNET_free_non_null(fi->data.dir.dir_data); | ||
435 | } | 447 | } |
436 | /* clean up client-info */ | ||
437 | if (NULL != cleaner) | ||
438 | cleaner (cleaner_cls, | ||
439 | fi, | ||
440 | fi->data.dir.dir_size, | ||
441 | fi->meta, | ||
442 | &fi->keywords, | ||
443 | &fi->bo, | ||
444 | &no, | ||
445 | &fi->client_info); | ||
446 | GNUNET_free_non_null (fi->data.dir.dir_data); | ||
447 | } | ||
448 | else | 448 | else |
449 | { | ||
450 | /* call clean-up function of the reader */ | ||
451 | if (NULL != fi->data.file.reader) | ||
452 | { | 449 | { |
453 | (void) fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL); | 450 | /* call clean-up function of the reader */ |
454 | fi->data.file.reader = NULL; | 451 | if (NULL != fi->data.file.reader) |
452 | { | ||
453 | (void)fi->data.file.reader(fi->data.file.reader_cls, 0, 0, NULL, NULL); | ||
454 | fi->data.file.reader = NULL; | ||
455 | } | ||
456 | /* clean up client-info */ | ||
457 | if (NULL != cleaner) | ||
458 | cleaner(cleaner_cls, | ||
459 | fi, | ||
460 | fi->data.file.file_size, | ||
461 | fi->meta, | ||
462 | &fi->keywords, | ||
463 | &fi->bo, | ||
464 | &fi->data.file.do_index, | ||
465 | &fi->client_info); | ||
455 | } | 466 | } |
456 | /* clean up client-info */ | 467 | GNUNET_free_non_null(fi->filename); |
457 | if (NULL != cleaner) | 468 | GNUNET_free_non_null(fi->emsg); |
458 | cleaner (cleaner_cls, | ||
459 | fi, | ||
460 | fi->data.file.file_size, | ||
461 | fi->meta, | ||
462 | &fi->keywords, | ||
463 | &fi->bo, | ||
464 | &fi->data.file.do_index, | ||
465 | &fi->client_info); | ||
466 | } | ||
467 | GNUNET_free_non_null (fi->filename); | ||
468 | GNUNET_free_non_null (fi->emsg); | ||
469 | if (NULL != fi->sks_uri) | 469 | if (NULL != fi->sks_uri) |
470 | GNUNET_FS_uri_destroy (fi->sks_uri); | 470 | GNUNET_FS_uri_destroy(fi->sks_uri); |
471 | if (NULL != fi->chk_uri) | 471 | if (NULL != fi->chk_uri) |
472 | GNUNET_FS_uri_destroy (fi->chk_uri); | 472 | GNUNET_FS_uri_destroy(fi->chk_uri); |
473 | /* clean up serialization */ | 473 | /* clean up serialization */ |
474 | if ((NULL != fi->serialization) && (0 != unlink (fi->serialization))) | 474 | if ((NULL != fi->serialization) && (0 != unlink(fi->serialization))) |
475 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 475 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, |
476 | "unlink", | 476 | "unlink", |
477 | fi->serialization); | 477 | fi->serialization); |
478 | if (NULL != fi->keywords) | 478 | if (NULL != fi->keywords) |
479 | GNUNET_FS_uri_destroy (fi->keywords); | 479 | GNUNET_FS_uri_destroy(fi->keywords); |
480 | if (NULL != fi->meta) | 480 | if (NULL != fi->meta) |
481 | GNUNET_CONTAINER_meta_data_destroy (fi->meta); | 481 | GNUNET_CONTAINER_meta_data_destroy(fi->meta); |
482 | GNUNET_free_non_null (fi->serialization); | 482 | GNUNET_free_non_null(fi->serialization); |
483 | if (NULL != fi->te) | 483 | if (NULL != fi->te) |
484 | { | 484 | { |
485 | GNUNET_FS_tree_encoder_finish (fi->te, NULL); | 485 | GNUNET_FS_tree_encoder_finish(fi->te, NULL); |
486 | fi->te = NULL; | 486 | fi->te = NULL; |
487 | } | 487 | } |
488 | GNUNET_free (fi); | 488 | GNUNET_free(fi); |
489 | } | 489 | } |
490 | 490 | ||
491 | 491 | ||
diff --git a/src/fs/fs_getopt.c b/src/fs/fs_getopt.c index 0d5907a40..4f53f64a5 100644 --- a/src/fs/fs_getopt.c +++ b/src/fs/fs_getopt.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_getopt.c | 22 | * @file 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] == '"')) | ||
77 | { | ||
78 | /* remove the quotes, keep the '+' */ | ||
79 | val = GNUNET_malloc (slen - 1); | ||
80 | val[0] = '+'; | ||
81 | GNUNET_memcpy (&val[1], | ||
82 | &value[2], | ||
83 | slen - 3); | ||
84 | val[slen - 2] = '\0'; | ||
85 | } | ||
86 | else | ||
87 | { | 72 | { |
88 | /* no quotes, just keep the '+' */ | 73 | /* simply preserve the "mandatory" flag */ |
89 | val = GNUNET_strdup (value); | 74 | if (slen < 2) |
75 | return GNUNET_SYSERR; /* empty keywords not allowed */ | ||
76 | if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"')) | ||
77 | { | ||
78 | /* remove the quotes, keep the '+' */ | ||
79 | val = GNUNET_malloc(slen - 1); | ||
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 | } | ||
90 | } | 91 | } |
91 | } | ||
92 | else | 92 | else |
93 | { | ||
94 | if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"')) | ||
95 | { | 93 | { |
96 | /* remove the quotes, add a space */ | 94 | if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"')) |
97 | val = GNUNET_malloc (slen); | 95 | { |
98 | val[0] = ' '; | 96 | /* remove the quotes, add a space */ |
99 | GNUNET_memcpy (&val[1], | 97 | val = GNUNET_malloc(slen); |
100 | &value[1], | 98 | val[0] = ' '; |
101 | slen - 2); | 99 | GNUNET_memcpy(&val[1], |
102 | val[slen - 1] = '\0'; | 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 | } | ||
103 | } | 111 | } |
104 | else | 112 | GNUNET_array_append(u->data.ksk.keywords, |
105 | { | 113 | u->data.ksk.keywordCount, |
106 | /* add a space to indicate "not mandatory" */ | 114 | val); |
107 | val = GNUNET_malloc (slen + 2); | ||
108 | strcpy (val, " "); | ||
109 | strcat (val, value); | ||
110 | } | ||
111 | } | ||
112 | GNUNET_array_append (u->data.ksk.keywords, | ||
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,12 +159,13 @@ 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 | #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR | 169 | #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR |
169 | enum EXTRACTOR_MetaType type; | 170 | enum EXTRACTOR_MetaType type; |
170 | const char *typename; | 171 | const char *typename; |
@@ -175,66 +176,66 @@ getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
175 | 176 | ||
176 | meta = *mm; | 177 | meta = *mm; |
177 | if (meta == NULL) | 178 | if (meta == NULL) |
178 | { | 179 | { |
179 | meta = GNUNET_CONTAINER_meta_data_create (); | 180 | meta = GNUNET_CONTAINER_meta_data_create(); |
180 | *mm = meta; | 181 | *mm = meta; |
181 | } | 182 | } |
182 | 183 | ||
183 | /* 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 |
184 | * commandline arguments, so that the following line is not needed. | 185 | * commandline arguments, so that the following line is not needed. |
185 | */ | 186 | */ |
186 | /*tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), locale_charset ());*/ | 187 | /*tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), locale_charset ());*/ |
187 | tmp = GNUNET_strdup (value); | 188 | tmp = GNUNET_strdup(value); |
188 | #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR | 189 | #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR |
189 | type = EXTRACTOR_metatype_get_max (); | 190 | type = EXTRACTOR_metatype_get_max(); |
190 | while (type > 0) | 191 | while (type > 0) |
191 | { | ||
192 | type--; | ||
193 | typename = EXTRACTOR_metatype_to_string (type); | ||
194 | typename_i18n = dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, typename); | ||
195 | if ((strlen (tmp) >= strlen (typename) + 1) && | ||
196 | (tmp[strlen (typename)] == ':') && | ||
197 | (0 == strncmp (typename, tmp, strlen (typename)))) | ||
198 | { | 192 | { |
199 | GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", type, | 193 | type--; |
200 | EXTRACTOR_METAFORMAT_UTF8, | 194 | typename = EXTRACTOR_metatype_to_string(type); |
201 | "text/plain", | 195 | typename_i18n = dgettext(LIBEXTRACTOR_GETTEXT_DOMAIN, typename); |
202 | &tmp[strlen (typename) + 1], | 196 | if ((strlen(tmp) >= strlen(typename) + 1) && |
203 | strlen (&tmp[strlen (typename) + 1]) + | 197 | (tmp[strlen(typename)] == ':') && |
204 | 1); | 198 | (0 == strncmp(typename, tmp, strlen(typename)))) |
205 | GNUNET_free (tmp); | 199 | { |
206 | tmp = NULL; | 200 | GNUNET_CONTAINER_meta_data_insert(meta, "<gnunet>", type, |
207 | break; | 201 | EXTRACTOR_METAFORMAT_UTF8, |
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 | } | ||
208 | } | 225 | } |
209 | if ((strlen (tmp) >= strlen (typename_i18n) + 1) && | ||
210 | (tmp[strlen (typename_i18n)] == ':') && | ||
211 | (0 == strncmp (typename_i18n, tmp, strlen (typename_i18n)))) | ||
212 | { | ||
213 | GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", type, | ||
214 | EXTRACTOR_METAFORMAT_UTF8, | ||
215 | "text/plain", | ||
216 | &tmp[strlen (typename_i18n) + 1], | ||
217 | strlen (&tmp | ||
218 | [strlen (typename_i18n) + 1]) + | ||
219 | 1); | ||
220 | GNUNET_free (tmp); | ||
221 | tmp = NULL; | ||
222 | break; | ||
223 | } | ||
224 | } | ||
225 | #endif | 226 | #endif |
226 | 227 | ||
227 | if (NULL != tmp) | 228 | if (NULL != tmp) |
228 | { | 229 | { |
229 | GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", | 230 | GNUNET_CONTAINER_meta_data_insert(meta, "<gnunet>", |
230 | EXTRACTOR_METATYPE_UNKNOWN, | 231 | EXTRACTOR_METATYPE_UNKNOWN, |
231 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 232 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
232 | tmp, strlen (tmp) + 1); | 233 | tmp, strlen(tmp) + 1); |
233 | GNUNET_free (tmp); | 234 | GNUNET_free(tmp); |
234 | printf (_ | 235 | printf(_ |
235 | ("Unknown metadata type in metadata option `%s'. Using metadata type `unknown' instead.\n"), | 236 | ("Unknown metadata type in metadata option `%s'. Using metadata type `unknown' instead.\n"), |
236 | value); | 237 | value); |
237 | } | 238 | } |
238 | return GNUNET_OK; | 239 | return GNUNET_OK; |
239 | } | 240 | } |
240 | 241 | ||
@@ -248,11 +249,11 @@ getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
248 | * @param[out] metadata set to the desired value | 249 | * @param[out] metadata set to the desired value |
249 | */ | 250 | */ |
250 | struct GNUNET_GETOPT_CommandLineOption | 251 | struct GNUNET_GETOPT_CommandLineOption |
251 | GNUNET_FS_GETOPT_METADATA (char shortName, | 252 | GNUNET_FS_GETOPT_METADATA(char shortName, |
252 | const char *name, | 253 | const char *name, |
253 | const char *argumentHelp, | 254 | const char *argumentHelp, |
254 | const char *description, | 255 | const char *description, |
255 | struct GNUNET_CONTAINER_MetaData **meta) | 256 | struct GNUNET_CONTAINER_MetaData **meta) |
256 | { | 257 | { |
257 | struct GNUNET_GETOPT_CommandLineOption clo = { | 258 | struct GNUNET_GETOPT_CommandLineOption clo = { |
258 | .shortName = shortName, | 259 | .shortName = shortName, |
@@ -261,7 +262,7 @@ GNUNET_FS_GETOPT_METADATA (char shortName, | |||
261 | .description = description, | 262 | .description = description, |
262 | .require_argument = 1, | 263 | .require_argument = 1, |
263 | .processor = &getopt_set_metadata, | 264 | .processor = &getopt_set_metadata, |
264 | .scls = (void *) meta | 265 | .scls = (void *)meta |
265 | }; | 266 | }; |
266 | 267 | ||
267 | return clo; | 268 | return clo; |
diff --git a/src/fs/fs_list_indexed.c b/src/fs/fs_list_indexed.c index 08a7be48e..c023d0ac6 100644 --- a/src/fs/fs_list_indexed.c +++ b/src/fs/fs_list_indexed.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_list_indexed.c | 22 | * @file fs/fs_list_indexed.c |
@@ -34,9 +34,7 @@ | |||
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 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * Connection to the FS service. | 39 | * Connection to the FS service. |
42 | */ | 40 | */ |
@@ -72,15 +70,15 @@ struct GNUNET_FS_GetIndexedContext | |||
72 | * @param msg message with indexing information | 70 | * @param msg message with indexing information |
73 | */ | 71 | */ |
74 | static void | 72 | static void |
75 | handle_index_info_end (void *cls, | 73 | handle_index_info_end(void *cls, |
76 | const struct GNUNET_MessageHeader *msg) | 74 | const struct GNUNET_MessageHeader *msg) |
77 | { | 75 | { |
78 | struct GNUNET_FS_GetIndexedContext *gic = cls; | 76 | struct GNUNET_FS_GetIndexedContext *gic = cls; |
79 | 77 | ||
80 | (void) gic->iterator (gic->iterator_cls, | 78 | (void)gic->iterator(gic->iterator_cls, |
81 | NULL, | 79 | NULL, |
82 | NULL); | 80 | NULL); |
83 | GNUNET_FS_get_indexed_files_cancel (gic); | 81 | GNUNET_FS_get_indexed_files_cancel(gic); |
84 | } | 82 | } |
85 | 83 | ||
86 | 84 | ||
@@ -92,18 +90,18 @@ handle_index_info_end (void *cls, | |||
92 | * @param iim message with indexing information | 90 | * @param iim message with indexing information |
93 | */ | 91 | */ |
94 | static int | 92 | static int |
95 | check_index_info (void *cls, | 93 | check_index_info(void *cls, |
96 | const struct IndexInfoMessage *iim) | 94 | const struct IndexInfoMessage *iim) |
97 | { | 95 | { |
98 | uint16_t msize = ntohs (iim->header.size) - sizeof (*iim); | 96 | uint16_t msize = ntohs(iim->header.size) - sizeof(*iim); |
99 | const char *filename; | 97 | const char *filename; |
100 | 98 | ||
101 | filename = (const char *) &iim[1]; | 99 | filename = (const char *)&iim[1]; |
102 | if (filename[msize - 1] != '\0') | 100 | if (filename[msize - 1] != '\0') |
103 | { | 101 | { |
104 | GNUNET_break (0); | 102 | GNUNET_break(0); |
105 | return GNUNET_SYSERR; | 103 | return GNUNET_SYSERR; |
106 | } | 104 | } |
107 | return GNUNET_OK; | 105 | return GNUNET_OK; |
108 | } | 106 | } |
109 | 107 | ||
@@ -116,21 +114,21 @@ check_index_info (void *cls, | |||
116 | * @param iim message with indexing information | 114 | * @param iim message with indexing information |
117 | */ | 115 | */ |
118 | static void | 116 | static void |
119 | handle_index_info (void *cls, | 117 | handle_index_info(void *cls, |
120 | const struct IndexInfoMessage *iim) | 118 | const struct IndexInfoMessage *iim) |
121 | { | 119 | { |
122 | struct GNUNET_FS_GetIndexedContext *gic = cls; | 120 | struct GNUNET_FS_GetIndexedContext *gic = cls; |
123 | const char *filename; | 121 | const char *filename; |
124 | 122 | ||
125 | filename = (const char *) &iim[1]; | 123 | filename = (const char *)&iim[1]; |
126 | if (GNUNET_OK != | 124 | if (GNUNET_OK != |
127 | gic->iterator (gic->iterator_cls, | 125 | gic->iterator(gic->iterator_cls, |
128 | filename, | 126 | filename, |
129 | &iim->file_id)) | 127 | &iim->file_id)) |
130 | { | 128 | { |
131 | GNUNET_FS_get_indexed_files_cancel (gic); | 129 | GNUNET_FS_get_indexed_files_cancel(gic); |
132 | return; | 130 | return; |
133 | } | 131 | } |
134 | } | 132 | } |
135 | 133 | ||
136 | 134 | ||
@@ -143,16 +141,16 @@ handle_index_info (void *cls, | |||
143 | * @param error error code | 141 | * @param error error code |
144 | */ | 142 | */ |
145 | static void | 143 | static void |
146 | mq_error_handler (void *cls, | 144 | mq_error_handler(void *cls, |
147 | enum GNUNET_MQ_Error error) | 145 | enum GNUNET_MQ_Error error) |
148 | { | 146 | { |
149 | struct GNUNET_FS_GetIndexedContext *gic = cls; | 147 | struct GNUNET_FS_GetIndexedContext *gic = cls; |
150 | 148 | ||
151 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 149 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
152 | _("Failed to receive response from `%s' service.\n"), | 150 | _("Failed to receive response from `%s' service.\n"), |
153 | "fs"); | 151 | "fs"); |
154 | (void) gic->iterator (gic->iterator_cls, NULL, NULL); | 152 | (void)gic->iterator(gic->iterator_cls, NULL, NULL); |
155 | GNUNET_FS_get_indexed_files_cancel (gic); | 153 | GNUNET_FS_get_indexed_files_cancel(gic); |
156 | } | 154 | } |
157 | 155 | ||
158 | 156 | ||
@@ -165,45 +163,45 @@ mq_error_handler (void *cls, | |||
165 | * @return NULL on error ('iter' is not called) | 163 | * @return NULL on error ('iter' is not called) |
166 | */ | 164 | */ |
167 | struct GNUNET_FS_GetIndexedContext * | 165 | struct GNUNET_FS_GetIndexedContext * |
168 | GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, | 166 | GNUNET_FS_get_indexed_files(struct GNUNET_FS_Handle *h, |
169 | GNUNET_FS_IndexedFileProcessor iterator, | 167 | GNUNET_FS_IndexedFileProcessor iterator, |
170 | void *iterator_cls) | 168 | void *iterator_cls) |
171 | { | 169 | { |
172 | struct GNUNET_FS_GetIndexedContext *gic | 170 | struct GNUNET_FS_GetIndexedContext *gic |
173 | = GNUNET_new (struct GNUNET_FS_GetIndexedContext); | 171 | = GNUNET_new(struct GNUNET_FS_GetIndexedContext); |
174 | struct GNUNET_MQ_MessageHandler handlers[] = { | 172 | struct GNUNET_MQ_MessageHandler handlers[] = { |
175 | GNUNET_MQ_hd_fixed_size (index_info_end, | 173 | GNUNET_MQ_hd_fixed_size(index_info_end, |
176 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END, | 174 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END, |
177 | struct GNUNET_MessageHeader, | 175 | struct GNUNET_MessageHeader, |
178 | gic), | 176 | gic), |
179 | GNUNET_MQ_hd_var_size (index_info, | 177 | GNUNET_MQ_hd_var_size(index_info, |
180 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY, | 178 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY, |
181 | struct IndexInfoMessage, | 179 | struct IndexInfoMessage, |
182 | gic), | 180 | gic), |
183 | GNUNET_MQ_handler_end () | 181 | GNUNET_MQ_handler_end() |
184 | }; | 182 | }; |
185 | struct GNUNET_MQ_Envelope *env; | 183 | struct GNUNET_MQ_Envelope *env; |
186 | struct GNUNET_MessageHeader *msg; | 184 | struct GNUNET_MessageHeader *msg; |
187 | 185 | ||
188 | gic->mq = GNUNET_CLIENT_connect (h->cfg, | 186 | gic->mq = GNUNET_CLIENT_connect(h->cfg, |
189 | "fs", | 187 | "fs", |
190 | handlers, | 188 | handlers, |
191 | &mq_error_handler, | 189 | &mq_error_handler, |
192 | h); | 190 | h); |
193 | if (NULL == gic->mq) | 191 | if (NULL == gic->mq) |
194 | { | 192 | { |
195 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 193 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
196 | _("Failed to not connect to `%s' service.\n"), | 194 | _("Failed to not connect to `%s' service.\n"), |
197 | "fs"); | 195 | "fs"); |
198 | GNUNET_free (gic); | 196 | GNUNET_free(gic); |
199 | return NULL; | 197 | return NULL; |
200 | } | 198 | } |
201 | gic->iterator = iterator; | 199 | gic->iterator = iterator; |
202 | gic->iterator_cls = iterator_cls; | 200 | gic->iterator_cls = iterator_cls; |
203 | env = GNUNET_MQ_msg (msg, | 201 | env = GNUNET_MQ_msg(msg, |
204 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET); | 202 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET); |
205 | GNUNET_MQ_send (gic->mq, | 203 | GNUNET_MQ_send(gic->mq, |
206 | env); | 204 | env); |
207 | return gic; | 205 | return gic; |
208 | } | 206 | } |
209 | 207 | ||
@@ -214,10 +212,10 @@ GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, | |||
214 | * @param gic operation to cancel | 212 | * @param gic operation to cancel |
215 | */ | 213 | */ |
216 | void | 214 | void |
217 | GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic) | 215 | GNUNET_FS_get_indexed_files_cancel(struct GNUNET_FS_GetIndexedContext *gic) |
218 | { | 216 | { |
219 | GNUNET_MQ_destroy (gic->mq); | 217 | GNUNET_MQ_destroy(gic->mq); |
220 | GNUNET_free (gic); | 218 | GNUNET_free(gic); |
221 | } | 219 | } |
222 | 220 | ||
223 | 221 | ||
diff --git a/src/fs/fs_misc.c b/src/fs/fs_misc.c index 918c637a0..79f082626 100644 --- a/src/fs/fs_misc.c +++ b/src/fs/fs_misc.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/fs_misc.c | 21 | * @file fs/fs_misc.c |
22 | * @brief misc. functions related to file-sharing in general | 22 | * @brief misc. functions related to file-sharing in general |
@@ -35,74 +35,74 @@ | |||
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" }, |
43 | {"application/gnunet-directory", ".gnd"}, | 43 | { "application/gnunet-directory", ".gnd" }, |
44 | {"application/java", ".class"}, | 44 | { "application/java", ".class" }, |
45 | {"application/msword", ".doc"}, | 45 | { "application/msword", ".doc" }, |
46 | {"application/nar", ".nar"}, | 46 | { "application/nar", ".nar" }, |
47 | {"application/narinfo", ".narinfo"}, | 47 | { "application/narinfo", ".narinfo" }, |
48 | {"application/ogg", ".ogg"}, | 48 | { "application/ogg", ".ogg" }, |
49 | {"application/pdf", ".pdf"}, | 49 | { "application/pdf", ".pdf" }, |
50 | {"application/pgp-keys", ".key"}, | 50 | { "application/pgp-keys", ".key" }, |
51 | {"application/pgp-signature", ".pgp"}, | 51 | { "application/pgp-signature", ".pgp" }, |
52 | {"application/postscript", ".ps"}, | 52 | { "application/postscript", ".ps" }, |
53 | {"application/rar", ".rar"}, | 53 | { "application/rar", ".rar" }, |
54 | {"application/rtf", ".rtf"}, | 54 | { "application/rtf", ".rtf" }, |
55 | {"application/xml", ".xml"}, | 55 | { "application/xml", ".xml" }, |
56 | {"application/x-debian-package", ".deb"}, | 56 | { "application/x-debian-package", ".deb" }, |
57 | {"application/x-dvi", ".dvi"}, | 57 | { "application/x-dvi", ".dvi" }, |
58 | {"application/x-flac", ".flac"}, | 58 | { "application/x-flac", ".flac" }, |
59 | {"application/x-gzip", ".gz"}, | 59 | { "application/x-gzip", ".gz" }, |
60 | {"application/x-java-archive", ".jar"}, | 60 | { "application/x-java-archive", ".jar" }, |
61 | {"application/x-java-vm", ".class"}, | 61 | { "application/x-java-vm", ".class" }, |
62 | {"application/x-python-code", ".pyc"}, | 62 | { "application/x-python-code", ".pyc" }, |
63 | {"application/x-redhat-package-manager", ".rpm"}, | 63 | { "application/x-redhat-package-manager", ".rpm" }, |
64 | {"application/x-rpm", ".rpm"}, | 64 | { "application/x-rpm", ".rpm" }, |
65 | {"application/x-tar", ".tar"}, | 65 | { "application/x-tar", ".tar" }, |
66 | {"application/x-tex-pk", ".pk"}, | 66 | { "application/x-tex-pk", ".pk" }, |
67 | {"application/x-texinfo", ".texinfo"}, | 67 | { "application/x-texinfo", ".texinfo" }, |
68 | {"application/x-xcf", ".xcf"}, | 68 | { "application/x-xcf", ".xcf" }, |
69 | {"application/x-xfig", ".xfig"}, | 69 | { "application/x-xfig", ".xfig" }, |
70 | {"application/zip", ".zip"}, | 70 | { "application/zip", ".zip" }, |
71 | 71 | ||
72 | {"audio/midi", ".midi"}, | 72 | { "audio/midi", ".midi" }, |
73 | {"audio/mpeg", ".mp3"}, | 73 | { "audio/mpeg", ".mp3" }, |
74 | {"audio/real", ".rm"}, | 74 | { "audio/real", ".rm" }, |
75 | {"audio/x-wav", ".wav"}, | 75 | { "audio/x-wav", ".wav" }, |
76 | 76 | ||
77 | {"image/gif", ".gif"}, | 77 | { "image/gif", ".gif" }, |
78 | {"image/jpeg", ".jpg"}, | 78 | { "image/jpeg", ".jpg" }, |
79 | {"image/pcx", ".pcx"}, | 79 | { "image/pcx", ".pcx" }, |
80 | {"image/png", ".png"}, | 80 | { "image/png", ".png" }, |
81 | {"image/tiff", ".tiff"}, | 81 | { "image/tiff", ".tiff" }, |
82 | {"image/x-ms-bmp", ".bmp"}, | 82 | { "image/x-ms-bmp", ".bmp" }, |
83 | {"image/x-xpixmap", ".xpm"}, | 83 | { "image/x-xpixmap", ".xpm" }, |
84 | 84 | ||
85 | {"text/css", ".css"}, | 85 | { "text/css", ".css" }, |
86 | {"text/html", ".html"}, | 86 | { "text/html", ".html" }, |
87 | {"text/plain", ".txt"}, | 87 | { "text/plain", ".txt" }, |
88 | {"text/rtf", ".rtf"}, | 88 | { "text/rtf", ".rtf" }, |
89 | {"text/x-c++hdr", ".h++"}, | 89 | { "text/x-c++hdr", ".h++" }, |
90 | {"text/x-c++src", ".c++"}, | 90 | { "text/x-c++src", ".c++" }, |
91 | {"text/x-chdr", ".h"}, | 91 | { "text/x-chdr", ".h" }, |
92 | {"text/x-csrc", ".c"}, | 92 | { "text/x-csrc", ".c" }, |
93 | {"text/x-java", ".java"}, | 93 | { "text/x-java", ".java" }, |
94 | {"text/x-moc", ".moc"}, | 94 | { "text/x-moc", ".moc" }, |
95 | {"text/x-pascal", ".pas"}, | 95 | { "text/x-pascal", ".pas" }, |
96 | {"text/x-perl", ".pl"}, | 96 | { "text/x-perl", ".pl" }, |
97 | {"text/x-python", ".py"}, | 97 | { "text/x-python", ".py" }, |
98 | {"text/x-tex", ".tex"}, | 98 | { "text/x-tex", ".tex" }, |
99 | 99 | ||
100 | {"video/avi", ".avi"}, | 100 | { "video/avi", ".avi" }, |
101 | {"video/mpeg", ".mpeg"}, | 101 | { "video/mpeg", ".mpeg" }, |
102 | {"video/quicktime", ".qt"}, | 102 | { "video/quicktime", ".qt" }, |
103 | {"video/real", ".rm"}, | 103 | { "video/real", ".rm" }, |
104 | {"video/x-msvideo", ".avi"}, | 104 | { "video/x-msvideo", ".avi" }, |
105 | {NULL, NULL}, | 105 | { NULL, NULL }, |
106 | }; | 106 | }; |
107 | char *ret; | 107 | char *ret; |
108 | unsigned int i; | 108 | unsigned int i; |
@@ -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 11a137a09..b740eb2ba 100644 --- a/src/fs/fs_namespace.c +++ b/src/fs/fs_namespace.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_namespace.c | 22 | * @file fs/fs_namespace.c |
@@ -37,8 +37,7 @@ | |||
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 | { | ||
42 | /** | 41 | /** |
43 | * Identifier for this node. | 42 | * Identifier for this node. |
44 | */ | 43 | */ |
@@ -75,9 +74,7 @@ struct NamespaceUpdateNode | |||
75 | /** | 74 | /** |
76 | * Handle to update information for a namespace. | 75 | * Handle to update information for a namespace. |
77 | */ | 76 | */ |
78 | struct GNUNET_FS_UpdateInformationGraph | 77 | struct GNUNET_FS_UpdateInformationGraph { |
79 | { | ||
80 | |||
81 | /** | 78 | /** |
82 | * Handle to the FS service context. | 79 | * Handle to the FS service context. |
83 | */ | 80 | */ |
@@ -125,7 +122,7 @@ struct GNUNET_FS_UpdateInformationGraph | |||
125 | * @return NULL on error, otherwise the name of the directory | 122 | * @return NULL on error, otherwise the name of the directory |
126 | */ | 123 | */ |
127 | static char * | 124 | static char * |
128 | get_update_information_directory ( | 125 | get_update_information_directory( |
129 | struct GNUNET_FS_Handle *h, | 126 | struct GNUNET_FS_Handle *h, |
130 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) | 127 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) |
131 | { | 128 | { |
@@ -136,20 +133,20 @@ get_update_information_directory ( | |||
136 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | 133 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; |
137 | 134 | ||
138 | if (GNUNET_OK != | 135 | if (GNUNET_OK != |
139 | GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "UPDATE_DIR", &dn)) | 136 | GNUNET_CONFIGURATION_get_value_filename(h->cfg, "FS", "UPDATE_DIR", &dn)) |
140 | { | 137 | { |
141 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "fs", "UPDATE_DIR"); | 138 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "fs", "UPDATE_DIR"); |
142 | return NULL; | 139 | return NULL; |
143 | } | 140 | } |
144 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, &pub); | 141 | GNUNET_CRYPTO_ecdsa_key_get_public(ns, &pub); |
145 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &hc); | 142 | GNUNET_CRYPTO_hash(&pub, sizeof(pub), &hc); |
146 | GNUNET_CRYPTO_hash_to_enc (&hc, &enc); | 143 | GNUNET_CRYPTO_hash_to_enc(&hc, &enc); |
147 | GNUNET_asprintf (&ret, | 144 | GNUNET_asprintf(&ret, |
148 | "%s%s%s", | 145 | "%s%s%s", |
149 | dn, | 146 | dn, |
150 | DIR_SEPARATOR_STR, | 147 | DIR_SEPARATOR_STR, |
151 | (const char *) enc.encoding); | 148 | (const char *)enc.encoding); |
152 | GNUNET_free (dn); | 149 | GNUNET_free(dn); |
153 | return ret; | 150 | return ret; |
154 | } | 151 | } |
155 | 152 | ||
@@ -160,24 +157,24 @@ get_update_information_directory ( | |||
160 | * @param uig data structure to free | 157 | * @param uig data structure to free |
161 | */ | 158 | */ |
162 | static void | 159 | static void |
163 | free_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | 160 | free_update_information_graph(struct GNUNET_FS_UpdateInformationGraph *uig) |
164 | { | 161 | { |
165 | unsigned int i; | 162 | unsigned int i; |
166 | struct NamespaceUpdateNode *nsn; | 163 | struct NamespaceUpdateNode *nsn; |
167 | 164 | ||
168 | for (i = 0; i < uig->update_node_count; i++) | 165 | for (i = 0; i < uig->update_node_count; i++) |
169 | { | 166 | { |
170 | nsn = uig->update_nodes[i]; | 167 | nsn = uig->update_nodes[i]; |
171 | GNUNET_CONTAINER_meta_data_destroy (nsn->md); | 168 | GNUNET_CONTAINER_meta_data_destroy(nsn->md); |
172 | GNUNET_FS_uri_destroy (nsn->uri); | 169 | GNUNET_FS_uri_destroy(nsn->uri); |
173 | GNUNET_free (nsn->id); | 170 | GNUNET_free(nsn->id); |
174 | GNUNET_free (nsn->update); | 171 | GNUNET_free(nsn->update); |
175 | GNUNET_free (nsn); | 172 | GNUNET_free(nsn); |
176 | } | 173 | } |
177 | GNUNET_array_grow (uig->update_nodes, uig->update_node_count, 0); | 174 | GNUNET_array_grow(uig->update_nodes, uig->update_node_count, 0); |
178 | if (NULL != uig->update_map) | 175 | if (NULL != uig->update_map) |
179 | GNUNET_CONTAINER_multihashmap_destroy (uig->update_map); | 176 | GNUNET_CONTAINER_multihashmap_destroy(uig->update_map); |
180 | GNUNET_free (uig); | 177 | GNUNET_free(uig); |
181 | } | 178 | } |
182 | 179 | ||
183 | 180 | ||
@@ -187,7 +184,7 @@ free_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | |||
187 | * @param uig update information graph to dump | 184 | * @param uig update information graph to dump |
188 | */ | 185 | */ |
189 | static void | 186 | static void |
190 | write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | 187 | write_update_information_graph(struct GNUNET_FS_UpdateInformationGraph *uig) |
191 | { | 188 | { |
192 | char *fn; | 189 | char *fn; |
193 | struct GNUNET_BIO_WriteHandle *wh; | 190 | struct GNUNET_BIO_WriteHandle *wh; |
@@ -195,40 +192,40 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | |||
195 | struct NamespaceUpdateNode *n; | 192 | struct NamespaceUpdateNode *n; |
196 | char *uris; | 193 | char *uris; |
197 | 194 | ||
198 | fn = get_update_information_directory (uig->h, &uig->ns); | 195 | fn = get_update_information_directory(uig->h, &uig->ns); |
199 | wh = GNUNET_BIO_write_open (fn); | 196 | wh = GNUNET_BIO_write_open(fn); |
200 | if (NULL == wh) | 197 | if (NULL == wh) |
201 | { | 198 | { |
202 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 199 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
203 | _ ("Failed to open `%s' for writing: %s\n"), | 200 | _("Failed to open `%s' for writing: %s\n"), |
204 | fn, | 201 | fn, |
205 | strerror (errno)); | 202 | strerror(errno)); |
206 | GNUNET_free (fn); | 203 | GNUNET_free(fn); |
207 | return; | 204 | return; |
208 | } | 205 | } |
209 | if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, uig->update_node_count)) | 206 | if (GNUNET_OK != GNUNET_BIO_write_int32(wh, uig->update_node_count)) |
210 | goto END; | 207 | goto END; |
211 | for (i = 0; i < uig->update_node_count; i++) | 208 | for (i = 0; i < uig->update_node_count; i++) |
212 | { | ||
213 | n = uig->update_nodes[i]; | ||
214 | uris = GNUNET_FS_uri_to_string (n->uri); | ||
215 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, n->id)) || | ||
216 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, n->md)) || | ||
217 | (GNUNET_OK != GNUNET_BIO_write_string (wh, n->update)) || | ||
218 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uris))) | ||
219 | { | 209 | { |
220 | GNUNET_free (uris); | 210 | n = uig->update_nodes[i]; |
221 | break; | 211 | uris = GNUNET_FS_uri_to_string(n->uri); |
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); | ||
222 | } | 221 | } |
223 | GNUNET_free (uris); | ||
224 | } | ||
225 | END: | 222 | END: |
226 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 223 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
227 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 224 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
228 | _ ("Failed to write `%s': %s\n"), | 225 | _("Failed to write `%s': %s\n"), |
229 | fn, | 226 | fn, |
230 | strerror (errno)); | 227 | strerror(errno)); |
231 | GNUNET_free (fn); | 228 | GNUNET_free(fn); |
232 | } | 229 | } |
233 | 230 | ||
234 | 231 | ||
@@ -240,8 +237,8 @@ END: | |||
240 | * @return update graph, never NULL | 237 | * @return update graph, never NULL |
241 | */ | 238 | */ |
242 | static struct GNUNET_FS_UpdateInformationGraph * | 239 | static struct GNUNET_FS_UpdateInformationGraph * |
243 | read_update_information_graph (struct GNUNET_FS_Handle *h, | 240 | read_update_information_graph(struct GNUNET_FS_Handle *h, |
244 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) | 241 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) |
245 | { | 242 | { |
246 | struct GNUNET_FS_UpdateInformationGraph *uig; | 243 | struct GNUNET_FS_UpdateInformationGraph *uig; |
247 | char *fn; | 244 | char *fn; |
@@ -252,79 +249,79 @@ read_update_information_graph (struct GNUNET_FS_Handle *h, | |||
252 | uint32_t count; | 249 | uint32_t count; |
253 | char *emsg; | 250 | char *emsg; |
254 | 251 | ||
255 | uig = GNUNET_new (struct GNUNET_FS_UpdateInformationGraph); | 252 | uig = GNUNET_new(struct GNUNET_FS_UpdateInformationGraph); |
256 | uig->h = h; | 253 | uig->h = h; |
257 | uig->ns = *ns; | 254 | uig->ns = *ns; |
258 | fn = get_update_information_directory (h, ns); | 255 | fn = get_update_information_directory(h, ns); |
259 | if (GNUNET_YES != GNUNET_DISK_file_test (fn)) | 256 | if (GNUNET_YES != GNUNET_DISK_file_test(fn)) |
260 | { | 257 | { |
261 | GNUNET_free (fn); | 258 | GNUNET_free(fn); |
262 | return uig; | 259 | return uig; |
263 | } | 260 | } |
264 | rh = GNUNET_BIO_read_open (fn); | 261 | rh = GNUNET_BIO_read_open(fn); |
265 | if (NULL == rh) | 262 | if (NULL == rh) |
266 | { | 263 | { |
267 | GNUNET_free (fn); | 264 | GNUNET_free(fn); |
268 | return uig; | 265 | return uig; |
269 | } | 266 | } |
270 | if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &count)) | 267 | if (GNUNET_OK != GNUNET_BIO_read_int32(rh, &count)) |
271 | { | 268 | { |
272 | GNUNET_break (0); | 269 | GNUNET_break(0); |
273 | goto END; | 270 | goto END; |
274 | } | 271 | } |
275 | if (count > 1024 * 1024) | 272 | if (count > 1024 * 1024) |
276 | { | 273 | { |
277 | GNUNET_break (0); | 274 | GNUNET_break(0); |
278 | goto END; | 275 | goto END; |
279 | } | 276 | } |
280 | if (0 == count) | 277 | if (0 == count) |
281 | goto END; | 278 | goto END; |
282 | uig->update_nodes = | 279 | uig->update_nodes = |
283 | GNUNET_malloc (count * sizeof (struct NamespaceUpdateNode *)); | 280 | GNUNET_malloc(count * sizeof(struct NamespaceUpdateNode *)); |
284 | 281 | ||
285 | for (i = 0; i < count; i++) | 282 | for (i = 0; i < count; i++) |
286 | { | ||
287 | n = GNUNET_new (struct NamespaceUpdateNode); | ||
288 | if ((GNUNET_OK != | ||
289 | GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) || | ||
290 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) || | ||
291 | (GNUNET_OK != | ||
292 | GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) || | ||
293 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2))) | ||
294 | { | 283 | { |
295 | GNUNET_break (0); | 284 | n = GNUNET_new(struct NamespaceUpdateNode); |
296 | GNUNET_free_non_null (n->id); | 285 | if ((GNUNET_OK != |
297 | GNUNET_free_non_null (n->update); | 286 | GNUNET_BIO_read_string(rh, "identifier", &n->id, 1024)) || |
298 | if (n->md != NULL) | 287 | (GNUNET_OK != GNUNET_BIO_read_meta_data(rh, "meta", &n->md)) || |
299 | GNUNET_CONTAINER_meta_data_destroy (n->md); | 288 | (GNUNET_OK != |
300 | GNUNET_free (n); | 289 | GNUNET_BIO_read_string(rh, "update-id", &n->update, 1024)) || |
301 | break; | 290 | (GNUNET_OK != GNUNET_BIO_read_string(rh, "uri", &uris, 1024 * 2))) |
302 | } | 291 | { |
303 | n->uri = GNUNET_FS_uri_parse (uris, &emsg); | 292 | GNUNET_break(0); |
304 | GNUNET_free (uris); | 293 | GNUNET_free_non_null(n->id); |
305 | if (n->uri == NULL) | 294 | GNUNET_free_non_null(n->update); |
306 | { | 295 | if (n->md != NULL) |
307 | GNUNET_break (0); | 296 | GNUNET_CONTAINER_meta_data_destroy(n->md); |
308 | GNUNET_free (emsg); | 297 | GNUNET_free(n); |
309 | GNUNET_free (n->id); | 298 | break; |
310 | GNUNET_free_non_null (n->update); | 299 | } |
311 | GNUNET_CONTAINER_meta_data_destroy (n->md); | 300 | n->uri = GNUNET_FS_uri_parse(uris, &emsg); |
312 | GNUNET_free (n); | 301 | GNUNET_free(uris); |
313 | break; | 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; | ||
314 | } | 313 | } |
315 | uig->update_nodes[i] = n; | ||
316 | } | ||
317 | uig->update_node_count = i; | 314 | uig->update_node_count = i; |
318 | END: | 315 | END: |
319 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 316 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
320 | { | 317 | { |
321 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 318 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
322 | _ ("Failed to read `%s': %s\n"), | 319 | _("Failed to read `%s': %s\n"), |
323 | fn, | 320 | fn, |
324 | emsg); | 321 | emsg); |
325 | GNUNET_free (emsg); | 322 | GNUNET_free(emsg); |
326 | } | 323 | } |
327 | GNUNET_free (fn); | 324 | GNUNET_free(fn); |
328 | return uig; | 325 | return uig; |
329 | } | 326 | } |
330 | 327 | ||
@@ -332,9 +329,7 @@ END: | |||
332 | /** | 329 | /** |
333 | * Context for the SKS publication. | 330 | * Context for the SKS publication. |
334 | */ | 331 | */ |
335 | struct GNUNET_FS_PublishSksContext | 332 | struct GNUNET_FS_PublishSksContext { |
336 | { | ||
337 | |||
338 | /** | 333 | /** |
339 | * URI of the new entry in the namespace. | 334 | * URI of the new entry in the namespace. |
340 | */ | 335 | */ |
@@ -386,33 +381,33 @@ struct GNUNET_FS_PublishSksContext | |||
386 | * @param msg error message (or NULL) | 381 | * @param msg error message (or NULL) |
387 | */ | 382 | */ |
388 | static void | 383 | static void |
389 | sks_publish_cont (void *cls, const char *msg) | 384 | sks_publish_cont(void *cls, const char *msg) |
390 | { | 385 | { |
391 | struct GNUNET_FS_PublishSksContext *psc = cls; | 386 | struct GNUNET_FS_PublishSksContext *psc = cls; |
392 | struct GNUNET_FS_UpdateInformationGraph *uig; | 387 | struct GNUNET_FS_UpdateInformationGraph *uig; |
393 | 388 | ||
394 | psc->uc = NULL; | 389 | psc->uc = NULL; |
395 | if (NULL != msg) | 390 | if (NULL != msg) |
396 | { | 391 | { |
397 | if (NULL != psc->cont) | 392 | if (NULL != psc->cont) |
398 | psc->cont (psc->cont_cls, NULL, msg); | 393 | psc->cont(psc->cont_cls, NULL, msg); |
399 | GNUNET_FS_publish_sks_cancel (psc); | 394 | GNUNET_FS_publish_sks_cancel(psc); |
400 | return; | 395 | return; |
401 | } | 396 | } |
402 | if (NULL != psc->nsn) | 397 | if (NULL != psc->nsn) |
403 | { | 398 | { |
404 | /* FIXME: this can be done much more | 399 | /* FIXME: this can be done much more |
405 | * efficiently by simply appending to the | 400 | * efficiently by simply appending to the |
406 | * file and overwriting the 4-byte header */ | 401 | * file and overwriting the 4-byte header */ |
407 | uig = read_update_information_graph (psc->h, &psc->ns); | 402 | uig = read_update_information_graph(psc->h, &psc->ns); |
408 | GNUNET_array_append (uig->update_nodes, uig->update_node_count, psc->nsn); | 403 | GNUNET_array_append(uig->update_nodes, uig->update_node_count, psc->nsn); |
409 | psc->nsn = NULL; | 404 | psc->nsn = NULL; |
410 | write_update_information_graph (uig); | 405 | write_update_information_graph(uig); |
411 | free_update_information_graph (uig); | 406 | free_update_information_graph(uig); |
412 | } | 407 | } |
413 | if (NULL != psc->cont) | 408 | if (NULL != psc->cont) |
414 | psc->cont (psc->cont_cls, psc->uri, NULL); | 409 | psc->cont(psc->cont_cls, psc->uri, NULL); |
415 | GNUNET_FS_publish_sks_cancel (psc); | 410 | GNUNET_FS_publish_sks_cancel(psc); |
416 | } | 411 | } |
417 | 412 | ||
418 | 413 | ||
@@ -432,59 +427,59 @@ sks_publish_cont (void *cls, const char *msg) | |||
432 | * @return NULL on error ('cont' will still be called) | 427 | * @return NULL on error ('cont' will still be called) |
433 | */ | 428 | */ |
434 | struct GNUNET_FS_PublishSksContext * | 429 | struct GNUNET_FS_PublishSksContext * |
435 | GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, | 430 | GNUNET_FS_publish_sks(struct GNUNET_FS_Handle *h, |
436 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 431 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
437 | const char *identifier, | 432 | const char *identifier, |
438 | const char *update, | 433 | const char *update, |
439 | const struct GNUNET_CONTAINER_MetaData *meta, | 434 | const struct GNUNET_CONTAINER_MetaData *meta, |
440 | const struct GNUNET_FS_Uri *uri, | 435 | const struct GNUNET_FS_Uri *uri, |
441 | const struct GNUNET_FS_BlockOptions *bo, | 436 | const struct GNUNET_FS_BlockOptions *bo, |
442 | enum GNUNET_FS_PublishOptions options, | 437 | enum GNUNET_FS_PublishOptions options, |
443 | GNUNET_FS_PublishContinuation cont, | 438 | GNUNET_FS_PublishContinuation cont, |
444 | void *cont_cls) | 439 | void *cont_cls) |
445 | { | 440 | { |
446 | struct GNUNET_FS_PublishSksContext *psc; | 441 | struct GNUNET_FS_PublishSksContext *psc; |
447 | struct GNUNET_FS_Uri *sks_uri; | 442 | struct GNUNET_FS_Uri *sks_uri; |
448 | 443 | ||
449 | sks_uri = GNUNET_new (struct GNUNET_FS_Uri); | 444 | sks_uri = GNUNET_new(struct GNUNET_FS_Uri); |
450 | sks_uri->type = GNUNET_FS_URI_SKS; | 445 | sks_uri->type = GNUNET_FS_URI_SKS; |
451 | sks_uri->data.sks.identifier = GNUNET_strdup (identifier); | 446 | sks_uri->data.sks.identifier = GNUNET_strdup(identifier); |
452 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, &sks_uri->data.sks.ns); | 447 | GNUNET_CRYPTO_ecdsa_key_get_public(ns, &sks_uri->data.sks.ns); |
453 | 448 | ||
454 | psc = GNUNET_new (struct GNUNET_FS_PublishSksContext); | 449 | psc = GNUNET_new(struct GNUNET_FS_PublishSksContext); |
455 | psc->h = h; | 450 | psc->h = h; |
456 | psc->uri = sks_uri; | 451 | psc->uri = sks_uri; |
457 | psc->cont = cont; | 452 | psc->cont = cont; |
458 | psc->cont_cls = cont_cls; | 453 | psc->cont_cls = cont_cls; |
459 | psc->ns = *ns; | 454 | psc->ns = *ns; |
460 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) | 455 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) |
461 | { | ||
462 | psc->dsh = GNUNET_DATASTORE_connect (h->cfg); | ||
463 | if (NULL == psc->dsh) | ||
464 | { | 456 | { |
465 | sks_publish_cont (psc, _ ("Failed to connect to datastore.")); | 457 | psc->dsh = GNUNET_DATASTORE_connect(h->cfg); |
466 | return NULL; | 458 | if (NULL == psc->dsh) |
459 | { | ||
460 | sks_publish_cont(psc, _("Failed to connect to datastore.")); | ||
461 | return NULL; | ||
462 | } | ||
467 | } | 463 | } |
468 | } | ||
469 | if (NULL != update) | 464 | if (NULL != update) |
470 | { | 465 | { |
471 | psc->nsn = GNUNET_new (struct NamespaceUpdateNode); | 466 | psc->nsn = GNUNET_new(struct NamespaceUpdateNode); |
472 | psc->nsn->id = GNUNET_strdup (identifier); | 467 | psc->nsn->id = GNUNET_strdup(identifier); |
473 | psc->nsn->update = GNUNET_strdup (update); | 468 | psc->nsn->update = GNUNET_strdup(update); |
474 | psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta); | 469 | psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate(meta); |
475 | psc->nsn->uri = GNUNET_FS_uri_dup (uri); | 470 | psc->nsn->uri = GNUNET_FS_uri_dup(uri); |
476 | } | 471 | } |
477 | psc->uc = GNUNET_FS_publish_ublock_ (h, | 472 | psc->uc = GNUNET_FS_publish_ublock_(h, |
478 | psc->dsh, | 473 | psc->dsh, |
479 | identifier, | 474 | identifier, |
480 | update, | 475 | update, |
481 | ns, | 476 | ns, |
482 | meta, | 477 | meta, |
483 | uri, | 478 | uri, |
484 | bo, | 479 | bo, |
485 | options, | 480 | options, |
486 | &sks_publish_cont, | 481 | &sks_publish_cont, |
487 | psc); | 482 | psc); |
488 | return psc; | 483 | return psc; |
489 | } | 484 | } |
490 | 485 | ||
@@ -495,36 +490,35 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, | |||
495 | * @param psc context of the operation to abort. | 490 | * @param psc context of the operation to abort. |
496 | */ | 491 | */ |
497 | void | 492 | void |
498 | GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc) | 493 | GNUNET_FS_publish_sks_cancel(struct GNUNET_FS_PublishSksContext *psc) |
499 | { | 494 | { |
500 | if (NULL != psc->uc) | 495 | if (NULL != psc->uc) |
501 | { | 496 | { |
502 | GNUNET_FS_publish_ublock_cancel_ (psc->uc); | 497 | GNUNET_FS_publish_ublock_cancel_(psc->uc); |
503 | psc->uc = NULL; | 498 | psc->uc = NULL; |
504 | } | 499 | } |
505 | if (NULL != psc->dsh) | 500 | if (NULL != psc->dsh) |
506 | { | 501 | { |
507 | GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO); | 502 | GNUNET_DATASTORE_disconnect(psc->dsh, GNUNET_NO); |
508 | psc->dsh = NULL; | 503 | psc->dsh = NULL; |
509 | } | 504 | } |
510 | GNUNET_FS_uri_destroy (psc->uri); | 505 | GNUNET_FS_uri_destroy(psc->uri); |
511 | if (NULL != psc->nsn) | 506 | if (NULL != psc->nsn) |
512 | { | 507 | { |
513 | GNUNET_CONTAINER_meta_data_destroy (psc->nsn->md); | 508 | GNUNET_CONTAINER_meta_data_destroy(psc->nsn->md); |
514 | GNUNET_FS_uri_destroy (psc->nsn->uri); | 509 | GNUNET_FS_uri_destroy(psc->nsn->uri); |
515 | GNUNET_free (psc->nsn->id); | 510 | GNUNET_free(psc->nsn->id); |
516 | GNUNET_free (psc->nsn->update); | 511 | GNUNET_free(psc->nsn->update); |
517 | GNUNET_free (psc->nsn); | 512 | GNUNET_free(psc->nsn); |
518 | } | 513 | } |
519 | GNUNET_free (psc); | 514 | GNUNET_free(psc); |
520 | } | 515 | } |
521 | 516 | ||
522 | 517 | ||
523 | /** | 518 | /** |
524 | * Closure for 'process_update_node'. | 519 | * Closure for 'process_update_node'. |
525 | */ | 520 | */ |
526 | struct ProcessUpdateClosure | 521 | struct ProcessUpdateClosure { |
527 | { | ||
528 | /** | 522 | /** |
529 | * Function to call for each node. | 523 | * Function to call for each node. |
530 | */ | 524 | */ |
@@ -548,12 +542,12 @@ struct ProcessUpdateClosure | |||
548 | * GNUNET_NO if not. | 542 | * GNUNET_NO if not. |
549 | */ | 543 | */ |
550 | static int | 544 | static int |
551 | process_update_node (void *cls, const struct GNUNET_HashCode *key, void *value) | 545 | process_update_node(void *cls, const struct GNUNET_HashCode *key, void *value) |
552 | { | 546 | { |
553 | struct ProcessUpdateClosure *pc = cls; | 547 | struct ProcessUpdateClosure *pc = cls; |
554 | struct NamespaceUpdateNode *nsn = value; | 548 | struct NamespaceUpdateNode *nsn = value; |
555 | 549 | ||
556 | pc->ip (pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); | 550 | pc->ip(pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); |
557 | return GNUNET_YES; | 551 | return GNUNET_YES; |
558 | } | 552 | } |
559 | 553 | ||
@@ -561,8 +555,7 @@ process_update_node (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
561 | /** | 555 | /** |
562 | * Closure for 'find_trees'. | 556 | * Closure for 'find_trees'. |
563 | */ | 557 | */ |
564 | struct FindTreeClosure | 558 | struct FindTreeClosure { |
565 | { | ||
566 | /** | 559 | /** |
567 | * UIG we are operating on. | 560 | * UIG we are operating on. |
568 | */ | 561 | */ |
@@ -611,38 +604,38 @@ struct FindTreeClosure | |||
611 | * GNUNET_NO if not. | 604 | * GNUNET_NO if not. |
612 | */ | 605 | */ |
613 | static int | 606 | static int |
614 | find_trees (void *cls, const struct GNUNET_HashCode *key, void *value) | 607 | find_trees(void *cls, const struct GNUNET_HashCode *key, void *value) |
615 | { | 608 | { |
616 | struct FindTreeClosure *fc = cls; | 609 | struct FindTreeClosure *fc = cls; |
617 | struct NamespaceUpdateNode *nsn = value; | 610 | struct NamespaceUpdateNode *nsn = value; |
618 | struct GNUNET_HashCode hc; | 611 | struct GNUNET_HashCode hc; |
619 | 612 | ||
620 | if (nsn->nug == fc->nug) | 613 | if (nsn->nug == fc->nug) |
621 | { | 614 | { |
622 | if (UINT_MAX == nsn->tree_id) | 615 | if (UINT_MAX == nsn->tree_id) |
623 | return GNUNET_YES; /* circular */ | 616 | return GNUNET_YES; /* circular */ |
624 | GNUNET_assert (nsn->tree_id < fc->tree_array_size); | 617 | GNUNET_assert(nsn->tree_id < fc->tree_array_size); |
625 | if (fc->tree_array[nsn->tree_id] != nsn) | 618 | if (fc->tree_array[nsn->tree_id] != nsn) |
626 | return GNUNET_YES; /* part of "another" (directed) TREE, | 619 | return GNUNET_YES; /* part of "another" (directed) TREE, |
627 | * and not root of it, end trace */ | 620 | * and not root of it, end trace */ |
628 | if (nsn->tree_id == fc->id) | 621 | if (nsn->tree_id == fc->id) |
629 | return GNUNET_YES; /* that's our own root (can this be?) */ | 622 | return GNUNET_YES; /* that's our own root (can this be?) */ |
630 | /* merge existing TREE, we have a root for both */ | 623 | /* merge existing TREE, we have a root for both */ |
631 | fc->tree_array[nsn->tree_id] = NULL; | 624 | fc->tree_array[nsn->tree_id] = NULL; |
632 | if (UINT_MAX == fc->id) | 625 | if (UINT_MAX == fc->id) |
633 | fc->id = nsn->tree_id; /* take over ID */ | 626 | fc->id = nsn->tree_id; /* take over ID */ |
634 | } | 627 | } |
635 | else | 628 | else |
636 | { | 629 | { |
637 | nsn->nug = fc->nug; | 630 | nsn->nug = fc->nug; |
638 | nsn->tree_id = UINT_MAX; /* mark as undef */ | 631 | nsn->tree_id = UINT_MAX; /* mark as undef */ |
639 | /* trace */ | 632 | /* trace */ |
640 | GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); | 633 | GNUNET_CRYPTO_hash(nsn->update, strlen(nsn->update), &hc); |
641 | GNUNET_CONTAINER_multihashmap_get_multiple (fc->uig->update_map, | 634 | GNUNET_CONTAINER_multihashmap_get_multiple(fc->uig->update_map, |
642 | &hc, | 635 | &hc, |
643 | &find_trees, | 636 | &find_trees, |
644 | fc); | 637 | fc); |
645 | } | 638 | } |
646 | return GNUNET_YES; | 639 | return GNUNET_YES; |
647 | } | 640 | } |
648 | 641 | ||
@@ -671,7 +664,7 @@ find_trees (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
671 | * @param ip_cls closure for ip | 664 | * @param ip_cls closure for ip |
672 | */ | 665 | */ |
673 | void | 666 | void |
674 | GNUNET_FS_namespace_list_updateable ( | 667 | GNUNET_FS_namespace_list_updateable( |
675 | struct GNUNET_FS_Handle *h, | 668 | struct GNUNET_FS_Handle *h, |
676 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 669 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
677 | const char *next_id, | 670 | const char *next_id, |
@@ -686,125 +679,125 @@ GNUNET_FS_namespace_list_updateable ( | |||
686 | struct FindTreeClosure fc; | 679 | struct FindTreeClosure fc; |
687 | struct GNUNET_FS_UpdateInformationGraph *uig; | 680 | struct GNUNET_FS_UpdateInformationGraph *uig; |
688 | 681 | ||
689 | uig = read_update_information_graph (h, ns); | 682 | uig = read_update_information_graph(h, ns); |
690 | if (NULL == uig->update_nodes) | 683 | if (NULL == uig->update_nodes) |
691 | { | 684 | { |
692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 685 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
693 | "No updateable nodes found for ID `%s'\n", | 686 | "No updateable nodes found for ID `%s'\n", |
694 | next_id); | 687 | next_id); |
695 | free_update_information_graph (uig); | 688 | free_update_information_graph(uig); |
696 | return; /* no nodes */ | 689 | return; /* no nodes */ |
697 | } | 690 | } |
698 | uig->update_map = | 691 | uig->update_map = |
699 | GNUNET_CONTAINER_multihashmap_create (2 + 3 * uig->update_node_count / 4, | 692 | GNUNET_CONTAINER_multihashmap_create(2 + 3 * uig->update_node_count / 4, |
700 | GNUNET_NO); | 693 | GNUNET_NO); |
701 | for (i = 0; i < uig->update_node_count; i++) | 694 | for (i = 0; i < uig->update_node_count; i++) |
702 | { | 695 | { |
703 | nsn = uig->update_nodes[i]; | 696 | nsn = uig->update_nodes[i]; |
704 | GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); | 697 | GNUNET_CRYPTO_hash(nsn->id, strlen(nsn->id), &hc); |
705 | GNUNET_CONTAINER_multihashmap_put ( | 698 | GNUNET_CONTAINER_multihashmap_put( |
706 | uig->update_map, | 699 | uig->update_map, |
707 | &hc, | 700 | &hc, |
708 | nsn, | 701 | nsn, |
709 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 702 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
710 | } | 703 | } |
711 | if (NULL != next_id) | 704 | if (NULL != next_id) |
712 | { | 705 | { |
713 | GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc); | 706 | GNUNET_CRYPTO_hash(next_id, strlen(next_id), &hc); |
714 | pc.ip = ip; | 707 | pc.ip = ip; |
715 | pc.ip_cls = ip_cls; | 708 | pc.ip_cls = ip_cls; |
716 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, | 709 | GNUNET_CONTAINER_multihashmap_get_multiple(uig->update_map, |
717 | &hc, | 710 | &hc, |
718 | &process_update_node, | 711 | &process_update_node, |
719 | &pc); | 712 | &pc); |
720 | free_update_information_graph (uig); | 713 | free_update_information_graph(uig); |
721 | return; | 714 | return; |
722 | } | 715 | } |
723 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 716 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
724 | "Calculating TREEs to find roots of update trees\n"); | 717 | "Calculating TREEs to find roots of update trees\n"); |
725 | /* Find heads of TREEs in update graph */ | 718 | /* Find heads of TREEs in update graph */ |
726 | nug = ++uig->nug_gen; | 719 | nug = ++uig->nug_gen; |
727 | fc.tree_array = NULL; | 720 | fc.tree_array = NULL; |
728 | fc.tree_array_size = 0; | 721 | fc.tree_array_size = 0; |
729 | 722 | ||
730 | for (i = 0; i < uig->update_node_count; i++) | 723 | for (i = 0; i < uig->update_node_count; i++) |
731 | { | ||
732 | nsn = uig->update_nodes[i]; | ||
733 | if (nsn->nug == nug) | ||
734 | { | ||
735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
736 | "TREE of node `%s' is %u\n", | ||
737 | nsn->id, | ||
738 | nsn->nug); | ||
739 | continue; /* already placed in TREE */ | ||
740 | } | ||
741 | GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); | ||
742 | nsn->nug = nug; | ||
743 | nsn->tree_id = UINT_MAX; | ||
744 | fc.id = UINT_MAX; | ||
745 | fc.nug = nug; | ||
746 | fc.uig = uig; | ||
747 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, | ||
748 | &hc, | ||
749 | &find_trees, | ||
750 | &fc); | ||
751 | if (UINT_MAX == fc.id) | ||
752 | { | 724 | { |
753 | /* start new TREE */ | 725 | nsn = uig->update_nodes[i]; |
754 | for (fc.id = 0; fc.id < fc.tree_array_size; fc.id++) | 726 | if (nsn->nug == nug) |
755 | { | ||
756 | if (NULL == fc.tree_array[fc.id]) | ||
757 | { | 727 | { |
758 | fc.tree_array[fc.id] = nsn; | 728 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
759 | nsn->tree_id = fc.id; | 729 | "TREE of node `%s' is %u\n", |
760 | break; | 730 | nsn->id, |
731 | nsn->nug); | ||
732 | continue; /* already placed in TREE */ | ||
761 | } | 733 | } |
762 | } | 734 | GNUNET_CRYPTO_hash(nsn->update, strlen(nsn->update), &hc); |
763 | if (fc.id == fc.tree_array_size) | 735 | nsn->nug = nug; |
764 | { | 736 | nsn->tree_id = UINT_MAX; |
765 | GNUNET_array_append (fc.tree_array, fc.tree_array_size, nsn); | 737 | fc.id = UINT_MAX; |
766 | nsn->tree_id = fc.id; | ||
767 | } | ||
768 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
769 | "Starting new TREE %u with node `%s'\n", | ||
770 | nsn->tree_id, | ||
771 | nsn->id); | ||
772 | /* put all nodes with same identifier into this TREE */ | ||
773 | GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); | ||
774 | fc.id = nsn->tree_id; | ||
775 | fc.nug = nug; | 738 | fc.nug = nug; |
776 | fc.uig = uig; | 739 | fc.uig = uig; |
777 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, | 740 | GNUNET_CONTAINER_multihashmap_get_multiple(uig->update_map, |
778 | &hc, | 741 | &hc, |
779 | &find_trees, | 742 | &find_trees, |
780 | &fc); | 743 | &fc); |
781 | } | 744 | if (UINT_MAX == fc.id) |
782 | else | 745 | { |
783 | { | 746 | /* start new TREE */ |
784 | /* make head of TREE "id" */ | 747 | for (fc.id = 0; fc.id < fc.tree_array_size; fc.id++) |
785 | fc.tree_array[fc.id] = nsn; | 748 | { |
786 | nsn->tree_id = fc.id; | 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 | { | ||
777 | /* make head of TREE "id" */ | ||
778 | fc.tree_array[fc.id] = nsn; | ||
779 | nsn->tree_id = fc.id; | ||
780 | } | ||
781 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
782 | "TREE of node `%s' is %u\n", | ||
783 | nsn->id, | ||
784 | fc.id); | ||
787 | } | 785 | } |
788 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
789 | "TREE of node `%s' is %u\n", | ||
790 | nsn->id, | ||
791 | fc.id); | ||
792 | } | ||
793 | for (i = 0; i < fc.tree_array_size; i++) | 786 | for (i = 0; i < fc.tree_array_size; i++) |
794 | { | ||
795 | nsn = fc.tree_array[i]; | ||
796 | if (NULL != nsn) | ||
797 | { | 787 | { |
798 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 788 | nsn = fc.tree_array[i]; |
799 | "Root of TREE %u is node `%s'\n", | 789 | if (NULL != nsn) |
800 | i, | 790 | { |
801 | nsn->id); | 791 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
802 | ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); | 792 | "Root of TREE %u is node `%s'\n", |
793 | i, | ||
794 | nsn->id); | ||
795 | ip(ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); | ||
796 | } | ||
803 | } | 797 | } |
804 | } | 798 | GNUNET_array_grow(fc.tree_array, fc.tree_array_size, 0); |
805 | GNUNET_array_grow (fc.tree_array, fc.tree_array_size, 0); | 799 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Done processing TREEs\n"); |
806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done processing TREEs\n"); | 800 | free_update_information_graph(uig); |
807 | free_update_information_graph (uig); | ||
808 | } | 801 | } |
809 | 802 | ||
810 | 803 | ||
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 71ab1122c..b599bb06e 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/fs_publish.c | 21 | * @file fs/fs_publish.c |
22 | * @brief publish a file or directory in GNUnet | 22 | * @brief publish a file or directory in GNUnet |
@@ -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,16 @@ 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 : p->data.file.file_size; |
59 | pi->value.publish.eta = | 59 | pi->value.publish.eta = |
60 | GNUNET_TIME_calculate_eta (p->start_time, offset, | 60 | GNUNET_TIME_calculate_eta(p->start_time, offset, |
61 | pi->value.publish.size); | 61 | pi->value.publish.size); |
62 | pi->value.publish.completed = offset; | 62 | pi->value.publish.completed = offset; |
63 | pi->value.publish.duration = | 63 | pi->value.publish.duration = |
64 | GNUNET_TIME_absolute_get_duration (p->start_time); | 64 | GNUNET_TIME_absolute_get_duration(p->start_time); |
65 | pi->value.publish.anonymity = p->bo.anonymity_level; | 65 | pi->value.publish.anonymity = p->bo.anonymity_level; |
66 | pi->fsh = pc->h; | 66 | pi->fsh = pc->h; |
67 | return pc->h->upcb (pc->h->upcb_cls, pi); | 67 | return pc->h->upcb(pc->h->upcb_cls, pi); |
68 | } | 68 | } |
69 | 69 | ||
70 | 70 | ||
@@ -74,31 +74,31 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
74 | * @param pc struct to clean up | 74 | * @param pc struct to clean up |
75 | */ | 75 | */ |
76 | static void | 76 | static void |
77 | publish_cleanup (struct GNUNET_FS_PublishContext *pc) | 77 | publish_cleanup(struct GNUNET_FS_PublishContext *pc) |
78 | { | 78 | { |
79 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 79 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
80 | "Cleaning up publish context (done!)\n"); | 80 | "Cleaning up publish context (done!)\n"); |
81 | if (NULL != pc->fhc) | 81 | if (NULL != pc->fhc) |
82 | { | 82 | { |
83 | GNUNET_CRYPTO_hash_file_cancel (pc->fhc); | 83 | GNUNET_CRYPTO_hash_file_cancel(pc->fhc); |
84 | pc->fhc = NULL; | 84 | pc->fhc = NULL; |
85 | } | 85 | } |
86 | GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); | 86 | GNUNET_FS_file_information_destroy(pc->fi, NULL, NULL); |
87 | GNUNET_free_non_null (pc->nid); | 87 | GNUNET_free_non_null(pc->nid); |
88 | GNUNET_free_non_null (pc->nuid); | 88 | GNUNET_free_non_null(pc->nuid); |
89 | GNUNET_free_non_null (pc->serialization); | 89 | GNUNET_free_non_null(pc->serialization); |
90 | if (NULL != pc->dsh) | 90 | if (NULL != pc->dsh) |
91 | { | 91 | { |
92 | GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO); | 92 | GNUNET_DATASTORE_disconnect(pc->dsh, GNUNET_NO); |
93 | pc->dsh = NULL; | 93 | pc->dsh = NULL; |
94 | } | 94 | } |
95 | if (NULL != pc->mq) | 95 | if (NULL != pc->mq) |
96 | { | 96 | { |
97 | GNUNET_MQ_destroy (pc->mq); | 97 | GNUNET_MQ_destroy(pc->mq); |
98 | pc->mq = NULL; | 98 | pc->mq = NULL; |
99 | } | 99 | } |
100 | GNUNET_assert (NULL == pc->upload_task); | 100 | GNUNET_assert(NULL == pc->upload_task); |
101 | GNUNET_free (pc); | 101 | GNUNET_free(pc); |
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
@@ -112,42 +112,42 @@ publish_cleanup (struct GNUNET_FS_PublishContext *pc) | |||
112 | * @param msg error message (or NULL) | 112 | * @param msg error message (or NULL) |
113 | */ | 113 | */ |
114 | static void | 114 | static void |
115 | ds_put_cont (void *cls, | 115 | ds_put_cont(void *cls, |
116 | int success, | 116 | int success, |
117 | struct GNUNET_TIME_Absolute min_expiration, | 117 | struct GNUNET_TIME_Absolute min_expiration, |
118 | const char *msg) | 118 | const char *msg) |
119 | { | 119 | { |
120 | struct GNUNET_FS_PublishContext *pc = cls; | 120 | struct GNUNET_FS_PublishContext *pc = cls; |
121 | struct GNUNET_FS_ProgressInfo pi; | 121 | struct GNUNET_FS_ProgressInfo pi; |
122 | 122 | ||
123 | pc->qre = NULL; | 123 | pc->qre = NULL; |
124 | if (GNUNET_SYSERR == success) | 124 | if (GNUNET_SYSERR == success) |
125 | { | ||
126 | GNUNET_asprintf (&pc->fi_pos->emsg, | ||
127 | _("Publishing failed: %s"), | ||
128 | msg); | ||
129 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | ||
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 | { | 125 | { |
139 | /* run unindex to clean up */ | 126 | GNUNET_asprintf(&pc->fi_pos->emsg, |
140 | GNUNET_FS_unindex_start (pc->h, | 127 | _("Publishing failed: %s"), |
141 | pc->fi_pos->filename, | 128 | msg); |
142 | NULL); | 129 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; |
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; | ||
143 | } | 145 | } |
144 | return; | ||
145 | } | ||
146 | pc->any_done = GNUNET_YES; | 146 | pc->any_done = GNUNET_YES; |
147 | GNUNET_assert (NULL == pc->upload_task); | 147 | GNUNET_assert(NULL == pc->upload_task); |
148 | pc->upload_task = | 148 | pc->upload_task = |
149 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 149 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
150 | &GNUNET_FS_publish_main_, pc); | 150 | &GNUNET_FS_publish_main_, pc); |
151 | } | 151 | } |
152 | 152 | ||
153 | 153 | ||
@@ -160,8 +160,8 @@ ds_put_cont (void *cls, | |||
160 | * @param pc context of the publication | 160 | * @param pc context of the publication |
161 | */ | 161 | */ |
162 | static void | 162 | static void |
163 | signal_publish_completion (struct GNUNET_FS_FileInformation *p, | 163 | signal_publish_completion(struct GNUNET_FS_FileInformation *p, |
164 | struct GNUNET_FS_PublishContext *pc) | 164 | struct GNUNET_FS_PublishContext *pc) |
165 | { | 165 | { |
166 | struct GNUNET_FS_ProgressInfo pi; | 166 | struct GNUNET_FS_ProgressInfo pi; |
167 | 167 | ||
@@ -170,8 +170,8 @@ signal_publish_completion (struct GNUNET_FS_FileInformation *p, | |||
170 | pi.value.publish.specifics.completed.chk_uri = p->chk_uri; | 170 | pi.value.publish.specifics.completed.chk_uri = p->chk_uri; |
171 | pi.value.publish.specifics.completed.sks_uri = p->sks_uri; | 171 | pi.value.publish.specifics.completed.sks_uri = p->sks_uri; |
172 | p->client_info = | 172 | p->client_info = |
173 | GNUNET_FS_publish_make_status_ (&pi, pc, p, | 173 | GNUNET_FS_publish_make_status_(&pi, pc, p, |
174 | p->data.file.file_size); | 174 | p->data.file.file_size); |
175 | } | 175 | } |
176 | 176 | ||
177 | 177 | ||
@@ -185,28 +185,27 @@ signal_publish_completion (struct GNUNET_FS_FileInformation *p, | |||
185 | * @param emsg error message | 185 | * @param emsg error message |
186 | */ | 186 | */ |
187 | static void | 187 | static void |
188 | signal_publish_error (struct GNUNET_FS_FileInformation *p, | 188 | signal_publish_error(struct GNUNET_FS_FileInformation *p, |
189 | struct GNUNET_FS_PublishContext *pc, | 189 | struct GNUNET_FS_PublishContext *pc, |
190 | const char *emsg) | 190 | const char *emsg) |
191 | { | 191 | { |
192 | struct GNUNET_FS_ProgressInfo pi; | 192 | struct GNUNET_FS_ProgressInfo pi; |
193 | 193 | ||
194 | p->emsg = GNUNET_strdup (emsg); | 194 | p->emsg = GNUNET_strdup(emsg); |
195 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | 195 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; |
196 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 196 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
197 | pi.value.publish.specifics.error.message = emsg; | 197 | pi.value.publish.specifics.error.message = emsg; |
198 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); | 198 | p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); |
199 | if ((p->is_directory != GNUNET_YES) && | 199 | if ((p->is_directory != GNUNET_YES) && |
200 | (NULL != p->filename) && | 200 | (NULL != p->filename) && |
201 | (GNUNET_YES == pc->any_done) && | 201 | (GNUNET_YES == pc->any_done) && |
202 | (p->data.file.do_index == GNUNET_YES)) | 202 | (p->data.file.do_index == GNUNET_YES)) |
203 | { | 203 | { |
204 | /* run unindex to clean up */ | 204 | /* run unindex to clean up */ |
205 | GNUNET_FS_unindex_start (pc->h, | 205 | GNUNET_FS_unindex_start(pc->h, |
206 | p->filename, | 206 | p->filename, |
207 | NULL); | 207 | NULL); |
208 | } | 208 | } |
209 | |||
210 | } | 209 | } |
211 | 210 | ||
212 | 211 | ||
@@ -219,18 +218,18 @@ signal_publish_error (struct GNUNET_FS_FileInformation *p, | |||
219 | * @param msg error message (typically NULL, not used) | 218 | * @param msg error message (typically NULL, not used) |
220 | */ | 219 | */ |
221 | static void | 220 | static void |
222 | finish_release_reserve (void *cls, int success, | 221 | finish_release_reserve(void *cls, int success, |
223 | struct GNUNET_TIME_Absolute min_expiration, | 222 | struct GNUNET_TIME_Absolute min_expiration, |
224 | const char *msg) | 223 | const char *msg) |
225 | { | 224 | { |
226 | struct GNUNET_FS_PublishContext *pc = cls; | 225 | struct GNUNET_FS_PublishContext *pc = cls; |
227 | 226 | ||
228 | pc->qre = NULL; | 227 | pc->qre = NULL; |
229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 228 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
230 | "Releasing reserve done!\n"); | 229 | "Releasing reserve done!\n"); |
231 | signal_publish_completion (pc->fi, pc); | 230 | signal_publish_completion(pc->fi, pc); |
232 | pc->all_done = GNUNET_YES; | 231 | pc->all_done = GNUNET_YES; |
233 | GNUNET_FS_publish_sync_ (pc); | 232 | GNUNET_FS_publish_sync_(pc); |
234 | } | 233 | } |
235 | 234 | ||
236 | 235 | ||
@@ -243,35 +242,35 @@ finish_release_reserve (void *cls, int success, | |||
243 | * @param emsg NULL on success, otherwise error message | 242 | * @param emsg NULL on success, otherwise error message |
244 | */ | 243 | */ |
245 | static void | 244 | static void |
246 | publish_sblocks_cont (void *cls, | 245 | publish_sblocks_cont(void *cls, |
247 | const struct GNUNET_FS_Uri *uri, | 246 | const struct GNUNET_FS_Uri *uri, |
248 | const char *emsg) | 247 | const char *emsg) |
249 | { | 248 | { |
250 | struct GNUNET_FS_PublishContext *pc = cls; | 249 | struct GNUNET_FS_PublishContext *pc = cls; |
251 | 250 | ||
252 | pc->sks_pc = NULL; | 251 | pc->sks_pc = NULL; |
253 | if (NULL != emsg) | 252 | if (NULL != emsg) |
254 | { | 253 | { |
255 | signal_publish_error (pc->fi, pc, emsg); | 254 | signal_publish_error(pc->fi, pc, emsg); |
256 | GNUNET_FS_publish_sync_ (pc); | 255 | GNUNET_FS_publish_sync_(pc); |
257 | return; | 256 | return; |
258 | } | 257 | } |
259 | if (NULL != uri) | 258 | if (NULL != uri) |
260 | { | 259 | { |
261 | /* sks publication, remember namespace URI */ | 260 | /* sks publication, remember namespace URI */ |
262 | pc->fi->sks_uri = GNUNET_FS_uri_dup (uri); | 261 | pc->fi->sks_uri = GNUNET_FS_uri_dup(uri); |
263 | } | 262 | } |
264 | GNUNET_assert (pc->qre == NULL); | 263 | GNUNET_assert(pc->qre == NULL); |
265 | if ((pc->dsh != NULL) && (pc->rid != 0)) | 264 | if ((pc->dsh != NULL) && (pc->rid != 0)) |
266 | { | 265 | { |
267 | pc->qre = | 266 | pc->qre = |
268 | GNUNET_DATASTORE_release_reserve (pc->dsh, pc->rid, UINT_MAX, UINT_MAX, | 267 | GNUNET_DATASTORE_release_reserve(pc->dsh, pc->rid, UINT_MAX, UINT_MAX, |
269 | &finish_release_reserve, pc); | 268 | &finish_release_reserve, pc); |
270 | } | 269 | } |
271 | else | 270 | else |
272 | { | 271 | { |
273 | finish_release_reserve (pc, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, NULL); | 272 | finish_release_reserve(pc, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, NULL); |
274 | } | 273 | } |
275 | } | 274 | } |
276 | 275 | ||
277 | 276 | ||
@@ -282,20 +281,20 @@ publish_sblocks_cont (void *cls, | |||
282 | * @param pc overall upload data | 281 | * @param pc overall upload data |
283 | */ | 282 | */ |
284 | static void | 283 | static void |
285 | publish_sblock (struct GNUNET_FS_PublishContext *pc) | 284 | publish_sblock(struct GNUNET_FS_PublishContext *pc) |
286 | { | 285 | { |
287 | if (NULL != pc->ns) | 286 | if (NULL != pc->ns) |
288 | pc->sks_pc = GNUNET_FS_publish_sks (pc->h, | 287 | pc->sks_pc = GNUNET_FS_publish_sks(pc->h, |
289 | pc->ns, | 288 | pc->ns, |
290 | pc->nid, | 289 | pc->nid, |
291 | pc->nuid, | 290 | pc->nuid, |
292 | pc->fi->meta, | 291 | pc->fi->meta, |
293 | pc->fi->chk_uri, | 292 | pc->fi->chk_uri, |
294 | &pc->fi->bo, | 293 | &pc->fi->bo, |
295 | pc->options, | 294 | pc->options, |
296 | &publish_sblocks_cont, pc); | 295 | &publish_sblocks_cont, pc); |
297 | else | 296 | else |
298 | publish_sblocks_cont (pc, NULL, NULL); | 297 | publish_sblocks_cont(pc, NULL, NULL); |
299 | } | 298 | } |
300 | 299 | ||
301 | 300 | ||
@@ -309,44 +308,44 @@ publish_sblock (struct GNUNET_FS_PublishContext *pc) | |||
309 | * @param emsg NULL on success, otherwise error message | 308 | * @param emsg NULL on success, otherwise error message |
310 | */ | 309 | */ |
311 | static void | 310 | static void |
312 | publish_kblocks_cont (void *cls, | 311 | publish_kblocks_cont(void *cls, |
313 | const struct GNUNET_FS_Uri *uri, | 312 | const struct GNUNET_FS_Uri *uri, |
314 | const char *emsg) | 313 | const char *emsg) |
315 | { | 314 | { |
316 | struct GNUNET_FS_PublishContext *pc = cls; | 315 | struct GNUNET_FS_PublishContext *pc = cls; |
317 | struct GNUNET_FS_FileInformation *p = pc->fi_pos; | 316 | struct GNUNET_FS_FileInformation *p = pc->fi_pos; |
318 | 317 | ||
319 | pc->ksk_pc = NULL; | 318 | pc->ksk_pc = NULL; |
320 | if (NULL != emsg) | 319 | if (NULL != emsg) |
321 | { | 320 | { |
322 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 321 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
323 | "Error uploading KSK blocks: %s\n", | 322 | "Error uploading KSK blocks: %s\n", |
324 | emsg); | 323 | emsg); |
325 | signal_publish_error (p, pc, emsg); | 324 | signal_publish_error(p, pc, emsg); |
326 | GNUNET_FS_file_information_sync_ (p); | 325 | GNUNET_FS_file_information_sync_(p); |
327 | GNUNET_FS_publish_sync_ (pc); | 326 | GNUNET_FS_publish_sync_(pc); |
328 | GNUNET_assert (NULL == pc->upload_task); | 327 | GNUNET_assert(NULL == pc->upload_task); |
329 | pc->upload_task = | 328 | pc->upload_task = |
330 | GNUNET_SCHEDULER_add_with_priority | 329 | GNUNET_SCHEDULER_add_with_priority |
331 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 330 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
332 | &GNUNET_FS_publish_main_, | 331 | &GNUNET_FS_publish_main_, |
333 | pc); | 332 | pc); |
334 | return; | 333 | return; |
335 | } | 334 | } |
336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 335 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
337 | "KSK blocks published, moving on to next file\n"); | 336 | "KSK blocks published, moving on to next file\n"); |
338 | if (NULL != p->dir) | 337 | if (NULL != p->dir) |
339 | signal_publish_completion (p, pc); | 338 | signal_publish_completion(p, pc); |
340 | /* move on to next file */ | 339 | /* move on to next file */ |
341 | if (NULL != p->next) | 340 | if (NULL != p->next) |
342 | pc->fi_pos = p->next; | 341 | pc->fi_pos = p->next; |
343 | else | 342 | else |
344 | pc->fi_pos = p->dir; | 343 | pc->fi_pos = p->dir; |
345 | GNUNET_FS_publish_sync_ (pc); | 344 | GNUNET_FS_publish_sync_(pc); |
346 | GNUNET_assert (NULL == pc->upload_task); | 345 | GNUNET_assert(NULL == pc->upload_task); |
347 | pc->upload_task = | 346 | pc->upload_task = |
348 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 347 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
349 | &GNUNET_FS_publish_main_, pc); | 348 | &GNUNET_FS_publish_main_, pc); |
350 | } | 349 | } |
351 | 350 | ||
352 | 351 | ||
@@ -364,11 +363,11 @@ publish_kblocks_cont (void *cls, | |||
364 | * @return number of bytes copied to buf, 0 on error | 363 | * @return number of bytes copied to buf, 0 on error |
365 | */ | 364 | */ |
366 | static size_t | 365 | static size_t |
367 | block_reader (void *cls, | 366 | block_reader(void *cls, |
368 | uint64_t offset, | 367 | uint64_t offset, |
369 | size_t max, | 368 | size_t max, |
370 | void *buf, | 369 | void *buf, |
371 | char **emsg) | 370 | char **emsg) |
372 | { | 371 | { |
373 | struct GNUNET_FS_PublishContext *pc = cls; | 372 | struct GNUNET_FS_PublishContext *pc = cls; |
374 | struct GNUNET_FS_FileInformation *p; | 373 | struct GNUNET_FS_FileInformation *p; |
@@ -377,31 +376,31 @@ block_reader (void *cls, | |||
377 | 376 | ||
378 | p = pc->fi_pos; | 377 | p = pc->fi_pos; |
379 | if (GNUNET_YES == p->is_directory) | 378 | if (GNUNET_YES == p->is_directory) |
380 | { | 379 | { |
381 | pt_size = GNUNET_MIN (max, p->data.dir.dir_size - offset); | 380 | pt_size = GNUNET_MIN(max, p->data.dir.dir_size - offset); |
382 | dd = p->data.dir.dir_data; | 381 | dd = p->data.dir.dir_data; |
383 | GNUNET_memcpy (buf, &dd[offset], pt_size); | 382 | GNUNET_memcpy(buf, &dd[offset], pt_size); |
384 | } | 383 | } |
385 | else | 384 | else |
386 | { | 385 | { |
387 | if (UINT64_MAX == offset) | 386 | if (UINT64_MAX == offset) |
388 | { | 387 | { |
389 | if (&GNUNET_FS_data_reader_file_ == p->data.file.reader) | 388 | if (&GNUNET_FS_data_reader_file_ == p->data.file.reader) |
390 | { | 389 | { |
391 | /* force closing the file to avoid keeping too many files open */ | 390 | /* force closing the file to avoid keeping too many files open */ |
392 | p->data.file.reader (p->data.file.reader_cls, offset, 0, NULL, NULL); | 391 | p->data.file.reader(p->data.file.reader_cls, offset, 0, NULL, NULL); |
393 | } | 392 | } |
394 | return 0; | 393 | return 0; |
395 | } | 394 | } |
396 | pt_size = GNUNET_MIN (max, p->data.file.file_size - offset); | 395 | pt_size = GNUNET_MIN(max, p->data.file.file_size - offset); |
397 | if (0 == pt_size) | 396 | if (0 == pt_size) |
398 | return 0; /* calling reader with pt_size==0 | 397 | return 0; /* calling reader with pt_size==0 |
399 | * might free buf, so don't! */ | 398 | * might free buf, so don't! */ |
400 | if (pt_size != | 399 | if (pt_size != |
401 | p->data.file.reader (p->data.file.reader_cls, offset, pt_size, buf, | 400 | p->data.file.reader(p->data.file.reader_cls, offset, pt_size, buf, |
402 | emsg)) | 401 | emsg)) |
403 | return 0; | 402 | return 0; |
404 | } | 403 | } |
405 | return pt_size; | 404 | return pt_size; |
406 | } | 405 | } |
407 | 406 | ||
@@ -414,7 +413,7 @@ block_reader (void *cls, | |||
414 | * @param cls our publishing context | 413 | * @param cls our publishing context |
415 | */ | 414 | */ |
416 | static void | 415 | static void |
417 | encode_cont (void *cls) | 416 | encode_cont(void *cls) |
418 | { | 417 | { |
419 | struct GNUNET_FS_PublishContext *pc = cls; | 418 | struct GNUNET_FS_PublishContext *pc = cls; |
420 | struct GNUNET_FS_FileInformation *p; | 419 | struct GNUNET_FS_FileInformation *p; |
@@ -422,44 +421,44 @@ encode_cont (void *cls) | |||
422 | char *emsg; | 421 | char *emsg; |
423 | uint64_t flen; | 422 | uint64_t flen; |
424 | 423 | ||
425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 424 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
426 | "Finished with tree encoder\n"); | 425 | "Finished with tree encoder\n"); |
427 | p = pc->fi_pos; | 426 | p = pc->fi_pos; |
428 | p->chk_uri = GNUNET_FS_tree_encoder_get_uri (p->te); | 427 | p->chk_uri = GNUNET_FS_tree_encoder_get_uri(p->te); |
429 | GNUNET_FS_file_information_sync_ (p); | 428 | GNUNET_FS_file_information_sync_(p); |
430 | GNUNET_FS_tree_encoder_finish (p->te, &emsg); | 429 | GNUNET_FS_tree_encoder_finish(p->te, &emsg); |
431 | p->te = NULL; | 430 | p->te = NULL; |
432 | if (NULL != emsg) | 431 | if (NULL != emsg) |
433 | { | 432 | { |
434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 433 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
435 | "Error during tree walk: %s\n", | 434 | "Error during tree walk: %s\n", |
436 | emsg); | 435 | emsg); |
437 | GNUNET_asprintf (&p->emsg, | 436 | GNUNET_asprintf(&p->emsg, |
438 | _("Publishing failed: %s"), | 437 | _("Publishing failed: %s"), |
439 | emsg); | 438 | emsg); |
440 | GNUNET_free (emsg); | 439 | GNUNET_free(emsg); |
441 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | 440 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; |
442 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 441 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
443 | pi.value.publish.specifics.error.message = p->emsg; | 442 | pi.value.publish.specifics.error.message = p->emsg; |
444 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); | 443 | p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); |
445 | } | 444 | } |
446 | else | 445 | else |
447 | { | 446 | { |
448 | /* final progress event */ | 447 | /* final progress event */ |
449 | GNUNET_assert (NULL != p->chk_uri); | 448 | GNUNET_assert(NULL != p->chk_uri); |
450 | flen = GNUNET_FS_uri_chk_get_file_size (p->chk_uri); | 449 | flen = GNUNET_FS_uri_chk_get_file_size(p->chk_uri); |
451 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS; | 450 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS; |
452 | pi.value.publish.specifics.progress.data = NULL; | 451 | pi.value.publish.specifics.progress.data = NULL; |
453 | pi.value.publish.specifics.progress.offset = flen; | 452 | pi.value.publish.specifics.progress.offset = flen; |
454 | pi.value.publish.specifics.progress.data_len = 0; | 453 | pi.value.publish.specifics.progress.data_len = 0; |
455 | pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth (flen); | 454 | pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth(flen); |
456 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, flen); | 455 | p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, flen); |
457 | } | 456 | } |
458 | /* continue with main */ /* continue with main */ | 457 | /* continue with main */ /* continue with main */ |
459 | GNUNET_assert (NULL == pc->upload_task); | 458 | GNUNET_assert(NULL == pc->upload_task); |
460 | pc->upload_task = | 459 | pc->upload_task = |
461 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 460 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
462 | &GNUNET_FS_publish_main_, pc); | 461 | &GNUNET_FS_publish_main_, pc); |
463 | } | 462 | } |
464 | 463 | ||
465 | 464 | ||
@@ -478,13 +477,13 @@ encode_cont (void *cls) | |||
478 | * @param block_size size of @a block (in bytes) | 477 | * @param block_size size of @a block (in bytes) |
479 | */ | 478 | */ |
480 | static void | 479 | static void |
481 | block_proc (void *cls, | 480 | block_proc(void *cls, |
482 | const struct ContentHashKey *chk, | 481 | const struct ContentHashKey *chk, |
483 | uint64_t offset, | 482 | uint64_t offset, |
484 | unsigned int depth, | 483 | unsigned int depth, |
485 | enum GNUNET_BLOCK_Type type, | 484 | enum GNUNET_BLOCK_Type type, |
486 | const void *block, | 485 | const void *block, |
487 | uint16_t block_size) | 486 | uint16_t block_size) |
488 | { | 487 | { |
489 | struct GNUNET_FS_PublishContext *pc = cls; | 488 | struct GNUNET_FS_PublishContext *pc = cls; |
490 | struct GNUNET_FS_FileInformation *p; | 489 | struct GNUNET_FS_FileInformation *p; |
@@ -492,62 +491,62 @@ block_proc (void *cls, | |||
492 | 491 | ||
493 | p = pc->fi_pos; | 492 | p = pc->fi_pos; |
494 | if (NULL == pc->dsh) | 493 | if (NULL == pc->dsh) |
495 | { | 494 | { |
496 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 495 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
497 | "Waiting for datastore connection\n"); | 496 | "Waiting for datastore connection\n"); |
498 | GNUNET_assert (NULL == pc->upload_task); | 497 | GNUNET_assert(NULL == pc->upload_task); |
499 | pc->upload_task = | 498 | pc->upload_task = |
500 | GNUNET_SCHEDULER_add_with_priority | 499 | GNUNET_SCHEDULER_add_with_priority |
501 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); | 500 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); |
502 | return; | 501 | return; |
503 | } | 502 | } |
504 | 503 | ||
505 | if ( (GNUNET_YES != p->is_directory) && | 504 | if ((GNUNET_YES != p->is_directory) && |
506 | (GNUNET_YES == p->data.file.do_index) && | 505 | (GNUNET_YES == p->data.file.do_index) && |
507 | (GNUNET_BLOCK_TYPE_FS_DBLOCK == type) ) | 506 | (GNUNET_BLOCK_TYPE_FS_DBLOCK == type)) |
508 | { | 507 | { |
509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 508 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
510 | "Indexing block `%s' for offset %llu with index size %u\n", | 509 | "Indexing block `%s' for offset %llu with index size %u\n", |
511 | GNUNET_h2s (&chk->query), | 510 | GNUNET_h2s(&chk->query), |
512 | (unsigned long long) offset, | 511 | (unsigned long long)offset, |
513 | (unsigned int) sizeof (struct OnDemandBlock)); | 512 | (unsigned int)sizeof(struct OnDemandBlock)); |
514 | odb.offset = GNUNET_htonll (offset); | 513 | odb.offset = GNUNET_htonll(offset); |
515 | odb.file_id = p->data.file.file_id; | 514 | odb.file_id = p->data.file.file_id; |
516 | GNUNET_assert (pc->qre == NULL); | 515 | GNUNET_assert(pc->qre == NULL); |
517 | pc->qre = | 516 | pc->qre = |
518 | GNUNET_DATASTORE_put (pc->dsh, | 517 | GNUNET_DATASTORE_put(pc->dsh, |
519 | (p->is_directory == GNUNET_YES) ? 0 : pc->rid, | 518 | (p->is_directory == GNUNET_YES) ? 0 : pc->rid, |
520 | &chk->query, | 519 | &chk->query, |
521 | sizeof (struct OnDemandBlock), | 520 | sizeof(struct OnDemandBlock), |
522 | &odb, | 521 | &odb, |
523 | GNUNET_BLOCK_TYPE_FS_ONDEMAND, | 522 | GNUNET_BLOCK_TYPE_FS_ONDEMAND, |
524 | p->bo.content_priority, | 523 | p->bo.content_priority, |
525 | p->bo.anonymity_level, | 524 | p->bo.anonymity_level, |
526 | p->bo.replication_level, | 525 | p->bo.replication_level, |
527 | p->bo.expiration_time, | 526 | p->bo.expiration_time, |
528 | -2, 1, | 527 | -2, 1, |
529 | &ds_put_cont, pc); | 528 | &ds_put_cont, pc); |
530 | return; | 529 | return; |
531 | } | 530 | } |
532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 531 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
533 | "Publishing block `%s' for offset %llu with size %u\n", | 532 | "Publishing block `%s' for offset %llu with size %u\n", |
534 | GNUNET_h2s (&chk->query), | 533 | GNUNET_h2s(&chk->query), |
535 | (unsigned long long) offset, | 534 | (unsigned long long)offset, |
536 | (unsigned int) block_size); | 535 | (unsigned int)block_size); |
537 | GNUNET_assert (pc->qre == NULL); | 536 | GNUNET_assert(pc->qre == NULL); |
538 | pc->qre = | 537 | pc->qre = |
539 | GNUNET_DATASTORE_put (pc->dsh, (p->is_directory == GNUNET_YES) ? 0 : pc->rid, | 538 | GNUNET_DATASTORE_put(pc->dsh, (p->is_directory == GNUNET_YES) ? 0 : pc->rid, |
540 | &chk->query, | 539 | &chk->query, |
541 | block_size, | 540 | block_size, |
542 | block, | 541 | block, |
543 | type, | 542 | type, |
544 | p->bo.content_priority, | 543 | p->bo.content_priority, |
545 | p->bo.anonymity_level, | 544 | p->bo.anonymity_level, |
546 | p->bo.replication_level, | 545 | p->bo.replication_level, |
547 | p->bo.expiration_time, | 546 | p->bo.expiration_time, |
548 | -2, 1, | 547 | -2, 1, |
549 | &ds_put_cont, | 548 | &ds_put_cont, |
550 | pc); | 549 | pc); |
551 | } | 550 | } |
552 | 551 | ||
553 | 552 | ||
@@ -562,10 +561,10 @@ block_proc (void *cls, | |||
562 | * @param depth depth of the block in the tree, 0 for DBLOCK | 561 | * @param depth depth of the block in the tree, 0 for DBLOCK |
563 | */ | 562 | */ |
564 | static void | 563 | static void |
565 | progress_proc (void *cls, uint64_t offset, | 564 | progress_proc(void *cls, uint64_t offset, |
566 | const void *pt_block, | 565 | const void *pt_block, |
567 | size_t pt_size, | 566 | size_t pt_size, |
568 | unsigned int depth) | 567 | unsigned int depth) |
569 | { | 568 | { |
570 | struct GNUNET_FS_PublishContext *pc = cls; | 569 | struct GNUNET_FS_PublishContext *pc = cls; |
571 | struct GNUNET_FS_FileInformation *p; | 570 | struct GNUNET_FS_FileInformation *p; |
@@ -578,24 +577,23 @@ progress_proc (void *cls, uint64_t offset, | |||
578 | pi.value.publish.specifics.progress.offset = offset; | 577 | pi.value.publish.specifics.progress.offset = offset; |
579 | pi.value.publish.specifics.progress.data_len = pt_size; | 578 | pi.value.publish.specifics.progress.data_len = pt_size; |
580 | pi.value.publish.specifics.progress.depth = depth; | 579 | pi.value.publish.specifics.progress.depth = depth; |
581 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, offset); | 580 | p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, offset); |
582 | if ( (0 != depth) || | 581 | if ((0 != depth) || |
583 | (GNUNET_YES == p->is_directory) ) | 582 | (GNUNET_YES == p->is_directory)) |
584 | return; | 583 | return; |
585 | while (NULL != (par = p->dir)) | 584 | while (NULL != (par = p->dir)) |
586 | { | 585 | { |
587 | p = par; | 586 | p = par; |
588 | GNUNET_assert (GNUNET_YES == par->is_directory); | 587 | GNUNET_assert(GNUNET_YES == par->is_directory); |
589 | p->data.dir.contents_completed += pt_size; | 588 | p->data.dir.contents_completed += pt_size; |
590 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY; | 589 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY; |
591 | pi.value.publish.specifics.progress_directory.completed = p->data.dir.contents_completed; | 590 | pi.value.publish.specifics.progress_directory.completed = p->data.dir.contents_completed; |
592 | pi.value.publish.specifics.progress_directory.total = p->data.dir.contents_size; | 591 | pi.value.publish.specifics.progress_directory.total = p->data.dir.contents_size; |
593 | pi.value.publish.specifics.progress_directory.eta = GNUNET_TIME_calculate_eta (p->start_time, | 592 | pi.value.publish.specifics.progress_directory.eta = GNUNET_TIME_calculate_eta(p->start_time, |
594 | p->data.dir.contents_completed, | 593 | p->data.dir.contents_completed, |
595 | p->data.dir.contents_size); | 594 | p->data.dir.contents_size); |
596 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); | 595 | p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); |
597 | 596 | } | |
598 | } | ||
599 | } | 597 | } |
600 | 598 | ||
601 | 599 | ||
@@ -607,7 +605,7 @@ progress_proc (void *cls, uint64_t offset, | |||
607 | * @param pc overall upload data | 605 | * @param pc overall upload data |
608 | */ | 606 | */ |
609 | static void | 607 | static void |
610 | publish_content (struct GNUNET_FS_PublishContext *pc) | 608 | publish_content(struct GNUNET_FS_PublishContext *pc) |
611 | { | 609 | { |
612 | struct GNUNET_FS_FileInformation *p; | 610 | struct GNUNET_FS_FileInformation *p; |
613 | char *emsg; | 611 | char *emsg; |
@@ -617,65 +615,64 @@ publish_content (struct GNUNET_FS_PublishContext *pc) | |||
617 | uint64_t size; | 615 | uint64_t size; |
618 | 616 | ||
619 | p = pc->fi_pos; | 617 | p = pc->fi_pos; |
620 | GNUNET_assert (NULL != p); | 618 | GNUNET_assert(NULL != p); |
621 | if (NULL == p->te) | 619 | if (NULL == p->te) |
622 | { | 620 | { |
623 | if (GNUNET_YES == p->is_directory) | 621 | if (GNUNET_YES == p->is_directory) |
624 | { | ||
625 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n"); | ||
626 | db = GNUNET_FS_directory_builder_create (p->meta); | ||
627 | dirpos = p->data.dir.entries; | ||
628 | while (NULL != dirpos) | ||
629 | { | ||
630 | if (GNUNET_YES == dirpos->is_directory) | ||
631 | { | ||
632 | raw_data = dirpos->data.dir.dir_data; | ||
633 | dirpos->data.dir.dir_data = NULL; | ||
634 | } | ||
635 | else | ||
636 | { | 622 | { |
637 | raw_data = NULL; | 623 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n"); |
638 | if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) && | 624 | db = GNUNET_FS_directory_builder_create(p->meta); |
639 | (dirpos->data.file.file_size > 0)) | 625 | dirpos = p->data.dir.entries; |
640 | { | 626 | while (NULL != dirpos) |
641 | raw_data = GNUNET_malloc (dirpos->data.file.file_size); | ||
642 | emsg = NULL; | ||
643 | if (dirpos->data.file.file_size != | ||
644 | dirpos->data.file.reader (dirpos->data.file.reader_cls, 0, | ||
645 | dirpos->data.file.file_size, raw_data, | ||
646 | &emsg)) | ||
647 | { | 627 | { |
648 | GNUNET_free_non_null (emsg); | 628 | if (GNUNET_YES == dirpos->is_directory) |
649 | GNUNET_free (raw_data); | 629 | { |
650 | raw_data = NULL; | 630 | raw_data = dirpos->data.dir.dir_data; |
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; | ||
651 | } | 657 | } |
652 | dirpos->data.file.reader (dirpos->data.file.reader_cls, UINT64_MAX, 0, 0, NULL); | 658 | GNUNET_free_non_null(p->data.dir.dir_data); |
653 | } | 659 | p->data.dir.dir_data = NULL; |
660 | p->data.dir.dir_size = 0; | ||
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); | ||
654 | } | 664 | } |
655 | GNUNET_FS_directory_builder_add (db, dirpos->chk_uri, dirpos->meta, | 665 | size = (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; |
656 | raw_data); | 666 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
657 | GNUNET_free_non_null (raw_data); | 667 | "Creating tree encoder\n"); |
658 | dirpos = dirpos->next; | 668 | p->te = |
659 | } | 669 | GNUNET_FS_tree_encoder_create(pc->h, size, pc, &block_reader, |
660 | GNUNET_free_non_null (p->data.dir.dir_data); | 670 | &block_proc, &progress_proc, |
661 | p->data.dir.dir_data = NULL; | 671 | &encode_cont); |
662 | p->data.dir.dir_size = 0; | 672 | } |
663 | GNUNET_FS_directory_builder_finish (db, &p->data.dir.dir_size, | 673 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
664 | &p->data.dir.dir_data); | 674 | "Processing next block from tree\n"); |
665 | GNUNET_FS_file_information_sync_ (p); | 675 | GNUNET_FS_tree_encoder_next(p->te); |
666 | } | ||
667 | size = (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; | ||
668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
669 | "Creating tree encoder\n"); | ||
670 | p->te = | ||
671 | GNUNET_FS_tree_encoder_create (pc->h, size, pc, &block_reader, | ||
672 | &block_proc, &progress_proc, | ||
673 | &encode_cont); | ||
674 | |||
675 | } | ||
676 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
677 | "Processing next block from tree\n"); | ||
678 | GNUNET_FS_tree_encoder_next (p->te); | ||
679 | } | 676 | } |
680 | 677 | ||
681 | 678 | ||
@@ -687,17 +684,17 @@ publish_content (struct GNUNET_FS_PublishContext *pc) | |||
687 | * @param msg the response we got | 684 | * @param msg the response we got |
688 | */ | 685 | */ |
689 | static int | 686 | static int |
690 | check_index_start_failed (void *cls, | 687 | check_index_start_failed(void *cls, |
691 | const struct GNUNET_MessageHeader *msg) | 688 | const struct GNUNET_MessageHeader *msg) |
692 | { | 689 | { |
693 | size_t msize = ntohs (msg->size) - sizeof (*msg); | 690 | size_t msize = ntohs(msg->size) - sizeof(*msg); |
694 | const char *emsg = (const char *) &msg[1]; | 691 | const char *emsg = (const char *)&msg[1]; |
695 | 692 | ||
696 | if (emsg[msize - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') | 693 | if (emsg[msize - sizeof(struct GNUNET_MessageHeader) - 1] != '\0') |
697 | { | 694 | { |
698 | GNUNET_break (0); | 695 | GNUNET_break(0); |
699 | return GNUNET_SYSERR; | 696 | return GNUNET_SYSERR; |
700 | } | 697 | } |
701 | return GNUNET_OK; | 698 | return GNUNET_OK; |
702 | } | 699 | } |
703 | 700 | ||
@@ -710,27 +707,27 @@ check_index_start_failed (void *cls, | |||
710 | * @param msg the response we got | 707 | * @param msg the response we got |
711 | */ | 708 | */ |
712 | static void | 709 | static void |
713 | handle_index_start_failed (void *cls, | 710 | handle_index_start_failed(void *cls, |
714 | const struct GNUNET_MessageHeader *msg) | 711 | const struct GNUNET_MessageHeader *msg) |
715 | { | 712 | { |
716 | struct GNUNET_FS_PublishContext *pc = cls; | 713 | struct GNUNET_FS_PublishContext *pc = cls; |
717 | struct GNUNET_FS_FileInformation *p; | 714 | struct GNUNET_FS_FileInformation *p; |
718 | const char *emsg = (const char *) &msg[1]; | 715 | const char *emsg = (const char *)&msg[1]; |
719 | char *msgtxt; | 716 | char *msgtxt; |
720 | 717 | ||
721 | GNUNET_MQ_destroy (pc->mq); | 718 | GNUNET_MQ_destroy(pc->mq); |
722 | pc->mq = NULL; | 719 | pc->mq = NULL; |
723 | p = pc->fi_pos; | 720 | p = pc->fi_pos; |
724 | GNUNET_asprintf (&msgtxt, | 721 | GNUNET_asprintf(&msgtxt, |
725 | _("Can not index file `%s': %s.\n"), | 722 | _("Can not index file `%s': %s.\n"), |
726 | p->filename, | 723 | p->filename, |
727 | gettext (emsg)); | 724 | gettext(emsg)); |
728 | signal_publish_error (p, | 725 | signal_publish_error(p, |
729 | pc, | 726 | pc, |
730 | msgtxt); | 727 | msgtxt); |
731 | GNUNET_free (msgtxt); | 728 | GNUNET_free(msgtxt); |
732 | GNUNET_FS_file_information_sync_ (p); | 729 | GNUNET_FS_file_information_sync_(p); |
733 | GNUNET_FS_publish_sync_ (pc); | 730 | GNUNET_FS_publish_sync_(pc); |
734 | } | 731 | } |
735 | 732 | ||
736 | 733 | ||
@@ -742,18 +739,18 @@ handle_index_start_failed (void *cls, | |||
742 | * @param msg the response we got | 739 | * @param msg the response we got |
743 | */ | 740 | */ |
744 | static void | 741 | static void |
745 | handle_index_start_ok (void *cls, | 742 | handle_index_start_ok(void *cls, |
746 | const struct GNUNET_MessageHeader *msg) | 743 | const struct GNUNET_MessageHeader *msg) |
747 | { | 744 | { |
748 | struct GNUNET_FS_PublishContext *pc = cls; | 745 | struct GNUNET_FS_PublishContext *pc = cls; |
749 | struct GNUNET_FS_FileInformation *p; | 746 | struct GNUNET_FS_FileInformation *p; |
750 | 747 | ||
751 | GNUNET_MQ_destroy (pc->mq); | 748 | GNUNET_MQ_destroy(pc->mq); |
752 | pc->mq = NULL; | 749 | pc->mq = NULL; |
753 | p = pc->fi_pos; | 750 | p = pc->fi_pos; |
754 | p->data.file.index_start_confirmed = GNUNET_YES; | 751 | p->data.file.index_start_confirmed = GNUNET_YES; |
755 | GNUNET_FS_file_information_sync_ (p); | 752 | GNUNET_FS_file_information_sync_(p); |
756 | publish_content (pc); | 753 | publish_content(pc); |
757 | } | 754 | } |
758 | 755 | ||
759 | 756 | ||
@@ -766,25 +763,25 @@ handle_index_start_ok (void *cls, | |||
766 | * @param error error code | 763 | * @param error error code |
767 | */ | 764 | */ |
768 | static void | 765 | static void |
769 | index_mq_error_handler (void *cls, | 766 | index_mq_error_handler(void *cls, |
770 | enum GNUNET_MQ_Error error) | 767 | enum GNUNET_MQ_Error error) |
771 | { | 768 | { |
772 | struct GNUNET_FS_PublishContext *pc = cls; | 769 | struct GNUNET_FS_PublishContext *pc = cls; |
773 | struct GNUNET_FS_FileInformation *p; | 770 | struct GNUNET_FS_FileInformation *p; |
774 | 771 | ||
775 | if (NULL != pc->mq) | 772 | if (NULL != pc->mq) |
776 | { | 773 | { |
777 | GNUNET_MQ_destroy (pc->mq); | 774 | GNUNET_MQ_destroy(pc->mq); |
778 | pc->mq = NULL; | 775 | pc->mq = NULL; |
779 | } | 776 | } |
780 | p = pc->fi_pos; | 777 | p = pc->fi_pos; |
781 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 778 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
782 | _("Can not index file `%s': %s. Will try to insert instead.\n"), | 779 | _("Can not index file `%s': %s. Will try to insert instead.\n"), |
783 | p->filename, | 780 | p->filename, |
784 | _("error on index-start request to `fs' service")); | 781 | _("error on index-start request to `fs' service")); |
785 | p->data.file.do_index = GNUNET_NO; | 782 | p->data.file.do_index = GNUNET_NO; |
786 | GNUNET_FS_file_information_sync_ (p); | 783 | GNUNET_FS_file_information_sync_(p); |
787 | publish_content (pc); | 784 | publish_content(pc); |
788 | } | 785 | } |
789 | 786 | ||
790 | 787 | ||
@@ -796,20 +793,20 @@ index_mq_error_handler (void *cls, | |||
796 | * @param res resulting hash, NULL on error | 793 | * @param res resulting hash, NULL on error |
797 | */ | 794 | */ |
798 | static void | 795 | static void |
799 | hash_for_index_cb (void *cls, | 796 | hash_for_index_cb(void *cls, |
800 | const struct GNUNET_HashCode *res) | 797 | const struct GNUNET_HashCode *res) |
801 | { | 798 | { |
802 | struct GNUNET_FS_PublishContext *pc = cls; | 799 | struct GNUNET_FS_PublishContext *pc = cls; |
803 | struct GNUNET_MQ_MessageHandler handlers[] = { | 800 | struct GNUNET_MQ_MessageHandler handlers[] = { |
804 | GNUNET_MQ_hd_fixed_size (index_start_ok, | 801 | GNUNET_MQ_hd_fixed_size(index_start_ok, |
805 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK, | 802 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK, |
806 | struct GNUNET_MessageHeader, | 803 | struct GNUNET_MessageHeader, |
807 | pc), | 804 | pc), |
808 | GNUNET_MQ_hd_var_size (index_start_failed, | 805 | GNUNET_MQ_hd_var_size(index_start_failed, |
809 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED, | 806 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED, |
810 | struct GNUNET_MessageHeader, | 807 | struct GNUNET_MessageHeader, |
811 | pc), | 808 | pc), |
812 | GNUNET_MQ_handler_end () | 809 | GNUNET_MQ_handler_end() |
813 | }; | 810 | }; |
814 | struct GNUNET_FS_FileInformation *p; | 811 | struct GNUNET_FS_FileInformation *p; |
815 | struct GNUNET_MQ_Envelope *env; | 812 | struct GNUNET_MQ_Envelope *env; |
@@ -822,97 +819,97 @@ hash_for_index_cb (void *cls, | |||
822 | pc->fhc = NULL; | 819 | pc->fhc = NULL; |
823 | p = pc->fi_pos; | 820 | p = pc->fi_pos; |
824 | if (NULL == res) | 821 | if (NULL == res) |
825 | { | 822 | { |
826 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 823 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
827 | _("Can not index file `%s': %s. Will try to insert instead.\n"), | 824 | _("Can not index file `%s': %s. Will try to insert instead.\n"), |
828 | p->filename, | 825 | p->filename, |
829 | _("failed to compute hash")); | 826 | _("failed to compute hash")); |
830 | p->data.file.do_index = GNUNET_NO; | 827 | p->data.file.do_index = GNUNET_NO; |
831 | GNUNET_FS_file_information_sync_ (p); | 828 | GNUNET_FS_file_information_sync_(p); |
832 | publish_content (pc); | 829 | publish_content(pc); |
833 | return; | 830 | return; |
834 | } | 831 | } |
835 | if (GNUNET_YES == p->data.file.index_start_confirmed) | 832 | if (GNUNET_YES == p->data.file.index_start_confirmed) |
836 | { | 833 | { |
837 | publish_content (pc); | 834 | publish_content(pc); |
838 | return; | 835 | return; |
839 | } | 836 | } |
840 | fn = GNUNET_STRINGS_filename_expand (p->filename); | 837 | fn = GNUNET_STRINGS_filename_expand(p->filename); |
841 | GNUNET_assert (fn != NULL); | 838 | GNUNET_assert(fn != NULL); |
842 | slen = strlen (fn) + 1; | 839 | slen = strlen(fn) + 1; |
843 | if (slen >= | 840 | if (slen >= |
844 | GNUNET_MAX_MESSAGE_SIZE - sizeof (struct IndexStartMessage)) | 841 | GNUNET_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage)) |
845 | { | 842 | { |
846 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 843 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
847 | _ | 844 | _ |
848 | ("Can not index file `%s': %s. Will try to insert instead.\n"), | 845 | ("Can not index file `%s': %s. Will try to insert instead.\n"), |
849 | fn, _("filename too long")); | 846 | fn, _("filename too long")); |
850 | GNUNET_free (fn); | 847 | GNUNET_free(fn); |
851 | p->data.file.do_index = GNUNET_NO; | 848 | p->data.file.do_index = GNUNET_NO; |
852 | GNUNET_FS_file_information_sync_ (p); | 849 | GNUNET_FS_file_information_sync_(p); |
853 | publish_content (pc); | 850 | publish_content(pc); |
854 | return; | 851 | return; |
855 | } | 852 | } |
856 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 853 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
857 | "Hash of indexed file `%s' is `%s'\n", | 854 | "Hash of indexed file `%s' is `%s'\n", |
858 | p->filename, | 855 | p->filename, |
859 | GNUNET_h2s (res)); | 856 | GNUNET_h2s(res)); |
860 | if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) | 857 | if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) |
861 | { | 858 | { |
862 | p->data.file.file_id = *res; | 859 | p->data.file.file_id = *res; |
863 | p->data.file.have_hash = GNUNET_YES; | 860 | p->data.file.have_hash = GNUNET_YES; |
864 | p->data.file.index_start_confirmed = GNUNET_YES; | 861 | p->data.file.index_start_confirmed = GNUNET_YES; |
865 | GNUNET_FS_file_information_sync_ (p); | 862 | GNUNET_FS_file_information_sync_(p); |
866 | publish_content (pc); | 863 | publish_content(pc); |
867 | GNUNET_free (fn); | 864 | GNUNET_free(fn); |
868 | return; | 865 | return; |
869 | } | 866 | } |
870 | pc->mq = GNUNET_CLIENT_connect (pc->h->cfg, | 867 | pc->mq = GNUNET_CLIENT_connect(pc->h->cfg, |
871 | "fs", | 868 | "fs", |
872 | handlers, | 869 | handlers, |
873 | &index_mq_error_handler, | 870 | &index_mq_error_handler, |
874 | pc); | 871 | pc); |
875 | if (NULL == pc->mq) | 872 | if (NULL == pc->mq) |
876 | { | 873 | { |
877 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 874 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
878 | _("Can not index file `%s': %s. Will try to insert instead.\n"), | 875 | _("Can not index file `%s': %s. Will try to insert instead.\n"), |
879 | p->filename, | 876 | p->filename, |
880 | _("could not connect to `fs' service")); | 877 | _("could not connect to `fs' service")); |
881 | p->data.file.do_index = GNUNET_NO; | 878 | p->data.file.do_index = GNUNET_NO; |
882 | publish_content (pc); | 879 | publish_content(pc); |
883 | GNUNET_free (fn); | 880 | GNUNET_free(fn); |
884 | return; | 881 | return; |
885 | } | 882 | } |
886 | if (p->data.file.have_hash != GNUNET_YES) | 883 | if (p->data.file.have_hash != GNUNET_YES) |
887 | { | 884 | { |
888 | p->data.file.file_id = *res; | 885 | p->data.file.file_id = *res; |
889 | p->data.file.have_hash = GNUNET_YES; | 886 | p->data.file.have_hash = GNUNET_YES; |
890 | GNUNET_FS_file_information_sync_ (p); | 887 | GNUNET_FS_file_information_sync_(p); |
891 | } | 888 | } |
892 | env = GNUNET_MQ_msg_extra (ism, | 889 | env = GNUNET_MQ_msg_extra(ism, |
893 | slen, | 890 | slen, |
894 | GNUNET_MESSAGE_TYPE_FS_INDEX_START); | 891 | GNUNET_MESSAGE_TYPE_FS_INDEX_START); |
895 | if (GNUNET_OK == | 892 | if (GNUNET_OK == |
896 | GNUNET_DISK_file_get_identifiers (p->filename, | 893 | GNUNET_DISK_file_get_identifiers(p->filename, |
897 | &dev, | 894 | &dev, |
898 | &ino)) | 895 | &ino)) |
899 | { | 896 | { |
900 | ism->device = GNUNET_htonll (dev); | 897 | ism->device = GNUNET_htonll(dev); |
901 | ism->inode = GNUNET_htonll (ino); | 898 | ism->inode = GNUNET_htonll(ino); |
902 | } | 899 | } |
903 | else | 900 | else |
904 | { | 901 | { |
905 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 902 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
906 | _("Failed to get file identifiers for `%s'\n"), | 903 | _("Failed to get file identifiers for `%s'\n"), |
907 | p->filename); | 904 | p->filename); |
908 | } | 905 | } |
909 | ism->file_id = *res; | 906 | ism->file_id = *res; |
910 | GNUNET_memcpy (&ism[1], | 907 | GNUNET_memcpy(&ism[1], |
911 | fn, | 908 | fn, |
912 | slen); | 909 | slen); |
913 | GNUNET_free (fn); | 910 | GNUNET_free(fn); |
914 | GNUNET_MQ_send (pc->mq, | 911 | GNUNET_MQ_send(pc->mq, |
915 | env); | 912 | env); |
916 | } | 913 | } |
917 | 914 | ||
918 | 915 | ||
@@ -922,27 +919,27 @@ hash_for_index_cb (void *cls, | |||
922 | * @param pc publishing context to do this for | 919 | * @param pc publishing context to do this for |
923 | */ | 920 | */ |
924 | static void | 921 | static void |
925 | publish_kblocks (struct GNUNET_FS_PublishContext *pc) | 922 | publish_kblocks(struct GNUNET_FS_PublishContext *pc) |
926 | { | 923 | { |
927 | struct GNUNET_FS_FileInformation *p; | 924 | struct GNUNET_FS_FileInformation *p; |
928 | 925 | ||
929 | p = pc->fi_pos; | 926 | p = pc->fi_pos; |
930 | /* upload of "p" complete, publish KBlocks! */ | 927 | /* upload of "p" complete, publish KBlocks! */ |
931 | if (NULL != p->keywords) | 928 | if (NULL != p->keywords) |
932 | { | 929 | { |
933 | pc->ksk_pc = GNUNET_FS_publish_ksk (pc->h, | 930 | pc->ksk_pc = GNUNET_FS_publish_ksk(pc->h, |
934 | p->keywords, | 931 | p->keywords, |
935 | p->meta, | 932 | p->meta, |
936 | p->chk_uri, | 933 | p->chk_uri, |
937 | &p->bo, | 934 | &p->bo, |
938 | pc->options, | 935 | pc->options, |
939 | &publish_kblocks_cont, | 936 | &publish_kblocks_cont, |
940 | pc); | 937 | pc); |
941 | } | 938 | } |
942 | else | 939 | else |
943 | { | 940 | { |
944 | publish_kblocks_cont (pc, p->chk_uri, NULL); | 941 | publish_kblocks_cont(pc, p->chk_uri, NULL); |
945 | } | 942 | } |
946 | } | 943 | } |
947 | 944 | ||
948 | 945 | ||
@@ -953,8 +950,8 @@ publish_kblocks (struct GNUNET_FS_PublishContext *pc) | |||
953 | * @param sig the response we got | 950 | * @param sig the response we got |
954 | */ | 951 | */ |
955 | static void | 952 | static void |
956 | handle_signature_response (void *cls, | 953 | handle_signature_response(void *cls, |
957 | const struct ResponseLocSignatureMessage *sig) | 954 | const struct ResponseLocSignatureMessage *sig) |
958 | { | 955 | { |
959 | struct GNUNET_FS_PublishContext *pc = cls; | 956 | struct GNUNET_FS_PublishContext *pc = cls; |
960 | struct GNUNET_FS_FileInformation *p; | 957 | struct GNUNET_FS_FileInformation *p; |
@@ -964,11 +961,11 @@ handle_signature_response (void *cls, | |||
964 | /* p->data.loc.fi kept from CHK before */ | 961 | /* p->data.loc.fi kept from CHK before */ |
965 | p->chk_uri->data.loc.peer = sig->peer; | 962 | p->chk_uri->data.loc.peer = sig->peer; |
966 | p->chk_uri->data.loc.expirationTime | 963 | p->chk_uri->data.loc.expirationTime |
967 | = GNUNET_TIME_absolute_ntoh (sig->expiration_time); | 964 | = GNUNET_TIME_absolute_ntoh(sig->expiration_time); |
968 | p->chk_uri->data.loc.contentSignature = sig->signature; | 965 | p->chk_uri->data.loc.contentSignature = sig->signature; |
969 | GNUNET_FS_file_information_sync_ (p); | 966 | GNUNET_FS_file_information_sync_(p); |
970 | GNUNET_FS_publish_sync_ (pc); | 967 | GNUNET_FS_publish_sync_(pc); |
971 | publish_kblocks (pc); | 968 | publish_kblocks(pc); |
972 | } | 969 | } |
973 | 970 | ||
974 | 971 | ||
@@ -981,19 +978,19 @@ handle_signature_response (void *cls, | |||
981 | * @param error error code | 978 | * @param error error code |
982 | */ | 979 | */ |
983 | static void | 980 | static void |
984 | loc_mq_error_handler (void *cls, | 981 | loc_mq_error_handler(void *cls, |
985 | enum GNUNET_MQ_Error error) | 982 | enum GNUNET_MQ_Error error) |
986 | { | 983 | { |
987 | struct GNUNET_FS_PublishContext *pc = cls; | 984 | struct GNUNET_FS_PublishContext *pc = cls; |
988 | 985 | ||
989 | if (NULL != pc->mq) | 986 | if (NULL != pc->mq) |
990 | { | 987 | { |
991 | GNUNET_MQ_destroy (pc->mq); | 988 | GNUNET_MQ_destroy(pc->mq); |
992 | pc->mq = NULL; | 989 | pc->mq = NULL; |
993 | } | 990 | } |
994 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 991 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
995 | _("Can not create LOC URI. Will continue with CHK instead.\n")); | 992 | _("Can not create LOC URI. Will continue with CHK instead.\n")); |
996 | publish_kblocks (pc); | 993 | publish_kblocks(pc); |
997 | } | 994 | } |
998 | 995 | ||
999 | 996 | ||
@@ -1005,42 +1002,42 @@ loc_mq_error_handler (void *cls, | |||
1005 | * @param pc the publishing context do to this for | 1002 | * @param pc the publishing context do to this for |
1006 | */ | 1003 | */ |
1007 | static void | 1004 | static void |
1008 | create_loc_uri (struct GNUNET_FS_PublishContext *pc) | 1005 | create_loc_uri(struct GNUNET_FS_PublishContext *pc) |
1009 | { | 1006 | { |
1010 | struct GNUNET_MQ_MessageHandler handlers[] = { | 1007 | struct GNUNET_MQ_MessageHandler handlers[] = { |
1011 | GNUNET_MQ_hd_fixed_size (signature_response, | 1008 | GNUNET_MQ_hd_fixed_size(signature_response, |
1012 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE, | 1009 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE, |
1013 | struct ResponseLocSignatureMessage, | 1010 | struct ResponseLocSignatureMessage, |
1014 | pc), | 1011 | pc), |
1015 | GNUNET_MQ_handler_end () | 1012 | GNUNET_MQ_handler_end() |
1016 | }; | 1013 | }; |
1017 | struct GNUNET_MQ_Envelope *env; | 1014 | struct GNUNET_MQ_Envelope *env; |
1018 | struct RequestLocSignatureMessage *req; | 1015 | struct RequestLocSignatureMessage *req; |
1019 | struct GNUNET_FS_FileInformation *p; | 1016 | struct GNUNET_FS_FileInformation *p; |
1020 | 1017 | ||
1021 | if (NULL != pc->mq) | 1018 | if (NULL != pc->mq) |
1022 | GNUNET_MQ_destroy (pc->mq); | 1019 | GNUNET_MQ_destroy(pc->mq); |
1023 | pc->mq = GNUNET_CLIENT_connect (pc->h->cfg, | 1020 | pc->mq = GNUNET_CLIENT_connect(pc->h->cfg, |
1024 | "fs", | 1021 | "fs", |
1025 | handlers, | 1022 | handlers, |
1026 | &loc_mq_error_handler, | 1023 | &loc_mq_error_handler, |
1027 | pc); | 1024 | pc); |
1028 | if (NULL == pc->mq) | 1025 | if (NULL == pc->mq) |
1029 | { | 1026 | { |
1030 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1027 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1031 | _("Can not create LOC URI. Will continue with CHK instead.\n")); | 1028 | _("Can not create LOC URI. Will continue with CHK instead.\n")); |
1032 | publish_kblocks (pc); | 1029 | publish_kblocks(pc); |
1033 | return; | 1030 | return; |
1034 | } | 1031 | } |
1035 | p = pc->fi_pos; | 1032 | p = pc->fi_pos; |
1036 | env = GNUNET_MQ_msg (req, | 1033 | env = GNUNET_MQ_msg(req, |
1037 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN); | 1034 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN); |
1038 | req->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | 1035 | req->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); |
1039 | req->expiration_time = GNUNET_TIME_absolute_hton (p->bo.expiration_time); | 1036 | req->expiration_time = GNUNET_TIME_absolute_hton(p->bo.expiration_time); |
1040 | req->chk = p->chk_uri->data.chk.chk; | 1037 | req->chk = p->chk_uri->data.chk.chk; |
1041 | req->file_length = GNUNET_htonll (p->chk_uri->data.chk.file_length); | 1038 | req->file_length = GNUNET_htonll(p->chk_uri->data.chk.file_length); |
1042 | GNUNET_MQ_send (pc->mq, | 1039 | GNUNET_MQ_send(pc->mq, |
1043 | env); | 1040 | env); |
1044 | } | 1041 | } |
1045 | 1042 | ||
1046 | 1043 | ||
@@ -1050,7 +1047,7 @@ create_loc_uri (struct GNUNET_FS_PublishContext *pc) | |||
1050 | * @param cls `struct GNUNET_FS_PublishContext *` identifies the upload | 1047 | * @param cls `struct GNUNET_FS_PublishContext *` identifies the upload |
1051 | */ | 1048 | */ |
1052 | void | 1049 | void |
1053 | GNUNET_FS_publish_main_ (void *cls) | 1050 | GNUNET_FS_publish_main_(void *cls) |
1054 | { | 1051 | { |
1055 | struct GNUNET_FS_PublishContext *pc = cls; | 1052 | struct GNUNET_FS_PublishContext *pc = cls; |
1056 | struct GNUNET_FS_ProgressInfo pi; | 1053 | struct GNUNET_FS_ProgressInfo pi; |
@@ -1060,108 +1057,108 @@ GNUNET_FS_publish_main_ (void *cls) | |||
1060 | pc->upload_task = NULL; | 1057 | pc->upload_task = NULL; |
1061 | p = pc->fi_pos; | 1058 | p = pc->fi_pos; |
1062 | if (NULL == p) | 1059 | if (NULL == p) |
1063 | { | 1060 | { |
1064 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1061 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1065 | "Publishing complete, now publishing SKS and KSK blocks.\n"); | 1062 | "Publishing complete, now publishing SKS and KSK blocks.\n"); |
1066 | /* upload of entire hierarchy complete, | 1063 | /* upload of entire hierarchy complete, |
1067 | * publish namespace entries */ | 1064 | * publish namespace entries */ |
1068 | GNUNET_FS_publish_sync_ (pc); | 1065 | GNUNET_FS_publish_sync_(pc); |
1069 | publish_sblock (pc); | 1066 | publish_sblock(pc); |
1070 | return; | 1067 | return; |
1071 | } | 1068 | } |
1072 | /* find starting position */ | 1069 | /* find starting position */ |
1073 | while ( (GNUNET_YES == p->is_directory) && | 1070 | while ((GNUNET_YES == p->is_directory) && |
1074 | (NULL != p->data.dir.entries) && | 1071 | (NULL != p->data.dir.entries) && |
1075 | (NULL == p->emsg) && | 1072 | (NULL == p->emsg) && |
1076 | (NULL == p->data.dir.entries->chk_uri) ) | 1073 | (NULL == p->data.dir.entries->chk_uri)) |
1077 | { | 1074 | { |
1078 | p = p->data.dir.entries; | 1075 | p = p->data.dir.entries; |
1079 | pc->fi_pos = p; | 1076 | pc->fi_pos = p; |
1080 | GNUNET_FS_publish_sync_ (pc); | 1077 | GNUNET_FS_publish_sync_(pc); |
1081 | } | 1078 | } |
1082 | /* abort on error */ | 1079 | /* abort on error */ |
1083 | if (NULL != p->emsg) | 1080 | if (NULL != p->emsg) |
1084 | { | 1081 | { |
1085 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1082 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1086 | "Error uploading: %s\n", | 1083 | "Error uploading: %s\n", |
1087 | p->emsg); | 1084 | p->emsg); |
1088 | /* error with current file, abort all | 1085 | /* error with current file, abort all |
1089 | * related files as well! */ | 1086 | * related files as well! */ |
1090 | while (NULL != p->dir) | 1087 | while (NULL != p->dir) |
1091 | { | 1088 | { |
1092 | fn = GNUNET_CONTAINER_meta_data_get_by_type (p->meta, | 1089 | fn = GNUNET_CONTAINER_meta_data_get_by_type(p->meta, |
1093 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 1090 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); |
1094 | p = p->dir; | 1091 | p = p->dir; |
1095 | if (fn != NULL) | 1092 | if (fn != NULL) |
1096 | { | 1093 | { |
1097 | GNUNET_asprintf (&p->emsg, | 1094 | GNUNET_asprintf(&p->emsg, |
1098 | _("Recursive upload failed at `%s': %s"), | 1095 | _("Recursive upload failed at `%s': %s"), |
1099 | fn, | 1096 | fn, |
1100 | p->emsg); | 1097 | p->emsg); |
1101 | GNUNET_free (fn); | 1098 | GNUNET_free(fn); |
1102 | } | 1099 | } |
1103 | else | 1100 | else |
1104 | { | 1101 | { |
1105 | GNUNET_asprintf (&p->emsg, | 1102 | GNUNET_asprintf(&p->emsg, |
1106 | _("Recursive upload failed: %s"), | 1103 | _("Recursive upload failed: %s"), |
1107 | p->emsg); | 1104 | p->emsg); |
1108 | } | 1105 | } |
1109 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | 1106 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; |
1110 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 1107 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
1111 | pi.value.publish.specifics.error.message = p->emsg; | 1108 | pi.value.publish.specifics.error.message = p->emsg; |
1112 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); | 1109 | 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; | ||
1113 | } | 1114 | } |
1114 | pc->all_done = GNUNET_YES; | ||
1115 | GNUNET_FS_publish_sync_ (pc); | ||
1116 | return; | ||
1117 | } | ||
1118 | /* handle completion */ | 1115 | /* handle completion */ |
1119 | if (NULL != p->chk_uri) | 1116 | if (NULL != p->chk_uri) |
1120 | { | ||
1121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1122 | "File upload complete, now publishing KSK blocks.\n"); | ||
1123 | GNUNET_FS_publish_sync_ (pc); | ||
1124 | |||
1125 | if ( (0 == p->bo.anonymity_level) && | ||
1126 | (GNUNET_YES != | ||
1127 | GNUNET_FS_uri_test_loc (p->chk_uri)) ) | ||
1128 | { | ||
1129 | /* zero anonymity, box CHK URI in LOC URI */ | ||
1130 | create_loc_uri (pc); | ||
1131 | } | ||
1132 | else | ||
1133 | { | 1117 | { |
1134 | publish_kblocks (pc); | 1118 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1119 | "File upload complete, now publishing KSK blocks.\n"); | ||
1120 | GNUNET_FS_publish_sync_(pc); | ||
1121 | |||
1122 | if ((0 == p->bo.anonymity_level) && | ||
1123 | (GNUNET_YES != | ||
1124 | GNUNET_FS_uri_test_loc(p->chk_uri))) | ||
1125 | { | ||
1126 | /* zero anonymity, box CHK URI in LOC URI */ | ||
1127 | create_loc_uri(pc); | ||
1128 | } | ||
1129 | else | ||
1130 | { | ||
1131 | publish_kblocks(pc); | ||
1132 | } | ||
1133 | return; | ||
1135 | } | 1134 | } |
1136 | return; | ||
1137 | } | ||
1138 | if ((GNUNET_YES != p->is_directory) && (p->data.file.do_index)) | 1135 | if ((GNUNET_YES != p->is_directory) && (p->data.file.do_index)) |
1139 | { | ||
1140 | if (NULL == p->filename) | ||
1141 | { | 1136 | { |
1142 | p->data.file.do_index = GNUNET_NO; | 1137 | if (NULL == p->filename) |
1143 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1138 | { |
1144 | _("Can not index file `%s': %s. Will try to insert instead.\n"), | 1139 | p->data.file.do_index = GNUNET_NO; |
1145 | "<no-name>", | 1140 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1146 | _("needs to be an actual file")); | 1141 | _("Can not index file `%s': %s. Will try to insert instead.\n"), |
1147 | GNUNET_FS_file_information_sync_ (p); | 1142 | "<no-name>", |
1148 | publish_content (pc); | 1143 | _("needs to be an actual file")); |
1144 | GNUNET_FS_file_information_sync_(p); | ||
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 | } | ||
1149 | return; | 1159 | return; |
1150 | } | 1160 | } |
1151 | if (p->data.file.have_hash) | 1161 | publish_content(pc); |
1152 | { | ||
1153 | hash_for_index_cb (pc, &p->data.file.file_id); | ||
1154 | } | ||
1155 | else | ||
1156 | { | ||
1157 | p->start_time = GNUNET_TIME_absolute_get (); | ||
1158 | pc->fhc = | ||
1159 | GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, p->filename, | ||
1160 | HASHING_BLOCKSIZE, &hash_for_index_cb, pc); | ||
1161 | } | ||
1162 | return; | ||
1163 | } | ||
1164 | publish_content (pc); | ||
1165 | } | 1162 | } |
1166 | 1163 | ||
1167 | 1164 | ||
@@ -1180,14 +1177,14 @@ GNUNET_FS_publish_main_ (void *cls) | |||
1180 | * @return #GNUNET_OK to continue (always) | 1177 | * @return #GNUNET_OK to continue (always) |
1181 | */ | 1178 | */ |
1182 | static int | 1179 | static int |
1183 | fip_signal_start (void *cls, | 1180 | fip_signal_start(void *cls, |
1184 | struct GNUNET_FS_FileInformation *fi, | 1181 | struct GNUNET_FS_FileInformation *fi, |
1185 | uint64_t length, | 1182 | uint64_t length, |
1186 | struct GNUNET_CONTAINER_MetaData *meta, | 1183 | struct GNUNET_CONTAINER_MetaData *meta, |
1187 | struct GNUNET_FS_Uri **uri, | 1184 | struct GNUNET_FS_Uri **uri, |
1188 | struct GNUNET_FS_BlockOptions *bo, | 1185 | struct GNUNET_FS_BlockOptions *bo, |
1189 | int *do_index, | 1186 | int *do_index, |
1190 | void **client_info) | 1187 | void **client_info) |
1191 | { | 1188 | { |
1192 | struct GNUNET_FS_PublishContext *pc = cls; | 1189 | struct GNUNET_FS_PublishContext *pc = cls; |
1193 | struct GNUNET_FS_ProgressInfo pi; | 1190 | struct GNUNET_FS_ProgressInfo pi; |
@@ -1195,52 +1192,52 @@ fip_signal_start (void *cls, | |||
1195 | uint64_t left; | 1192 | uint64_t left; |
1196 | 1193 | ||
1197 | if (GNUNET_YES == pc->skip_next_fi_callback) | 1194 | if (GNUNET_YES == pc->skip_next_fi_callback) |
1198 | { | 1195 | { |
1199 | pc->skip_next_fi_callback = GNUNET_NO; | 1196 | pc->skip_next_fi_callback = GNUNET_NO; |
1200 | return GNUNET_OK; | 1197 | return GNUNET_OK; |
1201 | } | 1198 | } |
1202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1199 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1203 | "Starting publish operation\n"); | 1200 | "Starting publish operation\n"); |
1204 | if (*do_index) | 1201 | if (*do_index) |
1205 | { | 1202 | { |
1206 | /* space for on-demand blocks */ | 1203 | /* space for on-demand blocks */ |
1207 | pc->reserve_space += | 1204 | pc->reserve_space += |
1208 | ((length + DBLOCK_SIZE - | 1205 | ((length + DBLOCK_SIZE - |
1209 | 1) / DBLOCK_SIZE) * sizeof (struct OnDemandBlock); | 1206 | 1) / DBLOCK_SIZE) * sizeof(struct OnDemandBlock); |
1210 | } | 1207 | } |
1211 | else | 1208 | else |
1212 | { | 1209 | { |
1213 | /* space for DBlocks */ | 1210 | /* space for DBlocks */ |
1214 | pc->reserve_space += length; | 1211 | pc->reserve_space += length; |
1215 | } | 1212 | } |
1216 | /* entries for IBlocks and DBlocks, space for IBlocks */ | 1213 | /* entries for IBlocks and DBlocks, space for IBlocks */ |
1217 | left = length; | 1214 | left = length; |
1218 | while (1) | 1215 | while (1) |
1219 | { | 1216 | { |
1220 | left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE; | 1217 | left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE; |
1221 | pc->reserve_entries += left; | 1218 | pc->reserve_entries += left; |
1222 | if (left <= 1) | 1219 | if (left <= 1) |
1223 | break; | 1220 | break; |
1224 | left = left * sizeof (struct ContentHashKey); | 1221 | left = left * sizeof(struct ContentHashKey); |
1225 | pc->reserve_space += left; | 1222 | pc->reserve_space += left; |
1226 | } | 1223 | } |
1227 | pc->reserve_entries++; | 1224 | pc->reserve_entries++; |
1228 | /* entries and space for keywords */ | 1225 | /* entries and space for keywords */ |
1229 | if (NULL != *uri) | 1226 | if (NULL != *uri) |
1230 | { | 1227 | { |
1231 | kc = GNUNET_FS_uri_ksk_get_keyword_count (*uri); | 1228 | kc = GNUNET_FS_uri_ksk_get_keyword_count(*uri); |
1232 | pc->reserve_entries += kc; | 1229 | pc->reserve_entries += kc; |
1233 | pc->reserve_space += GNUNET_MAX_MESSAGE_SIZE * kc; | 1230 | pc->reserve_space += GNUNET_MAX_MESSAGE_SIZE * kc; |
1234 | } | 1231 | } |
1235 | pi.status = GNUNET_FS_STATUS_PUBLISH_START; | 1232 | pi.status = GNUNET_FS_STATUS_PUBLISH_START; |
1236 | *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0); | 1233 | *client_info = GNUNET_FS_publish_make_status_(&pi, pc, fi, 0); |
1237 | GNUNET_FS_file_information_sync_ (fi); | 1234 | GNUNET_FS_file_information_sync_(fi); |
1238 | if ((fi->is_directory) && (fi->dir != NULL)) | 1235 | if ((fi->is_directory) && (fi->dir != NULL)) |
1239 | { | 1236 | { |
1240 | /* We are a directory, and we are not top-level; process entries in directory */ | 1237 | /* We are a directory, and we are not top-level; process entries in directory */ |
1241 | pc->skip_next_fi_callback = GNUNET_YES; | 1238 | pc->skip_next_fi_callback = GNUNET_YES; |
1242 | GNUNET_FS_file_information_inspect (fi, &fip_signal_start, pc); | 1239 | GNUNET_FS_file_information_inspect(fi, &fip_signal_start, pc); |
1243 | } | 1240 | } |
1244 | return GNUNET_OK; | 1241 | return GNUNET_OK; |
1245 | } | 1242 | } |
1246 | 1243 | ||
@@ -1253,39 +1250,39 @@ fip_signal_start (void *cls, | |||
1253 | * @param pc the publish context of which a file is being suspended | 1250 | * @param pc the publish context of which a file is being suspended |
1254 | */ | 1251 | */ |
1255 | static void | 1252 | static void |
1256 | suspend_operation (struct GNUNET_FS_FileInformation *fi, | 1253 | suspend_operation(struct GNUNET_FS_FileInformation *fi, |
1257 | struct GNUNET_FS_PublishContext *pc) | 1254 | struct GNUNET_FS_PublishContext *pc) |
1258 | { | 1255 | { |
1259 | struct GNUNET_FS_ProgressInfo pi; | 1256 | struct GNUNET_FS_ProgressInfo pi; |
1260 | uint64_t off; | 1257 | uint64_t off; |
1261 | 1258 | ||
1262 | if (NULL != pc->ksk_pc) | 1259 | if (NULL != pc->ksk_pc) |
1263 | { | 1260 | { |
1264 | GNUNET_FS_publish_ksk_cancel (pc->ksk_pc); | 1261 | GNUNET_FS_publish_ksk_cancel(pc->ksk_pc); |
1265 | pc->ksk_pc = NULL; | 1262 | pc->ksk_pc = NULL; |
1266 | } | 1263 | } |
1267 | if (NULL != pc->sks_pc) | 1264 | if (NULL != pc->sks_pc) |
1268 | { | 1265 | { |
1269 | GNUNET_FS_publish_sks_cancel (pc->sks_pc); | 1266 | GNUNET_FS_publish_sks_cancel(pc->sks_pc); |
1270 | pc->sks_pc = NULL; | 1267 | pc->sks_pc = NULL; |
1271 | } | 1268 | } |
1272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1269 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1273 | "Suspending publish operation\n"); | 1270 | "Suspending publish operation\n"); |
1274 | GNUNET_free_non_null (fi->serialization); | 1271 | GNUNET_free_non_null(fi->serialization); |
1275 | fi->serialization = NULL; | 1272 | fi->serialization = NULL; |
1276 | off = (NULL == fi->chk_uri) ? 0 : (GNUNET_YES == fi->is_directory) ? fi->data.dir.dir_size : fi->data.file.file_size; | 1273 | off = (NULL == fi->chk_uri) ? 0 : (GNUNET_YES == fi->is_directory) ? fi->data.dir.dir_size : fi->data.file.file_size; |
1277 | pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND; | 1274 | pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND; |
1278 | GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off)); | 1275 | GNUNET_break(NULL == GNUNET_FS_publish_make_status_(&pi, pc, fi, off)); |
1279 | if (NULL != pc->qre) | 1276 | if (NULL != pc->qre) |
1280 | { | 1277 | { |
1281 | GNUNET_DATASTORE_cancel (pc->qre); | 1278 | GNUNET_DATASTORE_cancel(pc->qre); |
1282 | pc->qre = NULL; | 1279 | pc->qre = NULL; |
1283 | } | 1280 | } |
1284 | if (NULL != pc->dsh) | 1281 | if (NULL != pc->dsh) |
1285 | { | 1282 | { |
1286 | GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO); | 1283 | GNUNET_DATASTORE_disconnect(pc->dsh, GNUNET_NO); |
1287 | pc->dsh = NULL; | 1284 | pc->dsh = NULL; |
1288 | } | 1285 | } |
1289 | pc->rid = 0; | 1286 | pc->rid = 0; |
1290 | } | 1287 | } |
1291 | 1288 | ||
@@ -1305,29 +1302,29 @@ suspend_operation (struct GNUNET_FS_FileInformation *fi, | |||
1305 | * @return #GNUNET_OK to continue (always) | 1302 | * @return #GNUNET_OK to continue (always) |
1306 | */ | 1303 | */ |
1307 | static int | 1304 | static int |
1308 | fip_signal_suspend (void *cls, | 1305 | fip_signal_suspend(void *cls, |
1309 | struct GNUNET_FS_FileInformation *fi, | 1306 | struct GNUNET_FS_FileInformation *fi, |
1310 | uint64_t length, | 1307 | uint64_t length, |
1311 | struct GNUNET_CONTAINER_MetaData *meta, | 1308 | struct GNUNET_CONTAINER_MetaData *meta, |
1312 | struct GNUNET_FS_Uri **uri, | 1309 | struct GNUNET_FS_Uri **uri, |
1313 | struct GNUNET_FS_BlockOptions *bo, | 1310 | struct GNUNET_FS_BlockOptions *bo, |
1314 | int *do_index, | 1311 | int *do_index, |
1315 | void **client_info) | 1312 | void **client_info) |
1316 | { | 1313 | { |
1317 | struct GNUNET_FS_PublishContext *pc = cls; | 1314 | struct GNUNET_FS_PublishContext *pc = cls; |
1318 | 1315 | ||
1319 | if (GNUNET_YES == pc->skip_next_fi_callback) | 1316 | if (GNUNET_YES == pc->skip_next_fi_callback) |
1320 | { | 1317 | { |
1321 | pc->skip_next_fi_callback = GNUNET_NO; | 1318 | pc->skip_next_fi_callback = GNUNET_NO; |
1322 | return GNUNET_OK; | 1319 | return GNUNET_OK; |
1323 | } | 1320 | } |
1324 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) | 1321 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) |
1325 | { | 1322 | { |
1326 | /* process entries in directory */ | 1323 | /* process entries in directory */ |
1327 | pc->skip_next_fi_callback = GNUNET_YES; | 1324 | pc->skip_next_fi_callback = GNUNET_YES; |
1328 | GNUNET_FS_file_information_inspect (fi, &fip_signal_suspend, pc); | 1325 | GNUNET_FS_file_information_inspect(fi, &fip_signal_suspend, pc); |
1329 | } | 1326 | } |
1330 | suspend_operation (fi, pc); | 1327 | suspend_operation(fi, pc); |
1331 | *client_info = NULL; | 1328 | *client_info = NULL; |
1332 | return GNUNET_OK; | 1329 | return GNUNET_OK; |
1333 | } | 1330 | } |
@@ -1340,21 +1337,21 @@ fip_signal_suspend (void *cls, | |||
1340 | * @param cls the `struct GNUNET_FS_PublishContext` to signal for | 1337 | * @param cls the `struct GNUNET_FS_PublishContext` to signal for |
1341 | */ | 1338 | */ |
1342 | void | 1339 | void |
1343 | GNUNET_FS_publish_signal_suspend_ (void *cls) | 1340 | GNUNET_FS_publish_signal_suspend_(void *cls) |
1344 | { | 1341 | { |
1345 | struct GNUNET_FS_PublishContext *pc = cls; | 1342 | struct GNUNET_FS_PublishContext *pc = cls; |
1346 | 1343 | ||
1347 | if (NULL != pc->upload_task) | 1344 | if (NULL != pc->upload_task) |
1348 | { | 1345 | { |
1349 | GNUNET_SCHEDULER_cancel (pc->upload_task); | 1346 | GNUNET_SCHEDULER_cancel(pc->upload_task); |
1350 | pc->upload_task = NULL; | 1347 | pc->upload_task = NULL; |
1351 | } | 1348 | } |
1352 | pc->skip_next_fi_callback = GNUNET_YES; | 1349 | pc->skip_next_fi_callback = GNUNET_YES; |
1353 | GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_suspend, pc); | 1350 | GNUNET_FS_file_information_inspect(pc->fi, &fip_signal_suspend, pc); |
1354 | suspend_operation (pc->fi, pc); | 1351 | suspend_operation(pc->fi, pc); |
1355 | GNUNET_FS_end_top (pc->h, pc->top); | 1352 | GNUNET_FS_end_top(pc->h, pc->top); |
1356 | pc->top = NULL; | 1353 | pc->top = NULL; |
1357 | publish_cleanup (pc); | 1354 | publish_cleanup(pc); |
1358 | } | 1355 | } |
1359 | 1356 | ||
1360 | 1357 | ||
@@ -1368,30 +1365,30 @@ GNUNET_FS_publish_signal_suspend_ (void *cls) | |||
1368 | * @param msg error message on error, otherwise NULL | 1365 | * @param msg error message on error, otherwise NULL |
1369 | */ | 1366 | */ |
1370 | static void | 1367 | static void |
1371 | finish_reserve (void *cls, | 1368 | finish_reserve(void *cls, |
1372 | int success, | 1369 | int success, |
1373 | struct GNUNET_TIME_Absolute min_expiration, | 1370 | struct GNUNET_TIME_Absolute min_expiration, |
1374 | const char *msg) | 1371 | const char *msg) |
1375 | { | 1372 | { |
1376 | struct GNUNET_FS_PublishContext *pc = cls; | 1373 | struct GNUNET_FS_PublishContext *pc = cls; |
1377 | 1374 | ||
1378 | pc->qre = NULL; | 1375 | pc->qre = NULL; |
1379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1376 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1380 | "Reservation complete (%d)!\n", | 1377 | "Reservation complete (%d)!\n", |
1381 | success); | 1378 | success); |
1382 | if ((msg != NULL) || (success <= 0)) | 1379 | if ((msg != NULL) || (success <= 0)) |
1383 | { | 1380 | { |
1384 | GNUNET_asprintf (&pc->fi->emsg, | 1381 | GNUNET_asprintf(&pc->fi->emsg, |
1385 | _("Datastore failure: %s"), | 1382 | _("Datastore failure: %s"), |
1386 | msg); | 1383 | msg); |
1387 | signal_publish_error (pc->fi, pc, pc->fi->emsg); | 1384 | signal_publish_error(pc->fi, pc, pc->fi->emsg); |
1388 | return; | 1385 | return; |
1389 | } | 1386 | } |
1390 | pc->rid = success; | 1387 | pc->rid = success; |
1391 | GNUNET_assert (NULL == pc->upload_task); | 1388 | GNUNET_assert(NULL == pc->upload_task); |
1392 | pc->upload_task = | 1389 | pc->upload_task = |
1393 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 1390 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
1394 | &GNUNET_FS_publish_main_, pc); | 1391 | &GNUNET_FS_publish_main_, pc); |
1395 | } | 1392 | } |
1396 | 1393 | ||
1397 | 1394 | ||
@@ -1401,7 +1398,7 @@ finish_reserve (void *cls, | |||
1401 | * @param fi file structure to traverse | 1398 | * @param fi file structure to traverse |
1402 | */ | 1399 | */ |
1403 | static uint64_t | 1400 | static uint64_t |
1404 | compute_contents_size (struct GNUNET_FS_FileInformation *fi) | 1401 | compute_contents_size(struct GNUNET_FS_FileInformation *fi) |
1405 | { | 1402 | { |
1406 | struct GNUNET_FS_FileInformation *ent; | 1403 | struct GNUNET_FS_FileInformation *ent; |
1407 | 1404 | ||
@@ -1409,7 +1406,7 @@ compute_contents_size (struct GNUNET_FS_FileInformation *fi) | |||
1409 | return fi->data.file.file_size; | 1406 | return fi->data.file.file_size; |
1410 | fi->data.dir.contents_size = 0; | 1407 | fi->data.dir.contents_size = 0; |
1411 | for (ent = fi->data.dir.entries; NULL != ent; ent = ent->next) | 1408 | for (ent = fi->data.dir.entries; NULL != ent; ent = ent->next) |
1412 | fi->data.dir.contents_size += compute_contents_size (ent); | 1409 | fi->data.dir.contents_size += compute_contents_size(ent); |
1413 | return fi->data.dir.contents_size; | 1410 | return fi->data.dir.contents_size; |
1414 | } | 1411 | } |
1415 | 1412 | ||
@@ -1428,67 +1425,67 @@ compute_contents_size (struct GNUNET_FS_FileInformation *fi) | |||
1428 | * @return context that can be used to control the publish operation | 1425 | * @return context that can be used to control the publish operation |
1429 | */ | 1426 | */ |
1430 | struct GNUNET_FS_PublishContext * | 1427 | struct GNUNET_FS_PublishContext * |
1431 | GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, | 1428 | GNUNET_FS_publish_start(struct GNUNET_FS_Handle *h, |
1432 | struct GNUNET_FS_FileInformation *fi, | 1429 | struct GNUNET_FS_FileInformation *fi, |
1433 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 1430 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
1434 | const char *nid, | 1431 | const char *nid, |
1435 | const char *nuid, | 1432 | const char *nuid, |
1436 | enum GNUNET_FS_PublishOptions options) | 1433 | enum GNUNET_FS_PublishOptions options) |
1437 | { | 1434 | { |
1438 | struct GNUNET_FS_PublishContext *ret; | 1435 | struct GNUNET_FS_PublishContext *ret; |
1439 | struct GNUNET_DATASTORE_Handle *dsh; | 1436 | struct GNUNET_DATASTORE_Handle *dsh; |
1440 | 1437 | ||
1441 | GNUNET_assert (NULL != h); | 1438 | GNUNET_assert(NULL != h); |
1442 | compute_contents_size (fi); | 1439 | compute_contents_size(fi); |
1443 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) | 1440 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) |
1444 | { | 1441 | { |
1445 | dsh = GNUNET_DATASTORE_connect (h->cfg); | 1442 | dsh = GNUNET_DATASTORE_connect(h->cfg); |
1446 | if (NULL == dsh) | 1443 | if (NULL == dsh) |
1447 | return NULL; | 1444 | return NULL; |
1448 | } | 1445 | } |
1449 | else | 1446 | else |
1450 | { | 1447 | { |
1451 | dsh = NULL; | 1448 | dsh = NULL; |
1452 | } | 1449 | } |
1453 | ret = GNUNET_new (struct GNUNET_FS_PublishContext); | 1450 | ret = GNUNET_new(struct GNUNET_FS_PublishContext); |
1454 | ret->dsh = dsh; | 1451 | ret->dsh = dsh; |
1455 | ret->h = h; | 1452 | ret->h = h; |
1456 | ret->fi = fi; | 1453 | ret->fi = fi; |
1457 | if (NULL != ns) | 1454 | if (NULL != ns) |
1458 | { | 1455 | { |
1459 | ret->ns = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); | 1456 | ret->ns = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPrivateKey); |
1460 | *ret->ns = *ns; | 1457 | *ret->ns = *ns; |
1461 | GNUNET_assert (NULL != nid); | 1458 | GNUNET_assert(NULL != nid); |
1462 | ret->nid = GNUNET_strdup (nid); | 1459 | ret->nid = GNUNET_strdup(nid); |
1463 | if (NULL != nuid) | 1460 | if (NULL != nuid) |
1464 | ret->nuid = GNUNET_strdup (nuid); | 1461 | ret->nuid = GNUNET_strdup(nuid); |
1465 | } | 1462 | } |
1466 | ret->options = options; | 1463 | ret->options = options; |
1467 | /* signal start */ | 1464 | /* signal start */ |
1468 | GNUNET_FS_file_information_inspect (ret->fi, &fip_signal_start, ret); | 1465 | GNUNET_FS_file_information_inspect(ret->fi, &fip_signal_start, ret); |
1469 | ret->fi_pos = ret->fi; | 1466 | ret->fi_pos = ret->fi; |
1470 | ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, ret); | 1467 | ret->top = GNUNET_FS_make_top(h, &GNUNET_FS_publish_signal_suspend_, ret); |
1471 | GNUNET_FS_publish_sync_ (ret); | 1468 | GNUNET_FS_publish_sync_(ret); |
1472 | if (NULL != ret->dsh) | 1469 | if (NULL != ret->dsh) |
1473 | { | 1470 | { |
1474 | GNUNET_assert (NULL == ret->qre); | 1471 | GNUNET_assert(NULL == ret->qre); |
1475 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1472 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1476 | _("Reserving space for %u entries and %llu bytes for publication\n"), | 1473 | _("Reserving space for %u entries and %llu bytes for publication\n"), |
1477 | (unsigned int) ret->reserve_entries, | 1474 | (unsigned int)ret->reserve_entries, |
1478 | (unsigned long long) ret->reserve_space); | 1475 | (unsigned long long)ret->reserve_space); |
1479 | ret->qre = | 1476 | ret->qre = |
1480 | GNUNET_DATASTORE_reserve (ret->dsh, ret->reserve_space, | 1477 | GNUNET_DATASTORE_reserve(ret->dsh, ret->reserve_space, |
1481 | ret->reserve_entries, | 1478 | ret->reserve_entries, |
1482 | &finish_reserve, | 1479 | &finish_reserve, |
1483 | ret); | 1480 | ret); |
1484 | } | 1481 | } |
1485 | else | 1482 | else |
1486 | { | 1483 | { |
1487 | GNUNET_assert (NULL == ret->upload_task); | 1484 | GNUNET_assert(NULL == ret->upload_task); |
1488 | ret->upload_task = | 1485 | ret->upload_task = |
1489 | GNUNET_SCHEDULER_add_with_priority | 1486 | GNUNET_SCHEDULER_add_with_priority |
1490 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret); | 1487 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret); |
1491 | } | 1488 | } |
1492 | return ret; | 1489 | return ret; |
1493 | } | 1490 | } |
1494 | 1491 | ||
@@ -1508,39 +1505,39 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, | |||
1508 | * @return #GNUNET_OK to continue (always) | 1505 | * @return #GNUNET_OK to continue (always) |
1509 | */ | 1506 | */ |
1510 | static int | 1507 | static int |
1511 | fip_signal_stop (void *cls, | 1508 | fip_signal_stop(void *cls, |
1512 | struct GNUNET_FS_FileInformation *fi, | 1509 | struct GNUNET_FS_FileInformation *fi, |
1513 | uint64_t length, | 1510 | uint64_t length, |
1514 | struct GNUNET_CONTAINER_MetaData *meta, | 1511 | struct GNUNET_CONTAINER_MetaData *meta, |
1515 | struct GNUNET_FS_Uri **uri, | 1512 | struct GNUNET_FS_Uri **uri, |
1516 | struct GNUNET_FS_BlockOptions *bo, | 1513 | struct GNUNET_FS_BlockOptions *bo, |
1517 | int *do_index, void **client_info) | 1514 | int *do_index, void **client_info) |
1518 | { | 1515 | { |
1519 | struct GNUNET_FS_PublishContext *pc = cls; | 1516 | struct GNUNET_FS_PublishContext *pc = cls; |
1520 | struct GNUNET_FS_ProgressInfo pi; | 1517 | struct GNUNET_FS_ProgressInfo pi; |
1521 | uint64_t off; | 1518 | uint64_t off; |
1522 | 1519 | ||
1523 | if (GNUNET_YES == pc->skip_next_fi_callback) | 1520 | if (GNUNET_YES == pc->skip_next_fi_callback) |
1524 | { | 1521 | { |
1525 | pc->skip_next_fi_callback = GNUNET_NO; | 1522 | pc->skip_next_fi_callback = GNUNET_NO; |
1526 | return GNUNET_OK; | 1523 | return GNUNET_OK; |
1527 | } | 1524 | } |
1528 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) | 1525 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) |
1529 | { | 1526 | { |
1530 | /* process entries in directory first */ | 1527 | /* process entries in directory first */ |
1531 | pc->skip_next_fi_callback = GNUNET_YES; | 1528 | pc->skip_next_fi_callback = GNUNET_YES; |
1532 | GNUNET_FS_file_information_inspect (fi, &fip_signal_stop, pc); | 1529 | GNUNET_FS_file_information_inspect(fi, &fip_signal_stop, pc); |
1533 | } | 1530 | } |
1534 | if (NULL != fi->serialization) | 1531 | if (NULL != fi->serialization) |
1535 | { | 1532 | { |
1536 | GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, | 1533 | GNUNET_FS_remove_sync_file_(pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, |
1537 | fi->serialization); | 1534 | fi->serialization); |
1538 | GNUNET_free (fi->serialization); | 1535 | GNUNET_free(fi->serialization); |
1539 | fi->serialization = NULL; | 1536 | fi->serialization = NULL; |
1540 | } | 1537 | } |
1541 | off = (fi->chk_uri == NULL) ? 0 : length; | 1538 | off = (fi->chk_uri == NULL) ? 0 : length; |
1542 | pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; | 1539 | pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; |
1543 | GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off)); | 1540 | GNUNET_break(NULL == GNUNET_FS_publish_make_status_(&pi, pc, fi, off)); |
1544 | *client_info = NULL; | 1541 | *client_info = NULL; |
1545 | return GNUNET_OK; | 1542 | return GNUNET_OK; |
1546 | } | 1543 | } |
@@ -1555,56 +1552,56 @@ fip_signal_stop (void *cls, | |||
1555 | * @param pc context for the upload to stop | 1552 | * @param pc context for the upload to stop |
1556 | */ | 1553 | */ |
1557 | void | 1554 | void |
1558 | GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc) | 1555 | GNUNET_FS_publish_stop(struct GNUNET_FS_PublishContext *pc) |
1559 | { | 1556 | { |
1560 | struct GNUNET_FS_ProgressInfo pi; | 1557 | struct GNUNET_FS_ProgressInfo pi; |
1561 | uint64_t off; | 1558 | uint64_t off; |
1562 | 1559 | ||
1563 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1560 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1564 | "Publish stop called\n"); | 1561 | "Publish stop called\n"); |
1565 | GNUNET_FS_end_top (pc->h, pc->top); | 1562 | GNUNET_FS_end_top(pc->h, pc->top); |
1566 | if (NULL != pc->ksk_pc) | 1563 | if (NULL != pc->ksk_pc) |
1567 | { | 1564 | { |
1568 | GNUNET_FS_publish_ksk_cancel (pc->ksk_pc); | 1565 | GNUNET_FS_publish_ksk_cancel(pc->ksk_pc); |
1569 | pc->ksk_pc = NULL; | 1566 | pc->ksk_pc = NULL; |
1570 | } | 1567 | } |
1571 | if (NULL != pc->sks_pc) | 1568 | if (NULL != pc->sks_pc) |
1572 | { | 1569 | { |
1573 | GNUNET_FS_publish_sks_cancel (pc->sks_pc); | 1570 | GNUNET_FS_publish_sks_cancel(pc->sks_pc); |
1574 | pc->sks_pc = NULL; | 1571 | pc->sks_pc = NULL; |
1575 | } | 1572 | } |
1576 | if (NULL != pc->upload_task) | 1573 | if (NULL != pc->upload_task) |
1577 | { | 1574 | { |
1578 | GNUNET_SCHEDULER_cancel (pc->upload_task); | 1575 | GNUNET_SCHEDULER_cancel(pc->upload_task); |
1579 | pc->upload_task = NULL; | 1576 | pc->upload_task = NULL; |
1580 | } | 1577 | } |
1581 | pc->skip_next_fi_callback = GNUNET_YES; | 1578 | pc->skip_next_fi_callback = GNUNET_YES; |
1582 | GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_stop, pc); | 1579 | GNUNET_FS_file_information_inspect(pc->fi, &fip_signal_stop, pc); |
1583 | 1580 | ||
1584 | if (NULL != pc->fi->serialization) | 1581 | if (NULL != pc->fi->serialization) |
1585 | { | 1582 | { |
1586 | GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, | 1583 | GNUNET_FS_remove_sync_file_(pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, |
1587 | pc->fi->serialization); | 1584 | pc->fi->serialization); |
1588 | GNUNET_free (pc->fi->serialization); | 1585 | GNUNET_free(pc->fi->serialization); |
1589 | pc->fi->serialization = NULL; | 1586 | pc->fi->serialization = NULL; |
1590 | } | 1587 | } |
1591 | off = (NULL == pc->fi->chk_uri) ? 0 : GNUNET_ntohll (pc->fi->chk_uri->data.chk.file_length); | 1588 | off = (NULL == pc->fi->chk_uri) ? 0 : GNUNET_ntohll(pc->fi->chk_uri->data.chk.file_length); |
1592 | 1589 | ||
1593 | if (NULL != pc->serialization) | 1590 | if (NULL != pc->serialization) |
1594 | { | 1591 | { |
1595 | GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1592 | GNUNET_FS_remove_sync_file_(pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
1596 | pc->serialization); | 1593 | pc->serialization); |
1597 | GNUNET_free (pc->serialization); | 1594 | GNUNET_free(pc->serialization); |
1598 | pc->serialization = NULL; | 1595 | pc->serialization = NULL; |
1599 | } | 1596 | } |
1600 | if (NULL != pc->qre) | 1597 | if (NULL != pc->qre) |
1601 | { | 1598 | { |
1602 | GNUNET_DATASTORE_cancel (pc->qre); | 1599 | GNUNET_DATASTORE_cancel(pc->qre); |
1603 | pc->qre = NULL; | 1600 | pc->qre = NULL; |
1604 | } | 1601 | } |
1605 | pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; | 1602 | pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; |
1606 | GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi, off)); | 1603 | GNUNET_break(NULL == GNUNET_FS_publish_make_status_(&pi, pc, pc->fi, off)); |
1607 | publish_cleanup (pc); | 1604 | publish_cleanup(pc); |
1608 | } | 1605 | } |
1609 | 1606 | ||
1610 | 1607 | ||
diff --git a/src/fs/fs_publish_ksk.c b/src/fs/fs_publish_ksk.c index e7f6408fd..151b8256c 100644 --- a/src/fs/fs_publish_ksk.c +++ b/src/fs/fs_publish_ksk.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_publish_ksk.c | 22 | * @file fs/fs_publish_ksk.c |
@@ -38,9 +38,7 @@ | |||
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 | { | ||
43 | |||
44 | /** | 42 | /** |
45 | * Keywords to use. | 43 | * Keywords to use. |
46 | */ | 44 | */ |
@@ -100,7 +98,6 @@ struct GNUNET_FS_PublishKskContext | |||
100 | * Keyword that we are currently processing. | 98 | * Keyword that we are currently processing. |
101 | */ | 99 | */ |
102 | unsigned int i; | 100 | unsigned int i; |
103 | |||
104 | }; | 101 | }; |
105 | 102 | ||
106 | 103 | ||
@@ -112,7 +109,7 @@ struct GNUNET_FS_PublishKskContext | |||
112 | * @param cls closure of type `struct PublishKskContext *` | 109 | * @param cls closure of type `struct PublishKskContext *` |
113 | */ | 110 | */ |
114 | static void | 111 | static void |
115 | publish_ksk_cont (void *cls); | 112 | publish_ksk_cont(void *cls); |
116 | 113 | ||
117 | 114 | ||
118 | /** | 115 | /** |
@@ -123,21 +120,21 @@ publish_ksk_cont (void *cls); | |||
123 | * @param msg error message (or NULL) | 120 | * @param msg error message (or NULL) |
124 | */ | 121 | */ |
125 | static void | 122 | static void |
126 | kb_put_cont (void *cls, | 123 | kb_put_cont(void *cls, |
127 | const char *msg) | 124 | const char *msg) |
128 | { | 125 | { |
129 | struct GNUNET_FS_PublishKskContext *pkc = cls; | 126 | struct GNUNET_FS_PublishKskContext *pkc = cls; |
130 | 127 | ||
131 | pkc->uc = NULL; | 128 | pkc->uc = NULL; |
132 | if (NULL != msg) | 129 | if (NULL != msg) |
133 | { | 130 | { |
134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 131 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
135 | "KBlock PUT operation failed: %s\n", msg); | 132 | "KBlock PUT operation failed: %s\n", msg); |
136 | pkc->cont (pkc->cont_cls, NULL, msg); | 133 | pkc->cont(pkc->cont_cls, NULL, msg); |
137 | GNUNET_FS_publish_ksk_cancel (pkc); | 134 | GNUNET_FS_publish_ksk_cancel(pkc); |
138 | return; | 135 | return; |
139 | } | 136 | } |
140 | pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc); | 137 | pkc->ksk_task = GNUNET_SCHEDULER_add_now(&publish_ksk_cont, pkc); |
141 | } | 138 | } |
142 | 139 | ||
143 | 140 | ||
@@ -148,33 +145,33 @@ kb_put_cont (void *cls, | |||
148 | * @param cls closure of type `struct GNUNET_FS_PublishKskContext *` | 145 | * @param cls closure of type `struct GNUNET_FS_PublishKskContext *` |
149 | */ | 146 | */ |
150 | static void | 147 | static void |
151 | publish_ksk_cont (void *cls) | 148 | publish_ksk_cont(void *cls) |
152 | { | 149 | { |
153 | struct GNUNET_FS_PublishKskContext *pkc = cls; | 150 | struct GNUNET_FS_PublishKskContext *pkc = cls; |
154 | const char *keyword; | 151 | const char *keyword; |
155 | 152 | ||
156 | pkc->ksk_task = NULL; | 153 | pkc->ksk_task = NULL; |
157 | if ( (pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || | 154 | if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || |
158 | (NULL == pkc->dsh) ) | 155 | (NULL == pkc->dsh)) |
159 | { | 156 | { |
160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 157 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
161 | "KSK PUT operation complete\n"); | 158 | "KSK PUT operation complete\n"); |
162 | pkc->cont (pkc->cont_cls, pkc->ksk_uri, | 159 | pkc->cont(pkc->cont_cls, pkc->ksk_uri, |
163 | NULL); | 160 | NULL); |
164 | GNUNET_FS_publish_ksk_cancel (pkc); | 161 | GNUNET_FS_publish_ksk_cancel(pkc); |
165 | return; | 162 | return; |
166 | } | 163 | } |
167 | keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++]; | 164 | keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++]; |
168 | pkc->uc = GNUNET_FS_publish_ublock_ (pkc->h, | 165 | pkc->uc = GNUNET_FS_publish_ublock_(pkc->h, |
169 | pkc->dsh, | 166 | pkc->dsh, |
170 | keyword + 1 /* skip '+' */, | 167 | keyword + 1 /* skip '+' */, |
171 | NULL, | 168 | NULL, |
172 | GNUNET_CRYPTO_ecdsa_key_get_anonymous (), | 169 | GNUNET_CRYPTO_ecdsa_key_get_anonymous(), |
173 | pkc->meta, | 170 | pkc->meta, |
174 | pkc->uri, | 171 | pkc->uri, |
175 | &pkc->bo, | 172 | &pkc->bo, |
176 | pkc->options, | 173 | pkc->options, |
177 | &kb_put_cont, pkc); | 174 | &kb_put_cont, pkc); |
178 | } | 175 | } |
179 | 176 | ||
180 | 177 | ||
@@ -192,39 +189,39 @@ publish_ksk_cont (void *cls) | |||
192 | * @return NULL on error ('cont' will still be called) | 189 | * @return NULL on error ('cont' will still be called) |
193 | */ | 190 | */ |
194 | struct GNUNET_FS_PublishKskContext * | 191 | struct GNUNET_FS_PublishKskContext * |
195 | GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, | 192 | GNUNET_FS_publish_ksk(struct GNUNET_FS_Handle *h, |
196 | const struct GNUNET_FS_Uri *ksk_uri, | 193 | const struct GNUNET_FS_Uri *ksk_uri, |
197 | const struct GNUNET_CONTAINER_MetaData *meta, | 194 | const struct GNUNET_CONTAINER_MetaData *meta, |
198 | const struct GNUNET_FS_Uri *uri, | 195 | const struct GNUNET_FS_Uri *uri, |
199 | const struct GNUNET_FS_BlockOptions *bo, | 196 | const struct GNUNET_FS_BlockOptions *bo, |
200 | enum GNUNET_FS_PublishOptions options, | 197 | enum GNUNET_FS_PublishOptions options, |
201 | GNUNET_FS_PublishContinuation cont, void *cont_cls) | 198 | GNUNET_FS_PublishContinuation cont, void *cont_cls) |
202 | { | 199 | { |
203 | struct GNUNET_FS_PublishKskContext *pkc; | 200 | struct GNUNET_FS_PublishKskContext *pkc; |
204 | 201 | ||
205 | GNUNET_assert (NULL != uri); | 202 | GNUNET_assert(NULL != uri); |
206 | pkc = GNUNET_new (struct GNUNET_FS_PublishKskContext); | 203 | pkc = GNUNET_new(struct GNUNET_FS_PublishKskContext); |
207 | pkc->h = h; | 204 | pkc->h = h; |
208 | pkc->bo = *bo; | 205 | pkc->bo = *bo; |
209 | pkc->options = options; | 206 | pkc->options = options; |
210 | pkc->cont = cont; | 207 | pkc->cont = cont; |
211 | pkc->cont_cls = cont_cls; | 208 | pkc->cont_cls = cont_cls; |
212 | pkc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 209 | pkc->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); |
213 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) | 210 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) |
214 | { | ||
215 | pkc->dsh = GNUNET_DATASTORE_connect (h->cfg); | ||
216 | if (NULL == pkc->dsh) | ||
217 | { | 211 | { |
218 | cont (cont_cls, | 212 | pkc->dsh = GNUNET_DATASTORE_connect(h->cfg); |
219 | NULL, | 213 | if (NULL == pkc->dsh) |
220 | _("Could not connect to datastore.")); | 214 | { |
221 | GNUNET_free (pkc); | 215 | cont(cont_cls, |
222 | return NULL; | 216 | NULL, |
217 | _("Could not connect to datastore.")); | ||
218 | GNUNET_free(pkc); | ||
219 | return NULL; | ||
220 | } | ||
223 | } | 221 | } |
224 | } | 222 | pkc->uri = GNUNET_FS_uri_dup(uri); |
225 | pkc->uri = GNUNET_FS_uri_dup (uri); | 223 | pkc->ksk_uri = GNUNET_FS_uri_dup(ksk_uri); |
226 | pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri); | 224 | pkc->ksk_task = GNUNET_SCHEDULER_add_now(&publish_ksk_cont, pkc); |
227 | pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc); | ||
228 | return pkc; | 225 | return pkc; |
229 | } | 226 | } |
230 | 227 | ||
@@ -235,27 +232,27 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, | |||
235 | * @param pkc context of the operation to abort. | 232 | * @param pkc context of the operation to abort. |
236 | */ | 233 | */ |
237 | void | 234 | void |
238 | GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc) | 235 | GNUNET_FS_publish_ksk_cancel(struct GNUNET_FS_PublishKskContext *pkc) |
239 | { | 236 | { |
240 | if (NULL != pkc->ksk_task) | 237 | if (NULL != pkc->ksk_task) |
241 | { | 238 | { |
242 | GNUNET_SCHEDULER_cancel (pkc->ksk_task); | 239 | GNUNET_SCHEDULER_cancel(pkc->ksk_task); |
243 | pkc->ksk_task = NULL; | 240 | pkc->ksk_task = NULL; |
244 | } | 241 | } |
245 | if (NULL != pkc->uc) | 242 | if (NULL != pkc->uc) |
246 | { | 243 | { |
247 | GNUNET_FS_publish_ublock_cancel_ (pkc->uc); | 244 | GNUNET_FS_publish_ublock_cancel_(pkc->uc); |
248 | pkc->uc = NULL; | 245 | pkc->uc = NULL; |
249 | } | 246 | } |
250 | if (NULL != pkc->dsh) | 247 | if (NULL != pkc->dsh) |
251 | { | 248 | { |
252 | GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO); | 249 | GNUNET_DATASTORE_disconnect(pkc->dsh, GNUNET_NO); |
253 | pkc->dsh = NULL; | 250 | pkc->dsh = NULL; |
254 | } | 251 | } |
255 | GNUNET_CONTAINER_meta_data_destroy (pkc->meta); | 252 | GNUNET_CONTAINER_meta_data_destroy(pkc->meta); |
256 | GNUNET_FS_uri_destroy (pkc->ksk_uri); | 253 | GNUNET_FS_uri_destroy(pkc->ksk_uri); |
257 | GNUNET_FS_uri_destroy (pkc->uri); | 254 | GNUNET_FS_uri_destroy(pkc->uri); |
258 | GNUNET_free (pkc); | 255 | GNUNET_free(pkc); |
259 | } | 256 | } |
260 | 257 | ||
261 | 258 | ||
diff --git a/src/fs/fs_publish_ublock.c b/src/fs/fs_publish_ublock.c index 368a4aff4..4dfb4a585 100644 --- a/src/fs/fs_publish_ublock.c +++ b/src/fs/fs_publish_ublock.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_publish_ublock.c | 22 | * @file fs/fs_publish_ublock.c |
@@ -43,21 +43,21 @@ | |||
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 *iv, |
48 | const char *label, | 48 | const char *label, |
49 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) | 49 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) |
50 | { | 50 | { |
51 | struct GNUNET_HashCode key; | 51 | struct GNUNET_HashCode key; |
52 | 52 | ||
53 | /* derive key from 'label' and public key of the namespace */ | 53 | /* derive key from 'label' and public key of the namespace */ |
54 | GNUNET_assert (GNUNET_YES == | 54 | GNUNET_assert(GNUNET_YES == |
55 | GNUNET_CRYPTO_kdf (&key, sizeof (key), | 55 | GNUNET_CRYPTO_kdf(&key, sizeof(key), |
56 | "UBLOCK-ENC", strlen ("UBLOCK-ENC"), | 56 | "UBLOCK-ENC", strlen("UBLOCK-ENC"), |
57 | label, strlen (label), | 57 | label, strlen(label), |
58 | pub, sizeof (*pub), | 58 | pub, sizeof(*pub), |
59 | NULL, 0)); | 59 | NULL, 0)); |
60 | GNUNET_CRYPTO_hash_to_aes_key (&key, skey, iv); | 60 | GNUNET_CRYPTO_hash_to_aes_key(&key, skey, iv); |
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
@@ -71,29 +71,27 @@ derive_ublock_encryption_key (struct GNUNET_CRYPTO_SymmetricSessionKey *skey, | |||
71 | * @param output where to write the result, has input_len bytes | 71 | * @param output where to write the result, has input_len bytes |
72 | */ | 72 | */ |
73 | void | 73 | void |
74 | GNUNET_FS_ublock_decrypt_ (const void *input, | 74 | GNUNET_FS_ublock_decrypt_(const void *input, |
75 | size_t input_len, | 75 | size_t input_len, |
76 | const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, | 76 | const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, |
77 | const char *label, | 77 | const char *label, |
78 | void *output) | 78 | void *output) |
79 | { | 79 | { |
80 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 80 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
81 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 81 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; |
82 | 82 | ||
83 | derive_ublock_encryption_key (&skey, &iv, | 83 | derive_ublock_encryption_key(&skey, &iv, |
84 | label, ns); | 84 | label, ns); |
85 | GNUNET_CRYPTO_symmetric_decrypt (input, input_len, | 85 | GNUNET_CRYPTO_symmetric_decrypt(input, input_len, |
86 | &skey, &iv, | 86 | &skey, &iv, |
87 | output); | 87 | output); |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Context for 'ublock_put_cont'. | 92 | * Context for 'ublock_put_cont'. |
93 | */ | 93 | */ |
94 | struct GNUNET_FS_PublishUblockContext | 94 | struct GNUNET_FS_PublishUblockContext { |
95 | { | ||
96 | |||
97 | /** | 95 | /** |
98 | * Function to call when done. | 96 | * Function to call when done. |
99 | */ | 97 | */ |
@@ -113,7 +111,6 @@ struct GNUNET_FS_PublishUblockContext | |||
113 | * Task to run continuation asynchronously. | 111 | * Task to run continuation asynchronously. |
114 | */ | 112 | */ |
115 | struct GNUNET_SCHEDULER_Task * task; | 113 | struct GNUNET_SCHEDULER_Task * task; |
116 | |||
117 | }; | 114 | }; |
118 | 115 | ||
119 | 116 | ||
@@ -130,16 +127,16 @@ struct GNUNET_FS_PublishUblockContext | |||
130 | * @param msg NULL on success, otherwise an error message | 127 | * @param msg NULL on success, otherwise an error message |
131 | */ | 128 | */ |
132 | static void | 129 | static void |
133 | ublock_put_cont (void *cls, | 130 | ublock_put_cont(void *cls, |
134 | int32_t success, | 131 | int32_t success, |
135 | struct GNUNET_TIME_Absolute min_expiration, | 132 | struct GNUNET_TIME_Absolute min_expiration, |
136 | const char *msg) | 133 | const char *msg) |
137 | { | 134 | { |
138 | struct GNUNET_FS_PublishUblockContext *uc = cls; | 135 | struct GNUNET_FS_PublishUblockContext *uc = cls; |
139 | 136 | ||
140 | uc->qre = NULL; | 137 | uc->qre = NULL; |
141 | uc->cont (uc->cont_cls, msg); | 138 | uc->cont(uc->cont_cls, msg); |
142 | GNUNET_free (uc); | 139 | GNUNET_free(uc); |
143 | } | 140 | } |
144 | 141 | ||
145 | 142 | ||
@@ -149,13 +146,13 @@ ublock_put_cont (void *cls, | |||
149 | * @param cls the `struct GNUNET_FS_PublishUblockContext *` | 146 | * @param cls the `struct GNUNET_FS_PublishUblockContext *` |
150 | */ | 147 | */ |
151 | static void | 148 | static void |
152 | run_cont (void *cls) | 149 | run_cont(void *cls) |
153 | { | 150 | { |
154 | struct GNUNET_FS_PublishUblockContext *uc = cls; | 151 | struct GNUNET_FS_PublishUblockContext *uc = cls; |
155 | 152 | ||
156 | uc->task = NULL; | 153 | uc->task = NULL; |
157 | uc->cont (uc->cont_cls, NULL); | 154 | uc->cont(uc->cont_cls, NULL); |
158 | GNUNET_free (uc); | 155 | GNUNET_free(uc); |
159 | } | 156 | } |
160 | 157 | ||
161 | 158 | ||
@@ -176,16 +173,16 @@ run_cont (void *cls) | |||
176 | * @return NULL on error (@a cont will still be called) | 173 | * @return NULL on error (@a cont will still be called) |
177 | */ | 174 | */ |
178 | struct GNUNET_FS_PublishUblockContext * | 175 | struct GNUNET_FS_PublishUblockContext * |
179 | GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, | 176 | GNUNET_FS_publish_ublock_(struct GNUNET_FS_Handle *h, |
180 | struct GNUNET_DATASTORE_Handle *dsh, | 177 | struct GNUNET_DATASTORE_Handle *dsh, |
181 | const char *label, | 178 | const char *label, |
182 | const char *ulabel, | 179 | const char *ulabel, |
183 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 180 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
184 | const struct GNUNET_CONTAINER_MetaData *meta, | 181 | const struct GNUNET_CONTAINER_MetaData *meta, |
185 | const struct GNUNET_FS_Uri *uri, | 182 | const struct GNUNET_FS_Uri *uri, |
186 | const struct GNUNET_FS_BlockOptions *bo, | 183 | const struct GNUNET_FS_BlockOptions *bo, |
187 | enum GNUNET_FS_PublishOptions options, | 184 | enum GNUNET_FS_PublishOptions options, |
188 | GNUNET_FS_UBlockContinuation cont, void *cont_cls) | 185 | GNUNET_FS_UBlockContinuation cont, void *cont_cls) |
189 | { | 186 | { |
190 | struct GNUNET_FS_PublishUblockContext *uc; | 187 | struct GNUNET_FS_PublishUblockContext *uc; |
191 | struct GNUNET_HashCode query; | 188 | struct GNUNET_HashCode query; |
@@ -207,101 +204,101 @@ GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, | |||
207 | if (NULL == meta) | 204 | if (NULL == meta) |
208 | mdsize = 0; | 205 | mdsize = 0; |
209 | else | 206 | else |
210 | mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); | 207 | mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size(meta); |
211 | GNUNET_assert (mdsize >= 0); | 208 | GNUNET_assert(mdsize >= 0); |
212 | uris = GNUNET_FS_uri_to_string (uri); | 209 | uris = GNUNET_FS_uri_to_string(uri); |
213 | slen = strlen (uris) + 1; | 210 | slen = strlen(uris) + 1; |
214 | if (NULL == ulabel) | 211 | if (NULL == ulabel) |
215 | ulen = 1; | 212 | ulen = 1; |
216 | else | 213 | else |
217 | ulen = strlen (ulabel) + 1; | 214 | ulen = strlen(ulabel) + 1; |
218 | size = mdsize + sizeof (struct UBlock) + slen + ulen; | 215 | size = mdsize + sizeof(struct UBlock) + slen + ulen; |
219 | if (size > MAX_UBLOCK_SIZE) | 216 | if (size > MAX_UBLOCK_SIZE) |
220 | { | 217 | { |
221 | size = MAX_UBLOCK_SIZE; | 218 | size = MAX_UBLOCK_SIZE; |
222 | mdsize = size - sizeof (struct UBlock) - (slen + ulen); | 219 | mdsize = size - sizeof(struct UBlock) - (slen + ulen); |
223 | } | 220 | } |
224 | ub_plain = GNUNET_malloc (size); | 221 | ub_plain = GNUNET_malloc(size); |
225 | kbe = (char *) &ub_plain[1]; | 222 | kbe = (char *)&ub_plain[1]; |
226 | if (NULL != ulabel) | 223 | if (NULL != ulabel) |
227 | GNUNET_memcpy (kbe, ulabel, ulen); | 224 | GNUNET_memcpy(kbe, ulabel, ulen); |
228 | kbe += ulen; | 225 | kbe += ulen; |
229 | GNUNET_memcpy (kbe, uris, slen); | 226 | GNUNET_memcpy(kbe, uris, slen); |
230 | kbe += slen; | 227 | kbe += slen; |
231 | GNUNET_free (uris); | 228 | GNUNET_free(uris); |
232 | sptr = kbe; | 229 | sptr = kbe; |
233 | if (NULL != meta) | 230 | if (NULL != meta) |
234 | mdsize = | 231 | mdsize = |
235 | GNUNET_CONTAINER_meta_data_serialize (meta, &sptr, mdsize, | 232 | GNUNET_CONTAINER_meta_data_serialize(meta, &sptr, mdsize, |
236 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | 233 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); |
237 | if (-1 == mdsize) | 234 | if (-1 == mdsize) |
238 | { | 235 | { |
239 | GNUNET_break (0); | 236 | GNUNET_break(0); |
240 | GNUNET_free (ub_plain); | 237 | GNUNET_free(ub_plain); |
241 | cont (cont_cls, _("Internal error.")); | 238 | cont(cont_cls, _("Internal error.")); |
242 | return NULL; | 239 | return NULL; |
243 | } | 240 | } |
244 | size = sizeof (struct UBlock) + slen + mdsize + ulen; | 241 | size = sizeof(struct UBlock) + slen + mdsize + ulen; |
245 | 242 | ||
246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 243 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
247 | "Publishing under identifier `%s'\n", | 244 | "Publishing under identifier `%s'\n", |
248 | label); | 245 | label); |
249 | /* get public key of the namespace */ | 246 | /* get public key of the namespace */ |
250 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, | 247 | GNUNET_CRYPTO_ecdsa_key_get_public(ns, |
251 | &pub); | 248 | &pub); |
252 | derive_ublock_encryption_key (&skey, &iv, | 249 | derive_ublock_encryption_key(&skey, &iv, |
253 | label, &pub); | 250 | label, &pub); |
254 | 251 | ||
255 | /* encrypt ublock */ | 252 | /* encrypt ublock */ |
256 | ub_enc = GNUNET_malloc (size); | 253 | ub_enc = GNUNET_malloc(size); |
257 | GNUNET_CRYPTO_symmetric_encrypt (&ub_plain[1], | 254 | GNUNET_CRYPTO_symmetric_encrypt(&ub_plain[1], |
258 | ulen + slen + mdsize, | 255 | ulen + slen + mdsize, |
259 | &skey, &iv, | 256 | &skey, &iv, |
260 | &ub_enc[1]); | 257 | &ub_enc[1]); |
261 | GNUNET_free (ub_plain); | 258 | GNUNET_free(ub_plain); |
262 | ub_enc->purpose.size = htonl (ulen + slen + mdsize + | 259 | ub_enc->purpose.size = htonl(ulen + slen + mdsize + |
263 | sizeof (struct UBlock) | 260 | sizeof(struct UBlock) |
264 | - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | 261 | - sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); |
265 | ub_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK); | 262 | ub_enc->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK); |
266 | 263 | ||
267 | /* derive signing-key from 'label' and public key of the namespace */ | 264 | /* derive signing-key from 'label' and public key of the namespace */ |
268 | nsd = GNUNET_CRYPTO_ecdsa_private_key_derive (ns, label, "fs-ublock"); | 265 | nsd = GNUNET_CRYPTO_ecdsa_private_key_derive(ns, label, "fs-ublock"); |
269 | GNUNET_CRYPTO_ecdsa_key_get_public (nsd, | 266 | GNUNET_CRYPTO_ecdsa_key_get_public(nsd, |
270 | &ub_enc->verification_key); | 267 | &ub_enc->verification_key); |
271 | GNUNET_assert (GNUNET_OK == | 268 | GNUNET_assert(GNUNET_OK == |
272 | GNUNET_CRYPTO_ecdsa_sign (nsd, | 269 | GNUNET_CRYPTO_ecdsa_sign(nsd, |
273 | &ub_enc->purpose, | 270 | &ub_enc->purpose, |
274 | &ub_enc->signature)); | 271 | &ub_enc->signature)); |
275 | GNUNET_CRYPTO_hash (&ub_enc->verification_key, | 272 | GNUNET_CRYPTO_hash(&ub_enc->verification_key, |
276 | sizeof (ub_enc->verification_key), | 273 | sizeof(ub_enc->verification_key), |
277 | &query); | 274 | &query); |
278 | GNUNET_free (nsd); | 275 | GNUNET_free(nsd); |
279 | 276 | ||
280 | uc = GNUNET_new (struct GNUNET_FS_PublishUblockContext); | 277 | uc = GNUNET_new(struct GNUNET_FS_PublishUblockContext); |
281 | uc->cont = cont; | 278 | uc->cont = cont; |
282 | uc->cont_cls = cont_cls; | 279 | uc->cont_cls = cont_cls; |
283 | if (NULL != dsh) | 280 | if (NULL != dsh) |
284 | { | 281 | { |
285 | uc->qre = | 282 | uc->qre = |
286 | GNUNET_DATASTORE_put (dsh, | 283 | GNUNET_DATASTORE_put(dsh, |
287 | 0, | 284 | 0, |
288 | &query, | 285 | &query, |
289 | ulen + slen + mdsize + sizeof (struct UBlock), | 286 | ulen + slen + mdsize + sizeof(struct UBlock), |
290 | ub_enc, | 287 | ub_enc, |
291 | GNUNET_BLOCK_TYPE_FS_UBLOCK, | 288 | GNUNET_BLOCK_TYPE_FS_UBLOCK, |
292 | bo->content_priority, | 289 | bo->content_priority, |
293 | bo->anonymity_level, | 290 | bo->anonymity_level, |
294 | bo->replication_level, | 291 | bo->replication_level, |
295 | bo->expiration_time, | 292 | bo->expiration_time, |
296 | -2, 1, | 293 | -2, 1, |
297 | &ublock_put_cont, uc); | 294 | &ublock_put_cont, uc); |
298 | } | 295 | } |
299 | else | 296 | else |
300 | { | 297 | { |
301 | uc->task = GNUNET_SCHEDULER_add_now (&run_cont, | 298 | uc->task = GNUNET_SCHEDULER_add_now(&run_cont, |
302 | uc); | 299 | uc); |
303 | } | 300 | } |
304 | GNUNET_free (ub_enc); | 301 | GNUNET_free(ub_enc); |
305 | return uc; | 302 | return uc; |
306 | } | 303 | } |
307 | 304 | ||
@@ -312,13 +309,13 @@ GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, | |||
312 | * @param uc operation to abort. | 309 | * @param uc operation to abort. |
313 | */ | 310 | */ |
314 | void | 311 | void |
315 | GNUNET_FS_publish_ublock_cancel_ (struct GNUNET_FS_PublishUblockContext *uc) | 312 | GNUNET_FS_publish_ublock_cancel_(struct GNUNET_FS_PublishUblockContext *uc) |
316 | { | 313 | { |
317 | if (NULL != uc->qre) | 314 | if (NULL != uc->qre) |
318 | GNUNET_DATASTORE_cancel (uc->qre); | 315 | GNUNET_DATASTORE_cancel(uc->qre); |
319 | if (NULL != uc->task) | 316 | if (NULL != uc->task) |
320 | GNUNET_SCHEDULER_cancel (uc->task); | 317 | GNUNET_SCHEDULER_cancel(uc->task); |
321 | GNUNET_free (uc); | 318 | GNUNET_free(uc); |
322 | } | 319 | } |
323 | 320 | ||
324 | /* end of fs_publish_ublock.c */ | 321 | /* end of fs_publish_ublock.c */ |
diff --git a/src/fs/fs_publish_ublock.h b/src/fs/fs_publish_ublock.h index ad07e5f6f..9d0a518c6 100644 --- a/src/fs/fs_publish_ublock.h +++ b/src/fs/fs_publish_ublock.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_publish_ublock.h | 22 | * @file 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 | /** |
@@ -65,7 +65,7 @@ struct GNUNET_FS_PublishUblockContext; | |||
65 | * @param emsg error message, NULL on success | 65 | * @param emsg error message, NULL on success |
66 | */ | 66 | */ |
67 | typedef void (*GNUNET_FS_UBlockContinuation) (void *cls, | 67 | typedef void (*GNUNET_FS_UBlockContinuation) (void *cls, |
68 | const char *emsg); | 68 | const char *emsg); |
69 | 69 | ||
70 | 70 | ||
71 | /** | 71 | /** |
@@ -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 e808d3eaa..662bc1619 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/fs_search.c | 21 | * @file fs/fs_search.c |
22 | * @brief Helper functions for searching. | 22 | * @brief Helper functions for searching. |
@@ -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,11 @@ 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(sc->start_time) |
63 | : GNUNET_TIME_UNIT_ZERO; | 63 | : GNUNET_TIME_UNIT_ZERO; |
64 | pi->value.search.anonymity = (NULL != sc) ? sc->anonymity : 0; | 64 | pi->value.search.anonymity = (NULL != sc) ? sc->anonymity : 0; |
65 | pi->fsh = h; | 65 | pi->fsh = h; |
66 | ret = h->upcb (h->upcb_cls, pi); | 66 | ret = h->upcb(h->upcb_cls, pi); |
67 | return ret; | 67 | return ret; |
68 | } | 68 | } |
69 | 69 | ||
@@ -79,14 +79,14 @@ GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
79 | * #GNUNET_OK otherwise | 79 | * #GNUNET_OK otherwise |
80 | */ | 80 | */ |
81 | static int | 81 | static int |
82 | test_result_present (void *cls, | 82 | test_result_present(void *cls, |
83 | const struct GNUNET_HashCode * key, | 83 | const struct GNUNET_HashCode * key, |
84 | void *value) | 84 | void *value) |
85 | { | 85 | { |
86 | const struct GNUNET_FS_Uri *uri = cls; | 86 | const struct GNUNET_FS_Uri *uri = cls; |
87 | struct GNUNET_FS_SearchResult *sr = value; | 87 | struct GNUNET_FS_SearchResult *sr = value; |
88 | 88 | ||
89 | if (GNUNET_FS_uri_test_equal (uri, sr->uri)) | 89 | if (GNUNET_FS_uri_test_equal(uri, sr->uri)) |
90 | return GNUNET_SYSERR; | 90 | return GNUNET_SYSERR; |
91 | return GNUNET_OK; | 91 | return GNUNET_OK; |
92 | } | 92 | } |
@@ -100,8 +100,8 @@ test_result_present (void *cls, | |||
100 | * @param sr the specific result | 100 | * @param sr the specific result |
101 | */ | 101 | */ |
102 | static void | 102 | static void |
103 | notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, | 103 | notify_client_chk_result(struct GNUNET_FS_SearchContext *sc, |
104 | struct GNUNET_FS_SearchResult *sr) | 104 | struct GNUNET_FS_SearchResult *sr) |
105 | { | 105 | { |
106 | struct GNUNET_FS_ProgressInfo pi; | 106 | struct GNUNET_FS_ProgressInfo pi; |
107 | 107 | ||
@@ -110,7 +110,7 @@ notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, | |||
110 | pi.value.search.specifics.result.uri = sr->uri; | 110 | pi.value.search.specifics.result.uri = sr->uri; |
111 | pi.value.search.specifics.result.result = sr; | 111 | pi.value.search.specifics.result.result = sr; |
112 | pi.value.search.specifics.result.applicability_rank = sr->optional_support; | 112 | pi.value.search.specifics.result.applicability_rank = sr->optional_support; |
113 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 113 | sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); |
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
@@ -122,8 +122,8 @@ notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, | |||
122 | * @param sr the specific result | 122 | * @param sr the specific result |
123 | */ | 123 | */ |
124 | static void | 124 | static void |
125 | notify_client_chk_update (struct GNUNET_FS_SearchContext *sc, | 125 | notify_client_chk_update(struct GNUNET_FS_SearchContext *sc, |
126 | struct GNUNET_FS_SearchResult *sr) | 126 | struct GNUNET_FS_SearchResult *sr) |
127 | { | 127 | { |
128 | struct GNUNET_FS_ProgressInfo pi; | 128 | struct GNUNET_FS_ProgressInfo pi; |
129 | 129 | ||
@@ -132,21 +132,20 @@ notify_client_chk_update (struct GNUNET_FS_SearchContext *sc, | |||
132 | pi.value.search.specifics.update.meta = sr->meta; | 132 | pi.value.search.specifics.update.meta = sr->meta; |
133 | pi.value.search.specifics.update.uri = sr->uri; | 133 | pi.value.search.specifics.update.uri = sr->uri; |
134 | pi.value.search.specifics.update.availability_rank = | 134 | pi.value.search.specifics.update.availability_rank = |
135 | 2 * sr->availability_success - sr->availability_trials; | 135 | 2 * sr->availability_success - sr->availability_trials; |
136 | pi.value.search.specifics.update.availability_certainty = | 136 | pi.value.search.specifics.update.availability_certainty = |
137 | sr->availability_trials; | 137 | sr->availability_trials; |
138 | pi.value.search.specifics.update.applicability_rank = sr->optional_support; | 138 | pi.value.search.specifics.update.applicability_rank = sr->optional_support; |
139 | pi.value.search.specifics.update.current_probe_time | 139 | pi.value.search.specifics.update.current_probe_time |
140 | = GNUNET_TIME_absolute_get_duration (sr->probe_active_time); | 140 | = GNUNET_TIME_absolute_get_duration(sr->probe_active_time); |
141 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 141 | sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | /** | 145 | /** |
146 | * Context for "get_result_present". | 146 | * Context for "get_result_present". |
147 | */ | 147 | */ |
148 | struct GetResultContext | 148 | struct GetResultContext { |
149 | { | ||
150 | /** | 149 | /** |
151 | * The URI we're looking for. | 150 | * The URI we're looking for. |
152 | */ | 151 | */ |
@@ -171,14 +170,14 @@ struct GetResultContext | |||
171 | * @return #GNUNET_OK | 170 | * @return #GNUNET_OK |
172 | */ | 171 | */ |
173 | static int | 172 | static int |
174 | get_result_present (void *cls, | 173 | get_result_present(void *cls, |
175 | const struct GNUNET_HashCode *key, | 174 | const struct GNUNET_HashCode *key, |
176 | void *value) | 175 | void *value) |
177 | { | 176 | { |
178 | struct GetResultContext *grc = cls; | 177 | struct GetResultContext *grc = cls; |
179 | struct GNUNET_FS_SearchResult *sr = value; | 178 | struct GNUNET_FS_SearchResult *sr = value; |
180 | 179 | ||
181 | if (GNUNET_FS_uri_test_equal (grc->uri, sr->uri)) | 180 | if (GNUNET_FS_uri_test_equal(grc->uri, sr->uri)) |
182 | grc->sr = sr; | 181 | grc->sr = sr; |
183 | return GNUNET_OK; | 182 | return GNUNET_OK; |
184 | } | 183 | } |
@@ -191,7 +190,7 @@ get_result_present (void *cls, | |||
191 | * @param sr search result to signal for | 190 | * @param sr search result to signal for |
192 | */ | 191 | */ |
193 | static void | 192 | static void |
194 | signal_probe_result (struct GNUNET_FS_SearchResult *sr) | 193 | signal_probe_result(struct GNUNET_FS_SearchResult *sr) |
195 | { | 194 | { |
196 | struct GNUNET_FS_ProgressInfo pi; | 195 | struct GNUNET_FS_ProgressInfo pi; |
197 | 196 | ||
@@ -205,9 +204,9 @@ signal_probe_result (struct GNUNET_FS_SearchResult *sr) | |||
205 | = sr->availability_trials; | 204 | = sr->availability_trials; |
206 | pi.value.search.specifics.update.applicability_rank = sr->optional_support; | 205 | pi.value.search.specifics.update.applicability_rank = sr->optional_support; |
207 | pi.value.search.specifics.update.current_probe_time | 206 | pi.value.search.specifics.update.current_probe_time |
208 | = GNUNET_TIME_absolute_get_duration (sr->probe_active_time); | 207 | = GNUNET_TIME_absolute_get_duration(sr->probe_active_time); |
209 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sr->h, sr->sc); | 208 | sr->client_info = GNUNET_FS_search_make_status_(&pi, sr->h, sr->sc); |
210 | GNUNET_FS_search_start_probe_ (sr); | 209 | GNUNET_FS_search_start_probe_(sr); |
211 | } | 210 | } |
212 | 211 | ||
213 | 212 | ||
@@ -217,21 +216,21 @@ signal_probe_result (struct GNUNET_FS_SearchResult *sr) | |||
217 | * @param cls our `struct GNUNET_FS_SearchResult *` | 216 | * @param cls our `struct GNUNET_FS_SearchResult *` |
218 | */ | 217 | */ |
219 | static void | 218 | static void |
220 | probe_failure_handler (void *cls) | 219 | probe_failure_handler(void *cls) |
221 | { | 220 | { |
222 | struct GNUNET_FS_SearchResult *sr = cls; | 221 | struct GNUNET_FS_SearchResult *sr = cls; |
223 | 222 | ||
224 | sr->probe_cancel_task = NULL; | 223 | sr->probe_cancel_task = NULL; |
225 | sr->availability_trials++; | 224 | sr->availability_trials++; |
226 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); | 225 | GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); |
227 | sr->probe_ctx = NULL; | 226 | sr->probe_ctx = NULL; |
228 | GNUNET_FS_stop_probe_ping_task_ (sr); | 227 | GNUNET_FS_stop_probe_ping_task_(sr); |
229 | GNUNET_FS_search_result_sync_ (sr); | 228 | GNUNET_FS_search_result_sync_(sr); |
230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 229 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
231 | "Probe #%u for search result %p failed\n", | 230 | "Probe #%u for search result %p failed\n", |
232 | sr->availability_trials, | 231 | sr->availability_trials, |
233 | sr); | 232 | sr); |
234 | signal_probe_result (sr); | 233 | signal_probe_result(sr); |
235 | } | 234 | } |
236 | 235 | ||
237 | 236 | ||
@@ -241,22 +240,22 @@ probe_failure_handler (void *cls) | |||
241 | * @param cls our `struct GNUNET_FS_SearchResult *` | 240 | * @param cls our `struct GNUNET_FS_SearchResult *` |
242 | */ | 241 | */ |
243 | static void | 242 | static void |
244 | probe_success_handler (void *cls) | 243 | probe_success_handler(void *cls) |
245 | { | 244 | { |
246 | struct GNUNET_FS_SearchResult *sr = cls; | 245 | struct GNUNET_FS_SearchResult *sr = cls; |
247 | 246 | ||
248 | sr->probe_cancel_task = NULL; | 247 | sr->probe_cancel_task = NULL; |
249 | sr->availability_trials++; | 248 | sr->availability_trials++; |
250 | sr->availability_success++; | 249 | sr->availability_success++; |
251 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); | 250 | GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); |
252 | sr->probe_ctx = NULL; | 251 | sr->probe_ctx = NULL; |
253 | GNUNET_FS_stop_probe_ping_task_ (sr); | 252 | GNUNET_FS_stop_probe_ping_task_(sr); |
254 | GNUNET_FS_search_result_sync_ (sr); | 253 | GNUNET_FS_search_result_sync_(sr); |
255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 254 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
256 | "Probe #%u for search result %p succeeded\n", | 255 | "Probe #%u for search result %p succeeded\n", |
257 | sr->availability_trials, | 256 | sr->availability_trials, |
258 | sr); | 257 | sr); |
259 | signal_probe_result (sr); | 258 | signal_probe_result(sr); |
260 | } | 259 | } |
261 | 260 | ||
262 | 261 | ||
@@ -276,82 +275,91 @@ probe_success_handler (void *cls) | |||
276 | * field in the `struct GNUNET_FS_ProgressInfo`. | 275 | * field in the `struct GNUNET_FS_ProgressInfo`. |
277 | */ | 276 | */ |
278 | void * | 277 | void * |
279 | GNUNET_FS_search_probe_progress_ (void *cls, | 278 | GNUNET_FS_search_probe_progress_(void *cls, |
280 | const struct GNUNET_FS_ProgressInfo *info) | 279 | const struct GNUNET_FS_ProgressInfo *info) |
281 | { | 280 | { |
282 | struct GNUNET_FS_SearchResult *sr = info->value.download.cctx; | 281 | struct GNUNET_FS_SearchResult *sr = info->value.download.cctx; |
283 | struct GNUNET_TIME_Relative dur; | 282 | struct GNUNET_TIME_Relative dur; |
284 | 283 | ||
285 | switch (info->status) | 284 | switch (info->status) |
286 | { | ||
287 | case GNUNET_FS_STATUS_DOWNLOAD_START: | ||
288 | /* ignore */ | ||
289 | break; | ||
290 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: | ||
291 | /* probes should never be resumed */ | ||
292 | GNUNET_assert (0); | ||
293 | break; | ||
294 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: | ||
295 | /* probes should never be suspended */ | ||
296 | GNUNET_break (0); | ||
297 | break; | ||
298 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
299 | /* ignore */ | ||
300 | break; | ||
301 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | ||
302 | if (NULL != sr->probe_cancel_task) | ||
303 | { | ||
304 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | ||
305 | sr->probe_cancel_task = NULL; | ||
306 | } | ||
307 | sr->probe_cancel_task = | ||
308 | GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, | ||
309 | &probe_failure_handler, sr); | ||
310 | break; | ||
311 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | ||
312 | if (NULL != sr->probe_cancel_task) | ||
313 | { | ||
314 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | ||
315 | sr->probe_cancel_task = NULL; | ||
316 | } | ||
317 | sr->probe_cancel_task = | ||
318 | GNUNET_SCHEDULER_add_now (&probe_success_handler, sr); | ||
319 | break; | ||
320 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
321 | if (NULL != sr->probe_cancel_task) | ||
322 | { | ||
323 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | ||
324 | sr->probe_cancel_task = NULL; | ||
325 | } | ||
326 | sr = NULL; | ||
327 | break; | ||
328 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | ||
329 | if (NULL == sr->probe_cancel_task) | ||
330 | { | 285 | { |
331 | sr->probe_active_time = GNUNET_TIME_absolute_get (); | 286 | case GNUNET_FS_STATUS_DOWNLOAD_START: |
287 | /* ignore */ | ||
288 | break; | ||
289 | |||
290 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: | ||
291 | /* probes should never be resumed */ | ||
292 | GNUNET_assert(0); | ||
293 | break; | ||
294 | |||
295 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: | ||
296 | /* probes should never be suspended */ | ||
297 | GNUNET_break(0); | ||
298 | break; | ||
299 | |||
300 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
301 | /* ignore */ | ||
302 | break; | ||
303 | |||
304 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | ||
305 | if (NULL != sr->probe_cancel_task) | ||
306 | { | ||
307 | GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); | ||
308 | sr->probe_cancel_task = NULL; | ||
309 | } | ||
332 | sr->probe_cancel_task = | 310 | sr->probe_cancel_task = |
333 | GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, | 311 | GNUNET_SCHEDULER_add_delayed(sr->remaining_probe_time, |
334 | &probe_failure_handler, sr); | 312 | &probe_failure_handler, sr); |
335 | } | 313 | break; |
336 | break; | 314 | |
337 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | 315 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
338 | if (NULL != sr->probe_cancel_task) | 316 | if (NULL != sr->probe_cancel_task) |
339 | { | 317 | { |
340 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | 318 | GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); |
341 | sr->probe_cancel_task = NULL; | 319 | sr->probe_cancel_task = NULL; |
342 | } | 320 | } |
343 | dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time); | ||
344 | sr->remaining_probe_time = | ||
345 | GNUNET_TIME_relative_subtract (sr->remaining_probe_time, dur); | ||
346 | if (0 == sr->remaining_probe_time.rel_value_us) | ||
347 | sr->probe_cancel_task = | 321 | sr->probe_cancel_task = |
348 | GNUNET_SCHEDULER_add_now (&probe_failure_handler, sr); | 322 | GNUNET_SCHEDULER_add_now(&probe_success_handler, sr); |
349 | GNUNET_FS_search_result_sync_ (sr); | 323 | break; |
350 | break; | 324 | |
351 | default: | 325 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: |
352 | GNUNET_break (0); | 326 | if (NULL != sr->probe_cancel_task) |
353 | return NULL; | 327 | { |
354 | } | 328 | GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); |
329 | sr->probe_cancel_task = NULL; | ||
330 | } | ||
331 | sr = NULL; | ||
332 | break; | ||
333 | |||
334 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | ||
335 | if (NULL == sr->probe_cancel_task) | ||
336 | { | ||
337 | sr->probe_active_time = GNUNET_TIME_absolute_get(); | ||
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 | } | ||
355 | return sr; | 363 | return sr; |
356 | } | 364 | } |
357 | 365 | ||
@@ -362,18 +370,18 @@ GNUNET_FS_search_probe_progress_ (void *cls, | |||
362 | * @param cls the `struct GNUNET_FS_SearchResult` that we are probing for | 370 | * @param cls the `struct GNUNET_FS_SearchResult` that we are probing for |
363 | */ | 371 | */ |
364 | static void | 372 | static void |
365 | probe_ping_task_cb (void *cls) | 373 | probe_ping_task_cb(void *cls) |
366 | { | 374 | { |
367 | struct GNUNET_FS_Handle *h = cls; | 375 | struct GNUNET_FS_Handle *h = cls; |
368 | struct GNUNET_FS_SearchResult *sr; | 376 | struct GNUNET_FS_SearchResult *sr; |
369 | 377 | ||
370 | for (sr = h->probes_head; NULL != sr; sr = sr->next) | 378 | for (sr = h->probes_head; NULL != sr; sr = sr->next) |
371 | if (NULL != sr->probe_ctx->mq) | 379 | if (NULL != sr->probe_ctx->mq) |
372 | signal_probe_result (sr); | 380 | signal_probe_result(sr); |
373 | h->probe_ping_task | 381 | h->probe_ping_task |
374 | = GNUNET_SCHEDULER_add_delayed (GNUNET_FS_PROBE_UPDATE_FREQUENCY, | 382 | = GNUNET_SCHEDULER_add_delayed(GNUNET_FS_PROBE_UPDATE_FREQUENCY, |
375 | &probe_ping_task_cb, | 383 | &probe_ping_task_cb, |
376 | h); | 384 | h); |
377 | } | 385 | } |
378 | 386 | ||
379 | 387 | ||
@@ -383,17 +391,17 @@ probe_ping_task_cb (void *cls) | |||
383 | * @param sr result to start pinging for. | 391 | * @param sr result to start pinging for. |
384 | */ | 392 | */ |
385 | static void | 393 | static void |
386 | start_probe_ping_task (struct GNUNET_FS_SearchResult *sr) | 394 | start_probe_ping_task(struct GNUNET_FS_SearchResult *sr) |
387 | { | 395 | { |
388 | struct GNUNET_FS_Handle *h = sr->h; | 396 | struct GNUNET_FS_Handle *h = sr->h; |
389 | 397 | ||
390 | GNUNET_CONTAINER_DLL_insert (h->probes_head, | 398 | GNUNET_CONTAINER_DLL_insert(h->probes_head, |
391 | h->probes_tail, | 399 | h->probes_tail, |
392 | sr); | 400 | sr); |
393 | if (NULL == h->probe_ping_task) | 401 | if (NULL == h->probe_ping_task) |
394 | h->probe_ping_task | 402 | h->probe_ping_task |
395 | = GNUNET_SCHEDULER_add_now (&probe_ping_task_cb, | 403 | = GNUNET_SCHEDULER_add_now(&probe_ping_task_cb, |
396 | h); | 404 | h); |
397 | } | 405 | } |
398 | 406 | ||
399 | 407 | ||
@@ -403,18 +411,18 @@ start_probe_ping_task (struct GNUNET_FS_SearchResult *sr) | |||
403 | * @param sr result to start pinging for. | 411 | * @param sr result to start pinging for. |
404 | */ | 412 | */ |
405 | void | 413 | void |
406 | GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr) | 414 | GNUNET_FS_stop_probe_ping_task_(struct GNUNET_FS_SearchResult *sr) |
407 | { | 415 | { |
408 | struct GNUNET_FS_Handle *h = sr->h; | 416 | struct GNUNET_FS_Handle *h = sr->h; |
409 | 417 | ||
410 | GNUNET_CONTAINER_DLL_remove (h->probes_head, | 418 | GNUNET_CONTAINER_DLL_remove(h->probes_head, |
411 | h->probes_tail, | 419 | h->probes_tail, |
412 | sr); | 420 | sr); |
413 | if (NULL == h->probes_head) | 421 | if (NULL == h->probes_head) |
414 | { | 422 | { |
415 | GNUNET_SCHEDULER_cancel (h->probe_ping_task); | 423 | GNUNET_SCHEDULER_cancel(h->probe_ping_task); |
416 | h->probe_ping_task = NULL; | 424 | h->probe_ping_task = NULL; |
417 | } | 425 | } |
418 | } | 426 | } |
419 | 427 | ||
420 | 428 | ||
@@ -424,7 +432,7 @@ GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr) | |||
424 | * @param sr the search result | 432 | * @param sr the search result |
425 | */ | 433 | */ |
426 | void | 434 | void |
427 | GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) | 435 | GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr) |
428 | { | 436 | { |
429 | uint64_t off; | 437 | uint64_t off; |
430 | uint64_t len; | 438 | uint64_t len; |
@@ -437,35 +445,35 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) | |||
437 | return; | 445 | return; |
438 | if (sr->availability_trials > AVAILABILITY_TRIALS_MAX) | 446 | if (sr->availability_trials > AVAILABILITY_TRIALS_MAX) |
439 | return; | 447 | return; |
440 | if ( (GNUNET_FS_URI_CHK != sr->uri->type) && (GNUNET_FS_URI_LOC != sr->uri->type)) | 448 | if ((GNUNET_FS_URI_CHK != sr->uri->type) && (GNUNET_FS_URI_LOC != sr->uri->type)) |
441 | return; | 449 | return; |
442 | len = GNUNET_FS_uri_chk_get_file_size (sr->uri); | 450 | len = GNUNET_FS_uri_chk_get_file_size(sr->uri); |
443 | if (0 == len) | 451 | if (0 == len) |
444 | return; | 452 | return; |
445 | if ((len <= DBLOCK_SIZE) && (sr->availability_success > 0)) | 453 | if ((len <= DBLOCK_SIZE) && (sr->availability_success > 0)) |
446 | return; | 454 | return; |
447 | off = len / DBLOCK_SIZE; | 455 | off = len / DBLOCK_SIZE; |
448 | if (off > 0) | 456 | if (off > 0) |
449 | off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, off); | 457 | off = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, off); |
450 | off *= DBLOCK_SIZE; | 458 | off *= DBLOCK_SIZE; |
451 | if (len - off < DBLOCK_SIZE) | 459 | if (len - off < DBLOCK_SIZE) |
452 | len = len - off; | 460 | len = len - off; |
453 | else | 461 | else |
454 | len = DBLOCK_SIZE; | 462 | len = DBLOCK_SIZE; |
455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 463 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
456 | "Starting probe #%u (at offset %llu) for search result %p\n", | 464 | "Starting probe #%u (at offset %llu) for search result %p\n", |
457 | sr->availability_trials + 1, | 465 | sr->availability_trials + 1, |
458 | (unsigned long long) off, | 466 | (unsigned long long)off, |
459 | sr); | 467 | sr); |
460 | sr->remaining_probe_time = | 468 | sr->remaining_probe_time = |
461 | GNUNET_TIME_relative_saturating_multiply (sr->h->avg_block_latency, | 469 | GNUNET_TIME_relative_saturating_multiply(sr->h->avg_block_latency, |
462 | 2 * (1 + sr->availability_trials)); | 470 | 2 * (1 + sr->availability_trials)); |
463 | sr->probe_ctx = | 471 | sr->probe_ctx = |
464 | GNUNET_FS_download_start (sr->h, sr->uri, sr->meta, NULL, NULL, off, | 472 | GNUNET_FS_download_start(sr->h, sr->uri, sr->meta, NULL, NULL, off, |
465 | len, sr->anonymity, | 473 | len, sr->anonymity, |
466 | GNUNET_FS_DOWNLOAD_NO_TEMPORARIES | | 474 | GNUNET_FS_DOWNLOAD_NO_TEMPORARIES | |
467 | GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL); | 475 | GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL); |
468 | start_probe_ping_task (sr); | 476 | start_probe_ping_task(sr); |
469 | } | 477 | } |
470 | 478 | ||
471 | 479 | ||
@@ -480,23 +488,23 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) | |||
480 | * @return the search result handle to access the probe activity | 488 | * @return the search result handle to access the probe activity |
481 | */ | 489 | */ |
482 | struct GNUNET_FS_SearchResult * | 490 | struct GNUNET_FS_SearchResult * |
483 | GNUNET_FS_probe (struct GNUNET_FS_Handle *h, | 491 | GNUNET_FS_probe(struct GNUNET_FS_Handle *h, |
484 | const struct GNUNET_FS_Uri *uri, | 492 | const struct GNUNET_FS_Uri *uri, |
485 | const struct GNUNET_CONTAINER_MetaData *meta, | 493 | const struct GNUNET_CONTAINER_MetaData *meta, |
486 | void *client_info, | 494 | void *client_info, |
487 | uint32_t anonymity) | 495 | uint32_t anonymity) |
488 | { | 496 | { |
489 | struct GNUNET_FS_SearchResult *sr; | 497 | struct GNUNET_FS_SearchResult *sr; |
490 | 498 | ||
491 | GNUNET_assert (NULL != h); | 499 | GNUNET_assert(NULL != h); |
492 | GNUNET_assert (NULL != uri); | 500 | GNUNET_assert(NULL != uri); |
493 | sr = GNUNET_new (struct GNUNET_FS_SearchResult); | 501 | sr = GNUNET_new(struct GNUNET_FS_SearchResult); |
494 | sr->h = h; | 502 | sr->h = h; |
495 | sr->uri = GNUNET_FS_uri_dup (uri); | 503 | sr->uri = GNUNET_FS_uri_dup(uri); |
496 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 504 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); |
497 | sr->client_info = client_info; | 505 | sr->client_info = client_info; |
498 | sr->anonymity = anonymity; | 506 | sr->anonymity = anonymity; |
499 | GNUNET_FS_search_start_probe_ (sr); | 507 | GNUNET_FS_search_start_probe_(sr); |
500 | return sr; | 508 | return sr; |
501 | } | 509 | } |
502 | 510 | ||
@@ -507,19 +515,19 @@ GNUNET_FS_probe (struct GNUNET_FS_Handle *h, | |||
507 | * @param sr search result | 515 | * @param sr search result |
508 | */ | 516 | */ |
509 | static void | 517 | static void |
510 | GNUNET_FS_search_stop_probe_ (struct GNUNET_FS_SearchResult *sr) | 518 | GNUNET_FS_search_stop_probe_(struct GNUNET_FS_SearchResult *sr) |
511 | { | 519 | { |
512 | if (NULL != sr->probe_ctx) | 520 | if (NULL != sr->probe_ctx) |
513 | { | 521 | { |
514 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); | 522 | GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); |
515 | sr->probe_ctx = NULL; | 523 | sr->probe_ctx = NULL; |
516 | GNUNET_FS_stop_probe_ping_task_ (sr); | 524 | GNUNET_FS_stop_probe_ping_task_(sr); |
517 | } | 525 | } |
518 | if (NULL != sr->probe_cancel_task) | 526 | if (NULL != sr->probe_cancel_task) |
519 | { | 527 | { |
520 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | 528 | GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); |
521 | sr->probe_cancel_task = NULL; | 529 | sr->probe_cancel_task = NULL; |
522 | } | 530 | } |
523 | } | 531 | } |
524 | 532 | ||
525 | 533 | ||
@@ -531,16 +539,16 @@ GNUNET_FS_search_stop_probe_ (struct GNUNET_FS_SearchResult *sr) | |||
531 | * @return the value of the 'client_info' pointer | 539 | * @return the value of the 'client_info' pointer |
532 | */ | 540 | */ |
533 | void * | 541 | void * |
534 | GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr) | 542 | GNUNET_FS_probe_stop(struct GNUNET_FS_SearchResult *sr) |
535 | { | 543 | { |
536 | void *client_info; | 544 | void *client_info; |
537 | 545 | ||
538 | GNUNET_assert (NULL == sr->sc); | 546 | GNUNET_assert(NULL == sr->sc); |
539 | GNUNET_FS_search_stop_probe_ (sr); | 547 | GNUNET_FS_search_stop_probe_(sr); |
540 | GNUNET_FS_uri_destroy (sr->uri); | 548 | GNUNET_FS_uri_destroy(sr->uri); |
541 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); | 549 | GNUNET_CONTAINER_meta_data_destroy(sr->meta); |
542 | client_info = sr->client_info; | 550 | client_info = sr->client_info; |
543 | GNUNET_free (sr); | 551 | GNUNET_free(sr); |
544 | return client_info; | 552 | return client_info; |
545 | } | 553 | } |
546 | 554 | ||
@@ -556,10 +564,10 @@ GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr) | |||
556 | * under the @a ent keyword | 564 | * under the @a ent keyword |
557 | */ | 565 | */ |
558 | static void | 566 | static void |
559 | process_ksk_result (struct GNUNET_FS_SearchContext *sc, | 567 | process_ksk_result(struct GNUNET_FS_SearchContext *sc, |
560 | struct SearchRequestEntry *ent, | 568 | struct SearchRequestEntry *ent, |
561 | const struct GNUNET_FS_Uri *uri, | 569 | const struct GNUNET_FS_Uri *uri, |
562 | const struct GNUNET_CONTAINER_MetaData *meta) | 570 | const struct GNUNET_CONTAINER_MetaData *meta) |
563 | { | 571 | { |
564 | struct GNUNET_HashCode key; | 572 | struct GNUNET_HashCode key; |
565 | struct GNUNET_FS_SearchResult *sr; | 573 | struct GNUNET_FS_SearchResult *sr; |
@@ -568,80 +576,80 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc, | |||
568 | unsigned int koff; | 576 | unsigned int koff; |
569 | 577 | ||
570 | /* check if new */ | 578 | /* check if new */ |
571 | GNUNET_assert (NULL != sc); | 579 | GNUNET_assert(NULL != sc); |
572 | if (GNUNET_OK != | 580 | if (GNUNET_OK != |
573 | GNUNET_FS_uri_to_key (uri, | 581 | GNUNET_FS_uri_to_key(uri, |
574 | &key)) | 582 | &key)) |
575 | { | 583 | { |
576 | GNUNET_break_op (0); | 584 | GNUNET_break_op(0); |
577 | return; | 585 | return; |
578 | } | 586 | } |
579 | if (GNUNET_SYSERR == | 587 | if (GNUNET_SYSERR == |
580 | GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, | 588 | GNUNET_CONTAINER_multihashmap_get_multiple(ent->results, |
581 | &key, | 589 | &key, |
582 | &test_result_present, | 590 | &test_result_present, |
583 | (void *) uri)) | 591 | (void *)uri)) |
584 | return; /* duplicate result */ | 592 | return; /* duplicate result */ |
585 | /* try to find search result in master map */ | 593 | /* try to find search result in master map */ |
586 | grc.sr = NULL; | 594 | grc.sr = NULL; |
587 | grc.uri = uri; | 595 | grc.uri = uri; |
588 | GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, | 596 | GNUNET_CONTAINER_multihashmap_get_multiple(sc->master_result_map, |
589 | &key, | 597 | &key, |
590 | &get_result_present, &grc); | 598 | &get_result_present, &grc); |
591 | sr = grc.sr; | 599 | sr = grc.sr; |
592 | is_new = (NULL == sr) || (sr->mandatory_missing > 0); | 600 | is_new = (NULL == sr) || (sr->mandatory_missing > 0); |
593 | if (NULL == sr) | 601 | if (NULL == sr) |
594 | { | 602 | { |
595 | sr = GNUNET_new (struct GNUNET_FS_SearchResult); | 603 | sr = GNUNET_new(struct GNUNET_FS_SearchResult); |
596 | sr->h = sc->h; | 604 | sr->h = sc->h; |
597 | sr->sc = sc; | 605 | sr->sc = sc; |
598 | sr->anonymity = sc->anonymity; | 606 | sr->anonymity = sc->anonymity; |
599 | sr->uri = GNUNET_FS_uri_dup (uri); | 607 | sr->uri = GNUNET_FS_uri_dup(uri); |
600 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 608 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); |
601 | sr->mandatory_missing = sc->mandatory_count; | 609 | sr->mandatory_missing = sc->mandatory_count; |
602 | sr->key = key; | 610 | sr->key = key; |
603 | sr->keyword_bitmap = GNUNET_malloc ((sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ | 611 | sr->keyword_bitmap = GNUNET_malloc((sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ |
604 | GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr, | 612 | GNUNET_CONTAINER_multihashmap_put(sc->master_result_map, &key, sr, |
605 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 613 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
606 | } | 614 | } |
607 | else | 615 | else |
608 | { | 616 | { |
609 | GNUNET_CONTAINER_meta_data_merge (sr->meta, meta); | 617 | GNUNET_CONTAINER_meta_data_merge(sr->meta, meta); |
610 | } | 618 | } |
611 | GNUNET_break (GNUNET_OK == | 619 | GNUNET_break(GNUNET_OK == |
612 | GNUNET_CONTAINER_multihashmap_put (ent->results, | 620 | GNUNET_CONTAINER_multihashmap_put(ent->results, |
613 | &sr->key, | 621 | &sr->key, |
614 | sr, | 622 | sr, |
615 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 623 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
616 | 624 | ||
617 | koff = ent - sc->requests; | 625 | koff = ent - sc->requests; |
618 | GNUNET_assert ( (ent >= sc->requests) && | 626 | GNUNET_assert((ent >= sc->requests) && |
619 | (koff < sc->uri->data.ksk.keywordCount)); | 627 | (koff < sc->uri->data.ksk.keywordCount)); |
620 | sr->keyword_bitmap[koff / 8] |= (1 << (koff % 8)); | 628 | sr->keyword_bitmap[koff / 8] |= (1 << (koff % 8)); |
621 | /* check if mandatory satisfied */ | 629 | /* check if mandatory satisfied */ |
622 | if (1 <= GNUNET_CONTAINER_multihashmap_size (ent->results)) | 630 | if (1 <= GNUNET_CONTAINER_multihashmap_size(ent->results)) |
623 | { | ||
624 | if (ent->mandatory) | ||
625 | { | 631 | { |
626 | GNUNET_break (sr->mandatory_missing > 0); | 632 | if (ent->mandatory) |
627 | sr->mandatory_missing--; | 633 | { |
634 | GNUNET_break(sr->mandatory_missing > 0); | ||
635 | sr->mandatory_missing--; | ||
636 | } | ||
637 | else | ||
638 | { | ||
639 | sr->optional_support++; | ||
640 | } | ||
628 | } | 641 | } |
629 | else | 642 | if (0 != sr->mandatory_missing) |
630 | { | 643 | { |
631 | sr->optional_support++; | 644 | GNUNET_break(NULL == sr->client_info); |
645 | return; | ||
632 | } | 646 | } |
633 | } | ||
634 | if (0 != sr->mandatory_missing) | ||
635 | { | ||
636 | GNUNET_break (NULL == sr->client_info); | ||
637 | return; | ||
638 | } | ||
639 | if (is_new) | 647 | if (is_new) |
640 | notify_client_chk_result (sc, sr); | 648 | notify_client_chk_result(sc, sr); |
641 | else | 649 | else |
642 | notify_client_chk_update (sc, sr); | 650 | notify_client_chk_update(sc, sr); |
643 | GNUNET_FS_search_result_sync_ (sr); | 651 | GNUNET_FS_search_result_sync_(sr); |
644 | GNUNET_FS_search_start_probe_ (sr); | 652 | GNUNET_FS_search_start_probe_(sr); |
645 | } | 653 | } |
646 | 654 | ||
647 | 655 | ||
@@ -658,12 +666,12 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc, | |||
658 | * @return context that can be used to control the search | 666 | * @return context that can be used to control the search |
659 | */ | 667 | */ |
660 | static struct GNUNET_FS_SearchContext * | 668 | static struct GNUNET_FS_SearchContext * |
661 | search_start (struct GNUNET_FS_Handle *h, | 669 | search_start(struct GNUNET_FS_Handle *h, |
662 | const struct GNUNET_FS_Uri *uri, | 670 | const struct GNUNET_FS_Uri *uri, |
663 | uint32_t anonymity, | 671 | uint32_t anonymity, |
664 | enum GNUNET_FS_SearchOptions options, | 672 | enum GNUNET_FS_SearchOptions options, |
665 | void *cctx, | 673 | void *cctx, |
666 | struct GNUNET_FS_SearchResult *psearch); | 674 | struct GNUNET_FS_SearchResult *psearch); |
667 | 675 | ||
668 | 676 | ||
669 | /** | 677 | /** |
@@ -674,58 +682,58 @@ search_start (struct GNUNET_FS_Handle *h, | |||
674 | * @param id_update identifier for updates, NULL for none | 682 | * @param id_update identifier for updates, NULL for none |
675 | * @param uri the URI that was found | 683 | * @param uri the URI that was found |
676 | * @param meta metadata associated with the URI | 684 | * @param meta metadata associated with the URI |
677 | */ | 685 | */ |
678 | static void | 686 | static void |
679 | process_sks_result (struct GNUNET_FS_SearchContext *sc, | 687 | process_sks_result(struct GNUNET_FS_SearchContext *sc, |
680 | const char *id_update, | 688 | const char *id_update, |
681 | const struct GNUNET_FS_Uri *uri, | 689 | const struct GNUNET_FS_Uri *uri, |
682 | const struct GNUNET_CONTAINER_MetaData *meta) | 690 | const struct GNUNET_CONTAINER_MetaData *meta) |
683 | { | 691 | { |
684 | struct GNUNET_FS_Uri uu; | 692 | struct GNUNET_FS_Uri uu; |
685 | struct GNUNET_HashCode key; | 693 | struct GNUNET_HashCode key; |
686 | struct GNUNET_FS_SearchResult *sr; | 694 | struct GNUNET_FS_SearchResult *sr; |
687 | 695 | ||
688 | /* check if new */ | 696 | /* check if new */ |
689 | GNUNET_assert (NULL != sc); | 697 | GNUNET_assert(NULL != sc); |
690 | if (GNUNET_OK != | 698 | if (GNUNET_OK != |
691 | GNUNET_FS_uri_to_key (uri, | 699 | GNUNET_FS_uri_to_key(uri, |
692 | &key)) | 700 | &key)) |
693 | { | 701 | { |
694 | GNUNET_break (0); | 702 | GNUNET_break(0); |
695 | return; | 703 | return; |
696 | } | 704 | } |
697 | GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, | 705 | GNUNET_CRYPTO_hash_xor(&uri->data.chk.chk.key, |
698 | &uri->data.chk.chk.query, | 706 | &uri->data.chk.chk.query, |
699 | &key); | 707 | &key); |
700 | if (GNUNET_SYSERR == | 708 | if (GNUNET_SYSERR == |
701 | GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key, | 709 | GNUNET_CONTAINER_multihashmap_get_multiple(sc->master_result_map, &key, |
702 | &test_result_present, | 710 | &test_result_present, |
703 | (void *) uri)) | 711 | (void *)uri)) |
704 | return; /* duplicate result */ | 712 | return; /* duplicate result */ |
705 | sr = GNUNET_new (struct GNUNET_FS_SearchResult); | 713 | sr = GNUNET_new(struct GNUNET_FS_SearchResult); |
706 | sr->h = sc->h; | 714 | sr->h = sc->h; |
707 | sr->sc = sc; | 715 | sr->sc = sc; |
708 | sr->anonymity = sc->anonymity; | 716 | sr->anonymity = sc->anonymity; |
709 | sr->uri = GNUNET_FS_uri_dup (uri); | 717 | sr->uri = GNUNET_FS_uri_dup(uri); |
710 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 718 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); |
711 | sr->key = key; | 719 | sr->key = key; |
712 | GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr, | 720 | GNUNET_CONTAINER_multihashmap_put(sc->master_result_map, &key, sr, |
713 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 721 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
714 | GNUNET_FS_search_result_sync_ (sr); | 722 | GNUNET_FS_search_result_sync_(sr); |
715 | GNUNET_FS_search_start_probe_ (sr); | 723 | GNUNET_FS_search_start_probe_(sr); |
716 | /* notify client */ | 724 | /* notify client */ |
717 | if (0 == sr->mandatory_missing) | 725 | if (0 == sr->mandatory_missing) |
718 | notify_client_chk_result (sc, sr); | 726 | notify_client_chk_result(sc, sr); |
719 | else | 727 | else |
720 | GNUNET_break (NULL == sr->client_info); | 728 | GNUNET_break(NULL == sr->client_info); |
721 | /* search for updates */ | 729 | /* search for updates */ |
722 | if (0 == strlen (id_update)) | 730 | if (0 == strlen(id_update)) |
723 | return; /* no updates */ | 731 | return; /* no updates */ |
724 | uu.type = GNUNET_FS_URI_SKS; | 732 | uu.type = GNUNET_FS_URI_SKS; |
725 | uu.data.sks.ns = sc->uri->data.sks.ns; | 733 | uu.data.sks.ns = sc->uri->data.sks.ns; |
726 | uu.data.sks.identifier = GNUNET_strdup (id_update); | 734 | uu.data.sks.identifier = GNUNET_strdup(id_update); |
727 | (void) search_start (sc->h, &uu, sc->anonymity, sc->options, NULL, sr); | 735 | (void)search_start(sc->h, &uu, sc->anonymity, sc->options, NULL, sr); |
728 | GNUNET_free (uu.data.sks.identifier); | 736 | GNUNET_free(uu.data.sks.identifier); |
729 | } | 737 | } |
730 | 738 | ||
731 | 739 | ||
@@ -744,11 +752,11 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc, | |||
744 | * keyword, internal error) | 752 | * keyword, internal error) |
745 | */ | 753 | */ |
746 | static int | 754 | static int |
747 | decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc, | 755 | decrypt_block_with_keyword(const struct GNUNET_FS_SearchContext *sc, |
748 | const struct GNUNET_CRYPTO_EcdsaPublicKey *dpub, | 756 | const struct GNUNET_CRYPTO_EcdsaPublicKey *dpub, |
749 | const void *edata, | 757 | const void *edata, |
750 | size_t edata_size, | 758 | size_t edata_size, |
751 | char *data) | 759 | char *data) |
752 | { | 760 | { |
753 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; | 761 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; |
754 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; | 762 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; |
@@ -756,23 +764,23 @@ decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc, | |||
756 | 764 | ||
757 | /* find key */ | 765 | /* find key */ |
758 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | 766 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
759 | if (0 == memcmp (dpub, | 767 | if (0 == memcmp(dpub, |
760 | &sc->requests[i].dpub, | 768 | &sc->requests[i].dpub, |
761 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 769 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) |
762 | break; | 770 | break; |
763 | if (i == sc->uri->data.ksk.keywordCount) | 771 | if (i == sc->uri->data.ksk.keywordCount) |
764 | { | 772 | { |
765 | /* oops, does not match any of our keywords!? */ | 773 | /* oops, does not match any of our keywords!? */ |
766 | GNUNET_break (0); | 774 | GNUNET_break(0); |
767 | return GNUNET_SYSERR; | 775 | return GNUNET_SYSERR; |
768 | } | 776 | } |
769 | /* decrypt */ | 777 | /* decrypt */ |
770 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); | 778 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous(); |
771 | GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub); | 779 | GNUNET_CRYPTO_ecdsa_key_get_public(anon, &anon_pub); |
772 | GNUNET_FS_ublock_decrypt_ (edata, edata_size, | 780 | GNUNET_FS_ublock_decrypt_(edata, edata_size, |
773 | &anon_pub, | 781 | &anon_pub, |
774 | sc->requests[i].keyword, | 782 | sc->requests[i].keyword, |
775 | data); | 783 | data); |
776 | return i; | 784 | return i; |
777 | } | 785 | } |
778 | 786 | ||
@@ -787,65 +795,65 @@ decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc, | |||
787 | * @param size size of @a ub | 795 | * @param size size of @a ub |
788 | */ | 796 | */ |
789 | static void | 797 | static void |
790 | process_kblock (struct GNUNET_FS_SearchContext *sc, | 798 | process_kblock(struct GNUNET_FS_SearchContext *sc, |
791 | const struct UBlock *ub, | 799 | const struct UBlock *ub, |
792 | size_t size) | 800 | size_t size) |
793 | { | 801 | { |
794 | size_t j; | 802 | size_t j; |
795 | char pt[size - sizeof (struct UBlock)]; | 803 | char pt[size - sizeof(struct UBlock)]; |
796 | const char *eos; | 804 | const char *eos; |
797 | struct GNUNET_CONTAINER_MetaData *meta; | 805 | struct GNUNET_CONTAINER_MetaData *meta; |
798 | struct GNUNET_FS_Uri *uri; | 806 | struct GNUNET_FS_Uri *uri; |
799 | char *emsg; | 807 | char *emsg; |
800 | int i; | 808 | int i; |
801 | 809 | ||
802 | if (-1 == (i = decrypt_block_with_keyword (sc, | 810 | if (-1 == (i = decrypt_block_with_keyword(sc, |
803 | &ub->verification_key, | 811 | &ub->verification_key, |
804 | &ub[1], | 812 | &ub[1], |
805 | size - sizeof (struct UBlock), | 813 | size - sizeof(struct UBlock), |
806 | pt))) | 814 | pt))) |
807 | return; | 815 | return; |
808 | /* parse; pt[0] is just '\0', so we skip over that */ | 816 | /* parse; pt[0] is just '\0', so we skip over that */ |
809 | eos = memchr (&pt[1], '\0', sizeof (pt) - 1); | 817 | eos = memchr(&pt[1], '\0', sizeof(pt) - 1); |
810 | if (NULL == eos) | 818 | if (NULL == eos) |
811 | { | ||
812 | GNUNET_break_op (0); | ||
813 | return; | ||
814 | } | ||
815 | if (NULL == (uri = GNUNET_FS_uri_parse (&pt[1], &emsg))) | ||
816 | { | ||
817 | if (GNUNET_FS_VERSION > 0x00090400) | ||
818 | { | 819 | { |
819 | /* we broke this in 0x00090300, so don't bitch | 820 | GNUNET_break_op(0); |
820 | too loudly just one version up... */ | 821 | return; |
821 | GNUNET_break_op (0); /* ublock malformed */ | 822 | } |
822 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 823 | if (NULL == (uri = GNUNET_FS_uri_parse(&pt[1], &emsg))) |
823 | _("Failed to parse URI `%s': %s\n"), | 824 | { |
824 | &pt[1], | 825 | if (GNUNET_FS_VERSION > 0x00090400) |
825 | emsg); | 826 | { |
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; | ||
826 | } | 837 | } |
827 | GNUNET_free_non_null (emsg); | ||
828 | return; | ||
829 | } | ||
830 | j = eos - pt + 1; | 838 | j = eos - pt + 1; |
831 | if (sizeof (pt) == j) | 839 | if (sizeof(pt) == j) |
832 | meta = GNUNET_CONTAINER_meta_data_create (); | 840 | meta = GNUNET_CONTAINER_meta_data_create(); |
833 | else | 841 | else |
834 | meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j); | 842 | meta = GNUNET_CONTAINER_meta_data_deserialize(&pt[j], sizeof(pt) - j); |
835 | if (NULL == meta) | 843 | if (NULL == meta) |
836 | { | 844 | { |
837 | GNUNET_break_op (0); /* ublock malformed */ | 845 | GNUNET_break_op(0); /* ublock malformed */ |
838 | GNUNET_FS_uri_destroy (uri); | 846 | GNUNET_FS_uri_destroy(uri); |
839 | return; | 847 | return; |
840 | } | 848 | } |
841 | process_ksk_result (sc, | 849 | process_ksk_result(sc, |
842 | &sc->requests[i], | 850 | &sc->requests[i], |
843 | uri, | 851 | uri, |
844 | meta); | 852 | meta); |
845 | 853 | ||
846 | /* clean up */ | 854 | /* clean up */ |
847 | GNUNET_CONTAINER_meta_data_destroy (meta); | 855 | GNUNET_CONTAINER_meta_data_destroy(meta); |
848 | GNUNET_FS_uri_destroy (uri); | 856 | GNUNET_FS_uri_destroy(uri); |
849 | } | 857 | } |
850 | 858 | ||
851 | 859 | ||
@@ -859,11 +867,11 @@ process_kblock (struct GNUNET_FS_SearchContext *sc, | |||
859 | * @param size size of @a ub | 867 | * @param size size of @a ub |
860 | */ | 868 | */ |
861 | static void | 869 | static void |
862 | process_sblock (struct GNUNET_FS_SearchContext *sc, | 870 | process_sblock(struct GNUNET_FS_SearchContext *sc, |
863 | const struct UBlock *ub, | 871 | const struct UBlock *ub, |
864 | size_t size) | 872 | size_t size) |
865 | { | 873 | { |
866 | size_t len = size - sizeof (struct UBlock); | 874 | size_t len = size - sizeof(struct UBlock); |
867 | char pt[len]; | 875 | char pt[len]; |
868 | struct GNUNET_FS_Uri *uri; | 876 | struct GNUNET_FS_Uri *uri; |
869 | struct GNUNET_CONTAINER_MetaData *meta; | 877 | struct GNUNET_CONTAINER_MetaData *meta; |
@@ -872,36 +880,36 @@ process_sblock (struct GNUNET_FS_SearchContext *sc, | |||
872 | size_t off; | 880 | size_t off; |
873 | char *emsg; | 881 | char *emsg; |
874 | 882 | ||
875 | GNUNET_FS_ublock_decrypt_ (&ub[1], len, | 883 | GNUNET_FS_ublock_decrypt_(&ub[1], len, |
876 | &sc->uri->data.sks.ns, | 884 | &sc->uri->data.sks.ns, |
877 | sc->uri->data.sks.identifier, | 885 | sc->uri->data.sks.identifier, |
878 | pt); | 886 | pt); |
879 | /* parse */ | 887 | /* parse */ |
880 | if (0 == (off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris))) | 888 | if (0 == (off = GNUNET_STRINGS_buffer_tokenize(pt, len, 2, &id, &uris))) |
881 | { | 889 | { |
882 | GNUNET_break_op (0); /* ublock malformed */ | 890 | GNUNET_break_op(0); /* ublock malformed */ |
883 | return; | 891 | return; |
884 | } | 892 | } |
885 | if (NULL == (meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off], len - off))) | 893 | if (NULL == (meta = GNUNET_CONTAINER_meta_data_deserialize(&pt[off], len - off))) |
886 | { | 894 | { |
887 | GNUNET_break_op (0); /* ublock malformed */ | 895 | GNUNET_break_op(0); /* ublock malformed */ |
888 | return; | 896 | return; |
889 | } | 897 | } |
890 | if (NULL == (uri = GNUNET_FS_uri_parse (uris, &emsg))) | 898 | if (NULL == (uri = GNUNET_FS_uri_parse(uris, &emsg))) |
891 | { | 899 | { |
892 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 900 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
893 | _("Failed to parse URI `%s': %s\n"), | 901 | _("Failed to parse URI `%s': %s\n"), |
894 | uris, emsg); | 902 | uris, emsg); |
895 | GNUNET_break_op (0); /* ublock malformed */ | 903 | GNUNET_break_op(0); /* ublock malformed */ |
896 | GNUNET_free_non_null (emsg); | 904 | GNUNET_free_non_null(emsg); |
897 | GNUNET_CONTAINER_meta_data_destroy (meta); | 905 | GNUNET_CONTAINER_meta_data_destroy(meta); |
898 | return; | 906 | return; |
899 | } | 907 | } |
900 | /* process */ | 908 | /* process */ |
901 | process_sks_result (sc, id, uri, meta); | 909 | process_sks_result(sc, id, uri, meta); |
902 | /* clean up */ | 910 | /* clean up */ |
903 | GNUNET_FS_uri_destroy (uri); | 911 | GNUNET_FS_uri_destroy(uri); |
904 | GNUNET_CONTAINER_meta_data_destroy (meta); | 912 | GNUNET_CONTAINER_meta_data_destroy(meta); |
905 | } | 913 | } |
906 | 914 | ||
907 | 915 | ||
@@ -913,7 +921,7 @@ process_sblock (struct GNUNET_FS_SearchContext *sc, | |||
913 | * @param sc the search to reconnec | 921 | * @param sc the search to reconnec |
914 | */ | 922 | */ |
915 | static void | 923 | static void |
916 | try_reconnect (struct GNUNET_FS_SearchContext *sc); | 924 | try_reconnect(struct GNUNET_FS_SearchContext *sc); |
917 | 925 | ||
918 | 926 | ||
919 | /** | 927 | /** |
@@ -923,8 +931,8 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc); | |||
923 | * @param msg result message received | 931 | * @param msg result message received |
924 | */ | 932 | */ |
925 | static int | 933 | static int |
926 | check_result (void *cls, | 934 | check_result(void *cls, |
927 | const struct ClientPutMessage *cm) | 935 | const struct ClientPutMessage *cm) |
928 | { | 936 | { |
929 | /* payload of any variable size is OK */ | 937 | /* payload of any variable size is OK */ |
930 | return GNUNET_OK; | 938 | return GNUNET_OK; |
@@ -938,49 +946,54 @@ check_result (void *cls, | |||
938 | * @param msg result message received | 946 | * @param msg result message received |
939 | */ | 947 | */ |
940 | static void | 948 | static void |
941 | handle_result (void *cls, | 949 | handle_result(void *cls, |
942 | const struct ClientPutMessage *cm) | 950 | const struct ClientPutMessage *cm) |
943 | { | 951 | { |
944 | struct GNUNET_FS_SearchContext *sc = cls; | 952 | struct GNUNET_FS_SearchContext *sc = cls; |
945 | uint16_t msize = ntohs (cm->header.size) - sizeof (*cm); | 953 | uint16_t msize = ntohs(cm->header.size) - sizeof(*cm); |
946 | enum GNUNET_BLOCK_Type type = ntohl (cm->type); | 954 | enum GNUNET_BLOCK_Type type = ntohl(cm->type); |
947 | 955 | ||
948 | if (GNUNET_TIME_absolute_get_duration (GNUNET_TIME_absolute_ntoh (cm->expiration)).rel_value_us > 0) | 956 | if (GNUNET_TIME_absolute_get_duration(GNUNET_TIME_absolute_ntoh(cm->expiration)).rel_value_us > 0) |
949 | { | 957 | { |
950 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 958 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
951 | "Result received has already expired.\n"); | 959 | "Result received has already expired.\n"); |
952 | return; /* result expired */ | 960 | return; /* result expired */ |
953 | } | 961 | } |
954 | switch (type) | 962 | switch (type) |
955 | { | 963 | { |
956 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | 964 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
957 | if (GNUNET_FS_URI_SKS == sc->uri->type) | 965 | if (GNUNET_FS_URI_SKS == sc->uri->type) |
958 | process_sblock (sc, | 966 | process_sblock(sc, |
959 | (const struct UBlock *) &cm[1], | 967 | (const struct UBlock *)&cm[1], |
960 | msize); | 968 | msize); |
961 | else | 969 | else |
962 | process_kblock (sc, | 970 | process_kblock(sc, |
963 | (const struct UBlock *) &cm[1], | 971 | (const struct UBlock *)&cm[1], |
964 | msize); | 972 | msize); |
965 | break; | 973 | break; |
966 | case GNUNET_BLOCK_TYPE_ANY: | 974 | |
967 | GNUNET_break (0); | 975 | case GNUNET_BLOCK_TYPE_ANY: |
968 | break; | 976 | GNUNET_break(0); |
969 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | 977 | break; |
970 | GNUNET_break (0); | 978 | |
971 | break; | 979 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
972 | case GNUNET_BLOCK_TYPE_FS_ONDEMAND: | 980 | GNUNET_break(0); |
973 | GNUNET_break (0); | 981 | break; |
974 | break; | 982 | |
975 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | 983 | case GNUNET_BLOCK_TYPE_FS_ONDEMAND: |
976 | GNUNET_break (0); | 984 | GNUNET_break(0); |
977 | break; | 985 | break; |
978 | default: | 986 | |
979 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 987 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: |
980 | _("Got result with unknown block type `%d', ignoring"), | 988 | GNUNET_break(0); |
981 | type); | 989 | break; |
982 | break; | 990 | |
983 | } | 991 | default: |
992 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
993 | _("Got result with unknown block type `%d', ignoring"), | ||
994 | type); | ||
995 | break; | ||
996 | } | ||
984 | } | 997 | } |
985 | 998 | ||
986 | 999 | ||
@@ -991,14 +1004,13 @@ handle_result (void *cls, | |||
991 | * @param sc context for the search | 1004 | * @param sc context for the search |
992 | */ | 1005 | */ |
993 | static void | 1006 | static void |
994 | schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc); | 1007 | schedule_transmit_search_request(struct GNUNET_FS_SearchContext *sc); |
995 | 1008 | ||
996 | 1009 | ||
997 | /** | 1010 | /** |
998 | * Closure for #build_result_set(). | 1011 | * Closure for #build_result_set(). |
999 | */ | 1012 | */ |
1000 | struct MessageBuilderContext | 1013 | struct MessageBuilderContext { |
1001 | { | ||
1002 | /** | 1014 | /** |
1003 | * How many entries can we store to xoff. | 1015 | * How many entries can we store to xoff. |
1004 | */ | 1016 | */ |
@@ -1036,21 +1048,21 @@ struct MessageBuilderContext | |||
1036 | * @return #GNUNET_OK to continue iterating | 1048 | * @return #GNUNET_OK to continue iterating |
1037 | */ | 1049 | */ |
1038 | static int | 1050 | static int |
1039 | build_result_set (void *cls, | 1051 | build_result_set(void *cls, |
1040 | const struct GNUNET_HashCode *key, | 1052 | const struct GNUNET_HashCode *key, |
1041 | void *value) | 1053 | void *value) |
1042 | { | 1054 | { |
1043 | struct MessageBuilderContext *mbc = cls; | 1055 | struct MessageBuilderContext *mbc = cls; |
1044 | struct GNUNET_FS_SearchResult *sr = value; | 1056 | struct GNUNET_FS_SearchResult *sr = value; |
1045 | 1057 | ||
1046 | if ( (NULL != sr->keyword_bitmap) && | 1058 | if ((NULL != sr->keyword_bitmap) && |
1047 | (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 << (mbc->keyword_offset % 8)))) ) | 1059 | (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 << (mbc->keyword_offset % 8))))) |
1048 | return GNUNET_OK; /* have no match for this keyword yet */ | 1060 | return GNUNET_OK; /* have no match for this keyword yet */ |
1049 | if (mbc->skip_cnt > 0) | 1061 | if (mbc->skip_cnt > 0) |
1050 | { | 1062 | { |
1051 | mbc->skip_cnt--; | 1063 | mbc->skip_cnt--; |
1052 | return GNUNET_OK; | 1064 | return GNUNET_OK; |
1053 | } | 1065 | } |
1054 | if (0 == mbc->put_cnt) | 1066 | if (0 == mbc->put_cnt) |
1055 | return GNUNET_SYSERR; | 1067 | return GNUNET_SYSERR; |
1056 | mbc->xoff[--mbc->put_cnt] = *key; | 1068 | mbc->xoff[--mbc->put_cnt] = *key; |
@@ -1069,15 +1081,15 @@ build_result_set (void *cls, | |||
1069 | * @return #GNUNET_OK to continue iterating | 1081 | * @return #GNUNET_OK to continue iterating |
1070 | */ | 1082 | */ |
1071 | static int | 1083 | static int |
1072 | find_result_set (void *cls, | 1084 | find_result_set(void *cls, |
1073 | const struct GNUNET_HashCode *key, | 1085 | const struct GNUNET_HashCode *key, |
1074 | void *value) | 1086 | void *value) |
1075 | { | 1087 | { |
1076 | struct MessageBuilderContext *mbc = cls; | 1088 | struct MessageBuilderContext *mbc = cls; |
1077 | struct GNUNET_FS_SearchResult *sr = value; | 1089 | struct GNUNET_FS_SearchResult *sr = value; |
1078 | 1090 | ||
1079 | if ( (NULL != sr->keyword_bitmap) && | 1091 | if ((NULL != sr->keyword_bitmap) && |
1080 | (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 << (mbc->keyword_offset % 8)))) ) | 1092 | (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 << (mbc->keyword_offset % 8))))) |
1081 | return GNUNET_OK; /* have no match for this keyword yet */ | 1093 | return GNUNET_OK; /* have no match for this keyword yet */ |
1082 | mbc->put_cnt++; | 1094 | mbc->put_cnt++; |
1083 | return GNUNET_OK; | 1095 | return GNUNET_OK; |
@@ -1091,7 +1103,7 @@ find_result_set (void *cls, | |||
1091 | * @param sc context for the search | 1103 | * @param sc context for the search |
1092 | */ | 1104 | */ |
1093 | static void | 1105 | static void |
1094 | schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) | 1106 | schedule_transmit_search_request(struct GNUNET_FS_SearchContext *sc) |
1095 | { | 1107 | { |
1096 | struct MessageBuilderContext mbc; | 1108 | struct MessageBuilderContext mbc; |
1097 | struct GNUNET_MQ_Envelope *env; | 1109 | struct GNUNET_MQ_Envelope *env; |
@@ -1106,115 +1118,115 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) | |||
1106 | unsigned int keyword_offset; | 1118 | unsigned int keyword_offset; |
1107 | int first_call; | 1119 | int first_call; |
1108 | 1120 | ||
1109 | memset (&mbc, 0, sizeof (mbc)); | 1121 | memset(&mbc, 0, sizeof(mbc)); |
1110 | mbc.sc = sc; | 1122 | mbc.sc = sc; |
1111 | if (GNUNET_FS_uri_test_ksk (sc->uri)) | 1123 | if (GNUNET_FS_uri_test_ksk(sc->uri)) |
1112 | { | 1124 | { |
1113 | /* This will calculate the result set size ONLY for | 1125 | /* This will calculate the result set size ONLY for |
1114 | "keyword_offset == 0", so we will have to recalculate | 1126 | "keyword_offset == 0", so we will have to recalculate |
1115 | it for the other keywords later! */ | 1127 | it for the other keywords later! */ |
1116 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1128 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, |
1117 | &find_result_set, | 1129 | &find_result_set, |
1118 | &mbc); | 1130 | &mbc); |
1119 | total_seen_results = mbc.put_cnt; | 1131 | total_seen_results = mbc.put_cnt; |
1120 | } | 1132 | } |
1121 | else | 1133 | else |
1122 | { | 1134 | { |
1123 | total_seen_results | 1135 | total_seen_results |
1124 | = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map); | 1136 | = GNUNET_CONTAINER_multihashmap_size(sc->master_result_map); |
1125 | } | 1137 | } |
1126 | search_request_map_offset = 0; | 1138 | search_request_map_offset = 0; |
1127 | keyword_offset = 0; | 1139 | keyword_offset = 0; |
1128 | first_call = GNUNET_YES; | 1140 | first_call = GNUNET_YES; |
1129 | while ( (0 != (left = | 1141 | while ((0 != (left = |
1130 | (total_seen_results - search_request_map_offset))) || | 1142 | (total_seen_results - search_request_map_offset))) || |
1131 | (GNUNET_YES == first_call) ) | 1143 | (GNUNET_YES == first_call)) |
1132 | { | ||
1133 | first_call = GNUNET_NO; | ||
1134 | options = SEARCH_MESSAGE_OPTION_NONE; | ||
1135 | if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) | ||
1136 | options |= SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY; | ||
1137 | |||
1138 | fit = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof (*sm)) / sizeof (struct GNUNET_HashCode); | ||
1139 | todo = GNUNET_MIN (fit, | ||
1140 | left); | ||
1141 | env = GNUNET_MQ_msg_extra (sm, | ||
1142 | sizeof (struct GNUNET_HashCode) * todo, | ||
1143 | GNUNET_MESSAGE_TYPE_FS_START_SEARCH); | ||
1144 | mbc.skip_cnt = search_request_map_offset; | ||
1145 | mbc.xoff = (struct GNUNET_HashCode *) &sm[1]; | ||
1146 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK); | ||
1147 | sm->anonymity_level = htonl (sc->anonymity); | ||
1148 | memset (&sm->target, | ||
1149 | 0, | ||
1150 | sizeof (struct GNUNET_PeerIdentity)); | ||
1151 | |||
1152 | if (GNUNET_FS_uri_test_ksk (sc->uri)) | ||
1153 | { | 1144 | { |
1154 | mbc.keyword_offset = keyword_offset; | 1145 | first_call = GNUNET_NO; |
1155 | /* calculate how many results we can send in this message */ | 1146 | options = SEARCH_MESSAGE_OPTION_NONE; |
1156 | mbc.put_cnt = todo; | 1147 | if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) |
1157 | /* now build message */ | 1148 | options |= SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY; |
1158 | sm->query = sc->requests[keyword_offset].uquery; | 1149 | |
1159 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1150 | fit = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*sm)) / sizeof(struct GNUNET_HashCode); |
1160 | &build_result_set, | 1151 | todo = GNUNET_MIN(fit, |
1161 | &mbc); | 1152 | left); |
1162 | search_request_map_offset += todo; | 1153 | env = GNUNET_MQ_msg_extra(sm, |
1163 | GNUNET_assert (0 == mbc.put_cnt); | 1154 | sizeof(struct GNUNET_HashCode) * todo, |
1164 | GNUNET_assert (total_seen_results >= search_request_map_offset); | 1155 | GNUNET_MESSAGE_TYPE_FS_START_SEARCH); |
1165 | if (total_seen_results != search_request_map_offset) | 1156 | mbc.skip_cnt = search_request_map_offset; |
1166 | { | 1157 | mbc.xoff = (struct GNUNET_HashCode *)&sm[1]; |
1167 | /* more requesting to be done... */ | 1158 | sm->type = htonl(GNUNET_BLOCK_TYPE_FS_UBLOCK); |
1168 | sm->options = htonl (options | SEARCH_MESSAGE_OPTION_CONTINUED); | 1159 | sm->anonymity_level = htonl(sc->anonymity); |
1169 | } | 1160 | memset(&sm->target, |
1170 | else | 1161 | 0, |
1171 | { | 1162 | sizeof(struct GNUNET_PeerIdentity)); |
1172 | sm->options = htonl (options); | 1163 | |
1173 | keyword_offset++; | 1164 | if (GNUNET_FS_uri_test_ksk(sc->uri)) |
1174 | if (sc->uri->data.ksk.keywordCount != keyword_offset) | ||
1175 | { | 1165 | { |
1176 | /* more keywords => more requesting to be done... */ | ||
1177 | first_call = GNUNET_YES; | ||
1178 | search_request_map_offset = 0; | ||
1179 | mbc.put_cnt = 0; | ||
1180 | mbc.keyword_offset = keyword_offset; | 1166 | mbc.keyword_offset = keyword_offset; |
1181 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1167 | /* calculate how many results we can send in this message */ |
1182 | &find_result_set, | 1168 | mbc.put_cnt = todo; |
1183 | &mbc); | 1169 | /* now build message */ |
1184 | total_seen_results = mbc.put_cnt; | 1170 | sm->query = sc->requests[keyword_offset].uquery; |
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 | } | ||
1185 | } | 1199 | } |
1186 | } | ||
1187 | } | ||
1188 | else | ||
1189 | { | ||
1190 | GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri)); | ||
1191 | |||
1192 | GNUNET_CRYPTO_ecdsa_public_key_derive (&sc->uri->data.sks.ns, | ||
1193 | sc->uri->data.sks.identifier, | ||
1194 | "fs-ublock", | ||
1195 | &dpub); | ||
1196 | GNUNET_CRYPTO_hash (&dpub, | ||
1197 | sizeof (dpub), | ||
1198 | &sm->query); | ||
1199 | mbc.put_cnt = todo; | ||
1200 | mbc.keyword_offset = 0; | ||
1201 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | ||
1202 | &build_result_set, | ||
1203 | &mbc); | ||
1204 | GNUNET_assert (total_seen_results >= search_request_map_offset); | ||
1205 | if (total_seen_results != search_request_map_offset) | ||
1206 | { | ||
1207 | /* more requesting to be done... */ | ||
1208 | sm->options = htonl (options | SEARCH_MESSAGE_OPTION_CONTINUED); | ||
1209 | } | ||
1210 | else | 1200 | else |
1211 | { | 1201 | { |
1212 | sm->options = htonl (options); | 1202 | GNUNET_assert(GNUNET_FS_uri_test_sks(sc->uri)); |
1213 | } | 1203 | |
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); | ||
1214 | } | 1229 | } |
1215 | GNUNET_MQ_send (sc->mq, | ||
1216 | env); | ||
1217 | } | ||
1218 | } | 1230 | } |
1219 | 1231 | ||
1220 | 1232 | ||
@@ -1227,17 +1239,17 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) | |||
1227 | * @param error error code | 1239 | * @param error error code |
1228 | */ | 1240 | */ |
1229 | static void | 1241 | static void |
1230 | search_mq_error_handler (void *cls, | 1242 | search_mq_error_handler(void *cls, |
1231 | enum GNUNET_MQ_Error error) | 1243 | enum GNUNET_MQ_Error error) |
1232 | { | 1244 | { |
1233 | struct GNUNET_FS_SearchContext *sc = cls; | 1245 | struct GNUNET_FS_SearchContext *sc = cls; |
1234 | 1246 | ||
1235 | if (NULL != sc->mq) | 1247 | if (NULL != sc->mq) |
1236 | { | 1248 | { |
1237 | GNUNET_MQ_destroy (sc->mq); | 1249 | GNUNET_MQ_destroy(sc->mq); |
1238 | sc->mq = NULL; | 1250 | sc->mq = NULL; |
1239 | } | 1251 | } |
1240 | try_reconnect (sc); | 1252 | try_reconnect(sc); |
1241 | } | 1253 | } |
1242 | 1254 | ||
1243 | 1255 | ||
@@ -1248,29 +1260,29 @@ search_mq_error_handler (void *cls, | |||
1248 | * @param cls our search context | 1260 | * @param cls our search context |
1249 | */ | 1261 | */ |
1250 | static void | 1262 | static void |
1251 | do_reconnect (void *cls) | 1263 | do_reconnect(void *cls) |
1252 | { | 1264 | { |
1253 | struct GNUNET_FS_SearchContext *sc = cls; | 1265 | struct GNUNET_FS_SearchContext *sc = cls; |
1254 | struct GNUNET_MQ_MessageHandler handlers[] = { | 1266 | struct GNUNET_MQ_MessageHandler handlers[] = { |
1255 | GNUNET_MQ_hd_var_size (result, | 1267 | GNUNET_MQ_hd_var_size(result, |
1256 | GNUNET_MESSAGE_TYPE_FS_PUT, | 1268 | GNUNET_MESSAGE_TYPE_FS_PUT, |
1257 | struct ClientPutMessage, | 1269 | struct ClientPutMessage, |
1258 | sc), | 1270 | sc), |
1259 | GNUNET_MQ_handler_end () | 1271 | GNUNET_MQ_handler_end() |
1260 | }; | 1272 | }; |
1261 | 1273 | ||
1262 | sc->task = NULL; | 1274 | sc->task = NULL; |
1263 | sc->mq = GNUNET_CLIENT_connect (sc->h->cfg, | 1275 | sc->mq = GNUNET_CLIENT_connect(sc->h->cfg, |
1264 | "fs", | 1276 | "fs", |
1265 | handlers, | 1277 | handlers, |
1266 | &search_mq_error_handler, | 1278 | &search_mq_error_handler, |
1267 | sc); | 1279 | sc); |
1268 | if (NULL == sc->mq) | 1280 | if (NULL == sc->mq) |
1269 | { | 1281 | { |
1270 | try_reconnect (sc); | 1282 | try_reconnect(sc); |
1271 | return; | 1283 | return; |
1272 | } | 1284 | } |
1273 | schedule_transmit_search_request (sc); | 1285 | schedule_transmit_search_request(sc); |
1274 | } | 1286 | } |
1275 | 1287 | ||
1276 | 1288 | ||
@@ -1282,18 +1294,18 @@ do_reconnect (void *cls) | |||
1282 | * @param sc the search to reconnec | 1294 | * @param sc the search to reconnec |
1283 | */ | 1295 | */ |
1284 | static void | 1296 | static void |
1285 | try_reconnect (struct GNUNET_FS_SearchContext *sc) | 1297 | try_reconnect(struct GNUNET_FS_SearchContext *sc) |
1286 | { | 1298 | { |
1287 | if (NULL != sc->mq) | 1299 | if (NULL != sc->mq) |
1288 | { | 1300 | { |
1289 | GNUNET_MQ_destroy (sc->mq); | 1301 | GNUNET_MQ_destroy(sc->mq); |
1290 | sc->mq = NULL; | 1302 | sc->mq = NULL; |
1291 | } | 1303 | } |
1292 | sc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (sc->reconnect_backoff); | 1304 | sc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF(sc->reconnect_backoff); |
1293 | sc->task = | 1305 | sc->task = |
1294 | GNUNET_SCHEDULER_add_delayed (sc->reconnect_backoff, | 1306 | GNUNET_SCHEDULER_add_delayed(sc->reconnect_backoff, |
1295 | &do_reconnect, | 1307 | &do_reconnect, |
1296 | sc); | 1308 | sc); |
1297 | } | 1309 | } |
1298 | 1310 | ||
1299 | 1311 | ||
@@ -1310,39 +1322,39 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc) | |||
1310 | * @return context that can be used to control the search | 1322 | * @return context that can be used to control the search |
1311 | */ | 1323 | */ |
1312 | static struct GNUNET_FS_SearchContext * | 1324 | static struct GNUNET_FS_SearchContext * |
1313 | search_start (struct GNUNET_FS_Handle *h, | 1325 | search_start(struct GNUNET_FS_Handle *h, |
1314 | const struct GNUNET_FS_Uri *uri, | 1326 | const struct GNUNET_FS_Uri *uri, |
1315 | uint32_t anonymity, | 1327 | uint32_t anonymity, |
1316 | enum GNUNET_FS_SearchOptions options, | 1328 | enum GNUNET_FS_SearchOptions options, |
1317 | void *cctx, | 1329 | void *cctx, |
1318 | struct GNUNET_FS_SearchResult *psearch) | 1330 | struct GNUNET_FS_SearchResult *psearch) |
1319 | { | 1331 | { |
1320 | struct GNUNET_FS_SearchContext *sc; | 1332 | struct GNUNET_FS_SearchContext *sc; |
1321 | struct GNUNET_FS_ProgressInfo pi; | 1333 | struct GNUNET_FS_ProgressInfo pi; |
1322 | 1334 | ||
1323 | sc = GNUNET_new (struct GNUNET_FS_SearchContext); | 1335 | sc = GNUNET_new(struct GNUNET_FS_SearchContext); |
1324 | sc->h = h; | 1336 | sc->h = h; |
1325 | sc->options = options; | 1337 | sc->options = options; |
1326 | sc->uri = GNUNET_FS_uri_dup (uri); | 1338 | sc->uri = GNUNET_FS_uri_dup(uri); |
1327 | sc->anonymity = anonymity; | 1339 | sc->anonymity = anonymity; |
1328 | sc->start_time = GNUNET_TIME_absolute_get (); | 1340 | sc->start_time = GNUNET_TIME_absolute_get(); |
1329 | if (NULL != psearch) | 1341 | if (NULL != psearch) |
1330 | { | 1342 | { |
1331 | sc->psearch_result = psearch; | 1343 | sc->psearch_result = psearch; |
1332 | psearch->update_search = sc; | 1344 | psearch->update_search = sc; |
1333 | } | 1345 | } |
1334 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); | 1346 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create(16, GNUNET_NO); |
1335 | sc->client_info = cctx; | 1347 | sc->client_info = cctx; |
1336 | if (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc)) | 1348 | if (GNUNET_OK != GNUNET_FS_search_start_searching_(sc)) |
1337 | { | 1349 | { |
1338 | GNUNET_FS_uri_destroy (sc->uri); | 1350 | GNUNET_FS_uri_destroy(sc->uri); |
1339 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); | 1351 | GNUNET_CONTAINER_multihashmap_destroy(sc->master_result_map); |
1340 | GNUNET_free (sc); | 1352 | GNUNET_free(sc); |
1341 | return NULL; | 1353 | return NULL; |
1342 | } | 1354 | } |
1343 | GNUNET_FS_search_sync_ (sc); | 1355 | GNUNET_FS_search_sync_(sc); |
1344 | pi.status = GNUNET_FS_STATUS_SEARCH_START; | 1356 | pi.status = GNUNET_FS_STATUS_SEARCH_START; |
1345 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 1357 | sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); |
1346 | return sc; | 1358 | return sc; |
1347 | } | 1359 | } |
1348 | 1360 | ||
@@ -1357,9 +1369,9 @@ search_start (struct GNUNET_FS_Handle *h, | |||
1357 | * @return #GNUNET_YES (we should continue to iterate) | 1369 | * @return #GNUNET_YES (we should continue to iterate) |
1358 | */ | 1370 | */ |
1359 | static int | 1371 | static int |
1360 | update_sre_result_maps (void *cls, | 1372 | update_sre_result_maps(void *cls, |
1361 | const struct GNUNET_HashCode *key, | 1373 | const struct GNUNET_HashCode *key, |
1362 | void *value) | 1374 | void *value) |
1363 | { | 1375 | { |
1364 | struct GNUNET_FS_SearchContext *sc = cls; | 1376 | struct GNUNET_FS_SearchContext *sc = cls; |
1365 | struct GNUNET_FS_SearchResult *sr = value; | 1377 | struct GNUNET_FS_SearchResult *sr = value; |
@@ -1367,11 +1379,11 @@ update_sre_result_maps (void *cls, | |||
1367 | 1379 | ||
1368 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | 1380 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
1369 | if (0 != (sr->keyword_bitmap[i / 8] & (1 << (i % 8)))) | 1381 | if (0 != (sr->keyword_bitmap[i / 8] & (1 << (i % 8)))) |
1370 | GNUNET_break (GNUNET_OK == | 1382 | GNUNET_break(GNUNET_OK == |
1371 | GNUNET_CONTAINER_multihashmap_put (sc->requests[i].results, | 1383 | GNUNET_CONTAINER_multihashmap_put(sc->requests[i].results, |
1372 | &sr->key, | 1384 | &sr->key, |
1373 | sr, | 1385 | sr, |
1374 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1386 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1375 | 1387 | ||
1376 | return GNUNET_YES; | 1388 | return GNUNET_YES; |
1377 | } | 1389 | } |
@@ -1385,7 +1397,7 @@ update_sre_result_maps (void *cls, | |||
1385 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1397 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1386 | */ | 1398 | */ |
1387 | int | 1399 | int |
1388 | GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc) | 1400 | GNUNET_FS_search_start_searching_(struct GNUNET_FS_SearchContext *sc) |
1389 | { | 1401 | { |
1390 | unsigned int i; | 1402 | unsigned int i; |
1391 | const char *keyword; | 1403 | const char *keyword; |
@@ -1393,45 +1405,45 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc) | |||
1393 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; | 1405 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; |
1394 | struct SearchRequestEntry *sre; | 1406 | struct SearchRequestEntry *sre; |
1395 | 1407 | ||
1396 | GNUNET_assert (NULL == sc->mq); | 1408 | GNUNET_assert(NULL == sc->mq); |
1397 | if (GNUNET_FS_uri_test_ksk (sc->uri)) | 1409 | if (GNUNET_FS_uri_test_ksk(sc->uri)) |
1398 | { | ||
1399 | GNUNET_assert (0 != sc->uri->data.ksk.keywordCount); | ||
1400 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); | ||
1401 | GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub); | ||
1402 | sc->requests | ||
1403 | = GNUNET_new_array (sc->uri->data.ksk.keywordCount, | ||
1404 | struct SearchRequestEntry); | ||
1405 | |||
1406 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | ||
1407 | { | 1410 | { |
1408 | keyword = &sc->uri->data.ksk.keywords[i][1]; | 1411 | GNUNET_assert(0 != sc->uri->data.ksk.keywordCount); |
1409 | sre = &sc->requests[i]; | 1412 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous(); |
1410 | sre->keyword = GNUNET_strdup (keyword); | 1413 | GNUNET_CRYPTO_ecdsa_key_get_public(anon, &anon_pub); |
1411 | GNUNET_CRYPTO_ecdsa_public_key_derive (&anon_pub, | 1414 | sc->requests |
1412 | keyword, | 1415 | = GNUNET_new_array(sc->uri->data.ksk.keywordCount, |
1413 | "fs-ublock", | 1416 | struct SearchRequestEntry); |
1414 | &sre->dpub); | 1417 | |
1415 | GNUNET_CRYPTO_hash (&sre->dpub, | 1418 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
1416 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), | 1419 | { |
1417 | &sre->uquery); | 1420 | keyword = &sc->uri->data.ksk.keywords[i][1]; |
1418 | sre->mandatory = (sc->uri->data.ksk.keywords[i][0] == '+'); | 1421 | sre = &sc->requests[i]; |
1419 | if (sre->mandatory) | 1422 | sre->keyword = GNUNET_strdup(keyword); |
1420 | sc->mandatory_count++; | 1423 | GNUNET_CRYPTO_ecdsa_public_key_derive(&anon_pub, |
1421 | sre->results = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO); | 1424 | keyword, |
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); | ||
1422 | } | 1438 | } |
1423 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1439 | GNUNET_assert(NULL == sc->task); |
1424 | &update_sre_result_maps, | 1440 | do_reconnect(sc); |
1425 | sc); | ||
1426 | } | ||
1427 | GNUNET_assert (NULL == sc->task); | ||
1428 | do_reconnect (sc); | ||
1429 | if (NULL == sc->mq) | 1441 | if (NULL == sc->mq) |
1430 | { | 1442 | { |
1431 | GNUNET_SCHEDULER_cancel (sc->task); | 1443 | GNUNET_SCHEDULER_cancel(sc->task); |
1432 | sc->task = NULL; | 1444 | sc->task = NULL; |
1433 | return GNUNET_SYSERR; | 1445 | return GNUNET_SYSERR; |
1434 | } | 1446 | } |
1435 | return GNUNET_OK; | 1447 | return GNUNET_OK; |
1436 | } | 1448 | } |
1437 | 1449 | ||
@@ -1445,25 +1457,25 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc) | |||
1445 | * @return #GNUNET_OK | 1457 | * @return #GNUNET_OK |
1446 | */ | 1458 | */ |
1447 | static int | 1459 | static int |
1448 | search_result_freeze_probes (void *cls, | 1460 | search_result_freeze_probes(void *cls, |
1449 | const struct GNUNET_HashCode *key, | 1461 | const struct GNUNET_HashCode *key, |
1450 | void *value) | 1462 | void *value) |
1451 | { | 1463 | { |
1452 | struct GNUNET_FS_SearchResult *sr = value; | 1464 | struct GNUNET_FS_SearchResult *sr = value; |
1453 | 1465 | ||
1454 | if (NULL != sr->probe_ctx) | 1466 | if (NULL != sr->probe_ctx) |
1455 | { | 1467 | { |
1456 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); | 1468 | GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); |
1457 | sr->probe_ctx = NULL; | 1469 | sr->probe_ctx = NULL; |
1458 | GNUNET_FS_stop_probe_ping_task_ (sr); | 1470 | GNUNET_FS_stop_probe_ping_task_(sr); |
1459 | } | 1471 | } |
1460 | if (NULL != sr->probe_cancel_task) | 1472 | if (NULL != sr->probe_cancel_task) |
1461 | { | 1473 | { |
1462 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | 1474 | GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); |
1463 | sr->probe_cancel_task = NULL; | 1475 | sr->probe_cancel_task = NULL; |
1464 | } | 1476 | } |
1465 | if (NULL != sr->update_search) | 1477 | if (NULL != sr->update_search) |
1466 | GNUNET_FS_search_pause (sr->update_search); | 1478 | GNUNET_FS_search_pause(sr->update_search); |
1467 | return GNUNET_OK; | 1479 | return GNUNET_OK; |
1468 | } | 1480 | } |
1469 | 1481 | ||
@@ -1477,15 +1489,15 @@ search_result_freeze_probes (void *cls, | |||
1477 | * @return #GNUNET_OK | 1489 | * @return #GNUNET_OK |
1478 | */ | 1490 | */ |
1479 | static int | 1491 | static int |
1480 | search_result_resume_probes (void *cls, | 1492 | search_result_resume_probes(void *cls, |
1481 | const struct GNUNET_HashCode * key, | 1493 | const struct GNUNET_HashCode * key, |
1482 | void *value) | 1494 | void *value) |
1483 | { | 1495 | { |
1484 | struct GNUNET_FS_SearchResult *sr = value; | 1496 | struct GNUNET_FS_SearchResult *sr = value; |
1485 | 1497 | ||
1486 | GNUNET_FS_search_start_probe_ (sr); | 1498 | GNUNET_FS_search_start_probe_(sr); |
1487 | if (NULL != sr->update_search) | 1499 | if (NULL != sr->update_search) |
1488 | GNUNET_FS_search_continue (sr->update_search); | 1500 | GNUNET_FS_search_continue(sr->update_search); |
1489 | return GNUNET_OK; | 1501 | return GNUNET_OK; |
1490 | } | 1502 | } |
1491 | 1503 | ||
@@ -1499,40 +1511,40 @@ search_result_resume_probes (void *cls, | |||
1499 | * @return #GNUNET_OK | 1511 | * @return #GNUNET_OK |
1500 | */ | 1512 | */ |
1501 | static int | 1513 | static int |
1502 | search_result_suspend (void *cls, | 1514 | search_result_suspend(void *cls, |
1503 | const struct GNUNET_HashCode *key, | 1515 | const struct GNUNET_HashCode *key, |
1504 | void *value) | 1516 | void *value) |
1505 | { | 1517 | { |
1506 | struct GNUNET_FS_SearchContext *sc = cls; | 1518 | struct GNUNET_FS_SearchContext *sc = cls; |
1507 | struct GNUNET_FS_SearchResult *sr = value; | 1519 | struct GNUNET_FS_SearchResult *sr = value; |
1508 | struct GNUNET_FS_ProgressInfo pi; | 1520 | struct GNUNET_FS_ProgressInfo pi; |
1509 | 1521 | ||
1510 | if (NULL != sr->download) | 1522 | if (NULL != sr->download) |
1511 | { | 1523 | { |
1512 | GNUNET_FS_download_signal_suspend_ (sr->download); | 1524 | GNUNET_FS_download_signal_suspend_(sr->download); |
1513 | sr->download = NULL; | 1525 | sr->download = NULL; |
1514 | } | 1526 | } |
1515 | if (NULL != sr->update_search) | 1527 | if (NULL != sr->update_search) |
1516 | { | 1528 | { |
1517 | GNUNET_FS_search_signal_suspend_ (sr->update_search); | 1529 | GNUNET_FS_search_signal_suspend_(sr->update_search); |
1518 | sr->update_search = NULL; | 1530 | sr->update_search = NULL; |
1519 | } | 1531 | } |
1520 | GNUNET_FS_search_stop_probe_ (sr); | 1532 | GNUNET_FS_search_stop_probe_(sr); |
1521 | if (0 == sr->mandatory_missing) | 1533 | if (0 == sr->mandatory_missing) |
1522 | { | 1534 | { |
1523 | /* client is aware of search result, notify about suspension event */ | 1535 | /* client is aware of search result, notify about suspension event */ |
1524 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND; | 1536 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND; |
1525 | pi.value.search.specifics.result_suspend.cctx = sr->client_info; | 1537 | pi.value.search.specifics.result_suspend.cctx = sr->client_info; |
1526 | pi.value.search.specifics.result_suspend.meta = sr->meta; | 1538 | pi.value.search.specifics.result_suspend.meta = sr->meta; |
1527 | pi.value.search.specifics.result_suspend.uri = sr->uri; | 1539 | pi.value.search.specifics.result_suspend.uri = sr->uri; |
1528 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 1540 | sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); |
1529 | } | 1541 | } |
1530 | GNUNET_break (NULL == sr->client_info); | 1542 | GNUNET_break(NULL == sr->client_info); |
1531 | GNUNET_free_non_null (sr->serialization); | 1543 | GNUNET_free_non_null(sr->serialization); |
1532 | GNUNET_FS_uri_destroy (sr->uri); | 1544 | GNUNET_FS_uri_destroy(sr->uri); |
1533 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); | 1545 | GNUNET_CONTAINER_meta_data_destroy(sr->meta); |
1534 | GNUNET_free_non_null (sr->keyword_bitmap); | 1546 | GNUNET_free_non_null(sr->keyword_bitmap); |
1535 | GNUNET_free (sr); | 1547 | GNUNET_free(sr); |
1536 | return GNUNET_OK; | 1548 | return GNUNET_OK; |
1537 | } | 1549 | } |
1538 | 1550 | ||
@@ -1544,43 +1556,43 @@ search_result_suspend (void *cls, | |||
1544 | * @param cls the `struct GNUNET_FS_SearchContext` to signal for | 1556 | * @param cls the `struct GNUNET_FS_SearchContext` to signal for |
1545 | */ | 1557 | */ |
1546 | void | 1558 | void |
1547 | GNUNET_FS_search_signal_suspend_ (void *cls) | 1559 | GNUNET_FS_search_signal_suspend_(void *cls) |
1548 | { | 1560 | { |
1549 | struct GNUNET_FS_SearchContext *sc = cls; | 1561 | struct GNUNET_FS_SearchContext *sc = cls; |
1550 | struct GNUNET_FS_ProgressInfo pi; | 1562 | struct GNUNET_FS_ProgressInfo pi; |
1551 | unsigned int i; | 1563 | unsigned int i; |
1552 | 1564 | ||
1553 | GNUNET_FS_end_top (sc->h, sc->top); | 1565 | GNUNET_FS_end_top(sc->h, sc->top); |
1554 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1566 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, |
1555 | &search_result_suspend, sc); | 1567 | &search_result_suspend, sc); |
1556 | pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND; | 1568 | pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND; |
1557 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 1569 | sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); |
1558 | GNUNET_break (NULL == sc->client_info); | 1570 | GNUNET_break(NULL == sc->client_info); |
1559 | if (sc->task != NULL) | 1571 | if (sc->task != NULL) |
1560 | { | 1572 | { |
1561 | GNUNET_SCHEDULER_cancel (sc->task); | 1573 | GNUNET_SCHEDULER_cancel(sc->task); |
1562 | sc->task = NULL; | 1574 | sc->task = NULL; |
1563 | } | 1575 | } |
1564 | if (NULL != sc->mq) | 1576 | if (NULL != sc->mq) |
1565 | { | 1577 | { |
1566 | GNUNET_MQ_destroy (sc->mq); | 1578 | GNUNET_MQ_destroy(sc->mq); |
1567 | sc->mq = NULL; | 1579 | sc->mq = NULL; |
1568 | } | 1580 | } |
1569 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); | 1581 | GNUNET_CONTAINER_multihashmap_destroy(sc->master_result_map); |
1570 | if (NULL != sc->requests) | 1582 | if (NULL != sc->requests) |
1571 | { | ||
1572 | GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); | ||
1573 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | ||
1574 | { | 1583 | { |
1575 | GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); | 1584 | GNUNET_assert(GNUNET_FS_uri_test_ksk(sc->uri)); |
1576 | GNUNET_free (sc->requests[i].keyword); | 1585 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
1586 | { | ||
1587 | GNUNET_CONTAINER_multihashmap_destroy(sc->requests[i].results); | ||
1588 | GNUNET_free(sc->requests[i].keyword); | ||
1589 | } | ||
1577 | } | 1590 | } |
1578 | } | 1591 | GNUNET_free_non_null(sc->requests); |
1579 | GNUNET_free_non_null (sc->requests); | 1592 | GNUNET_free_non_null(sc->emsg); |
1580 | GNUNET_free_non_null (sc->emsg); | 1593 | GNUNET_FS_uri_destroy(sc->uri); |
1581 | GNUNET_FS_uri_destroy (sc->uri); | 1594 | GNUNET_free_non_null(sc->serialization); |
1582 | GNUNET_free_non_null (sc->serialization); | 1595 | GNUNET_free(sc); |
1583 | GNUNET_free (sc); | ||
1584 | } | 1596 | } |
1585 | 1597 | ||
1586 | 1598 | ||
@@ -1596,16 +1608,16 @@ GNUNET_FS_search_signal_suspend_ (void *cls) | |||
1596 | * @return context that can be used to control the search | 1608 | * @return context that can be used to control the search |
1597 | */ | 1609 | */ |
1598 | struct GNUNET_FS_SearchContext * | 1610 | struct GNUNET_FS_SearchContext * |
1599 | GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, | 1611 | GNUNET_FS_search_start(struct GNUNET_FS_Handle *h, |
1600 | const struct GNUNET_FS_Uri *uri, uint32_t anonymity, | 1612 | const struct GNUNET_FS_Uri *uri, uint32_t anonymity, |
1601 | enum GNUNET_FS_SearchOptions options, void *cctx) | 1613 | enum GNUNET_FS_SearchOptions options, void *cctx) |
1602 | { | 1614 | { |
1603 | struct GNUNET_FS_SearchContext *ret; | 1615 | struct GNUNET_FS_SearchContext *ret; |
1604 | 1616 | ||
1605 | ret = search_start (h, uri, anonymity, options, cctx, NULL); | 1617 | ret = search_start(h, uri, anonymity, options, cctx, NULL); |
1606 | if (NULL == ret) | 1618 | if (NULL == ret) |
1607 | return NULL; | 1619 | return NULL; |
1608 | ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, ret); | 1620 | ret->top = GNUNET_FS_make_top(h, &GNUNET_FS_search_signal_suspend_, ret); |
1609 | return ret; | 1621 | return ret; |
1610 | } | 1622 | } |
1611 | 1623 | ||
@@ -1616,28 +1628,28 @@ GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, | |||
1616 | * @param sc context for the search that should be paused | 1628 | * @param sc context for the search that should be paused |
1617 | */ | 1629 | */ |
1618 | void | 1630 | void |
1619 | GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc) | 1631 | GNUNET_FS_search_pause(struct GNUNET_FS_SearchContext *sc) |
1620 | { | 1632 | { |
1621 | struct GNUNET_FS_ProgressInfo pi; | 1633 | struct GNUNET_FS_ProgressInfo pi; |
1622 | 1634 | ||
1623 | if (NULL != sc->task) | 1635 | if (NULL != sc->task) |
1624 | { | 1636 | { |
1625 | GNUNET_SCHEDULER_cancel (sc->task); | 1637 | GNUNET_SCHEDULER_cancel(sc->task); |
1626 | sc->task = NULL; | 1638 | sc->task = NULL; |
1627 | } | 1639 | } |
1628 | if (NULL != sc->mq) | 1640 | if (NULL != sc->mq) |
1629 | { | 1641 | { |
1630 | GNUNET_MQ_destroy (sc->mq); | 1642 | GNUNET_MQ_destroy(sc->mq); |
1631 | sc->mq = NULL; | 1643 | sc->mq = NULL; |
1632 | } | 1644 | } |
1633 | GNUNET_FS_search_sync_ (sc); | 1645 | GNUNET_FS_search_sync_(sc); |
1634 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1646 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, |
1635 | &search_result_freeze_probes, | 1647 | &search_result_freeze_probes, |
1636 | sc); | 1648 | sc); |
1637 | pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED; | 1649 | pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED; |
1638 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, | 1650 | sc->client_info = GNUNET_FS_search_make_status_(&pi, |
1639 | sc->h, | 1651 | sc->h, |
1640 | sc); | 1652 | sc); |
1641 | } | 1653 | } |
1642 | 1654 | ||
1643 | 1655 | ||
@@ -1647,18 +1659,18 @@ GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc) | |||
1647 | * @param sc context for the search that should be resumed | 1659 | * @param sc context for the search that should be resumed |
1648 | */ | 1660 | */ |
1649 | void | 1661 | void |
1650 | GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc) | 1662 | GNUNET_FS_search_continue(struct GNUNET_FS_SearchContext *sc) |
1651 | { | 1663 | { |
1652 | struct GNUNET_FS_ProgressInfo pi; | 1664 | struct GNUNET_FS_ProgressInfo pi; |
1653 | 1665 | ||
1654 | GNUNET_assert (NULL == sc->mq); | 1666 | GNUNET_assert(NULL == sc->mq); |
1655 | GNUNET_assert (NULL == sc->task); | 1667 | GNUNET_assert(NULL == sc->task); |
1656 | do_reconnect (sc); | 1668 | do_reconnect(sc); |
1657 | GNUNET_FS_search_sync_ (sc); | 1669 | GNUNET_FS_search_sync_(sc); |
1658 | pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED; | 1670 | pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED; |
1659 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 1671 | sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); |
1660 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1672 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, |
1661 | &search_result_resume_probes, sc); | 1673 | &search_result_resume_probes, sc); |
1662 | } | 1674 | } |
1663 | 1675 | ||
1664 | 1676 | ||
@@ -1671,48 +1683,48 @@ GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc) | |||
1671 | * @return #GNUNET_OK | 1683 | * @return #GNUNET_OK |
1672 | */ | 1684 | */ |
1673 | static int | 1685 | static int |
1674 | search_result_stop (void *cls, | 1686 | search_result_stop(void *cls, |
1675 | const struct GNUNET_HashCode *key, | 1687 | const struct GNUNET_HashCode *key, |
1676 | void *value) | 1688 | void *value) |
1677 | { | 1689 | { |
1678 | struct GNUNET_FS_SearchContext *sc = cls; | 1690 | struct GNUNET_FS_SearchContext *sc = cls; |
1679 | struct GNUNET_FS_SearchResult *sr = value; | 1691 | struct GNUNET_FS_SearchResult *sr = value; |
1680 | struct GNUNET_FS_ProgressInfo pi; | 1692 | struct GNUNET_FS_ProgressInfo pi; |
1681 | 1693 | ||
1682 | GNUNET_FS_search_stop_probe_ (sr); | 1694 | GNUNET_FS_search_stop_probe_(sr); |
1683 | if (NULL != sr->download) | 1695 | if (NULL != sr->download) |
1684 | { | ||
1685 | sr->download->search = NULL; | ||
1686 | sr->download->top | ||
1687 | = GNUNET_FS_make_top (sr->download->h, | ||
1688 | &GNUNET_FS_download_signal_suspend_, | ||
1689 | sr->download); | ||
1690 | if (NULL != sr->download->serialization) | ||
1691 | { | 1696 | { |
1692 | GNUNET_FS_remove_sync_file_ (sc->h, | 1697 | sr->download->search = NULL; |
1693 | GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, | 1698 | sr->download->top |
1694 | sr->download->serialization); | 1699 | = GNUNET_FS_make_top(sr->download->h, |
1695 | GNUNET_free (sr->download->serialization); | 1700 | &GNUNET_FS_download_signal_suspend_, |
1696 | sr->download->serialization = NULL; | 1701 | sr->download); |
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; | ||
1697 | } | 1715 | } |
1698 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT; | ||
1699 | GNUNET_FS_download_make_status_ (&pi, | ||
1700 | sr->download); | ||
1701 | GNUNET_FS_download_sync_ (sr->download); | ||
1702 | sr->download = NULL; | ||
1703 | } | ||
1704 | if (0 != sr->mandatory_missing) | 1716 | if (0 != sr->mandatory_missing) |
1705 | { | 1717 | { |
1706 | /* client is unaware of search result as | 1718 | /* client is unaware of search result as |
1707 | it does not match required keywords */ | 1719 | it does not match required keywords */ |
1708 | GNUNET_break (NULL == sr->client_info); | 1720 | GNUNET_break(NULL == sr->client_info); |
1709 | return GNUNET_OK; | 1721 | return GNUNET_OK; |
1710 | } | 1722 | } |
1711 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED; | 1723 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED; |
1712 | pi.value.search.specifics.result_stopped.cctx = sr->client_info; | 1724 | pi.value.search.specifics.result_stopped.cctx = sr->client_info; |
1713 | pi.value.search.specifics.result_stopped.meta = sr->meta; | 1725 | pi.value.search.specifics.result_stopped.meta = sr->meta; |
1714 | pi.value.search.specifics.result_stopped.uri = sr->uri; | 1726 | pi.value.search.specifics.result_stopped.uri = sr->uri; |
1715 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sr->h, sc); | 1727 | sr->client_info = GNUNET_FS_search_make_status_(&pi, sr->h, sc); |
1716 | return GNUNET_OK; | 1728 | return GNUNET_OK; |
1717 | } | 1729 | } |
1718 | 1730 | ||
@@ -1726,25 +1738,25 @@ search_result_stop (void *cls, | |||
1726 | * @return #GNUNET_OK | 1738 | * @return #GNUNET_OK |
1727 | */ | 1739 | */ |
1728 | static int | 1740 | static int |
1729 | search_result_free (void *cls, | 1741 | search_result_free(void *cls, |
1730 | const struct GNUNET_HashCode *key, | 1742 | const struct GNUNET_HashCode *key, |
1731 | void *value) | 1743 | void *value) |
1732 | { | 1744 | { |
1733 | struct GNUNET_FS_SearchResult *sr = value; | 1745 | struct GNUNET_FS_SearchResult *sr = value; |
1734 | 1746 | ||
1735 | if (NULL != sr->update_search) | 1747 | if (NULL != sr->update_search) |
1736 | { | 1748 | { |
1737 | GNUNET_FS_search_stop (sr->update_search); | 1749 | GNUNET_FS_search_stop(sr->update_search); |
1738 | GNUNET_assert (NULL == sr->update_search); | 1750 | GNUNET_assert(NULL == sr->update_search); |
1739 | } | 1751 | } |
1740 | GNUNET_break (NULL == sr->probe_ctx); | 1752 | GNUNET_break(NULL == sr->probe_ctx); |
1741 | GNUNET_break (NULL == sr->probe_cancel_task); | 1753 | GNUNET_break(NULL == sr->probe_cancel_task); |
1742 | GNUNET_break (NULL == sr->client_info); | 1754 | GNUNET_break(NULL == sr->client_info); |
1743 | GNUNET_free_non_null (sr->serialization); | 1755 | GNUNET_free_non_null(sr->serialization); |
1744 | GNUNET_FS_uri_destroy (sr->uri); | 1756 | GNUNET_FS_uri_destroy(sr->uri); |
1745 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); | 1757 | GNUNET_CONTAINER_meta_data_destroy(sr->meta); |
1746 | GNUNET_free_non_null (sr->keyword_bitmap); | 1758 | GNUNET_free_non_null(sr->keyword_bitmap); |
1747 | GNUNET_free (sr); | 1759 | GNUNET_free(sr); |
1748 | return GNUNET_OK; | 1760 | return GNUNET_OK; |
1749 | } | 1761 | } |
1750 | 1762 | ||
@@ -1755,60 +1767,60 @@ search_result_free (void *cls, | |||
1755 | * @param sc context for the search that should be stopped | 1767 | * @param sc context for the search that should be stopped |
1756 | */ | 1768 | */ |
1757 | void | 1769 | void |
1758 | GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc) | 1770 | GNUNET_FS_search_stop(struct GNUNET_FS_SearchContext *sc) |
1759 | { | 1771 | { |
1760 | struct GNUNET_FS_ProgressInfo pi; | 1772 | struct GNUNET_FS_ProgressInfo pi; |
1761 | unsigned int i; | 1773 | unsigned int i; |
1762 | 1774 | ||
1763 | if (NULL != sc->top) | 1775 | if (NULL != sc->top) |
1764 | GNUNET_FS_end_top (sc->h, sc->top); | 1776 | GNUNET_FS_end_top(sc->h, sc->top); |
1765 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1777 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, |
1766 | &search_result_stop, | 1778 | &search_result_stop, |
1767 | sc); | 1779 | sc); |
1768 | if (NULL != sc->psearch_result) | 1780 | if (NULL != sc->psearch_result) |
1769 | sc->psearch_result->update_search = NULL; | 1781 | sc->psearch_result->update_search = NULL; |
1770 | if (NULL != sc->serialization) | 1782 | if (NULL != sc->serialization) |
1771 | { | 1783 | { |
1772 | GNUNET_FS_remove_sync_file_ (sc->h, | 1784 | 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, | ||
1773 | (NULL != sc->psearch_result) | 1790 | (NULL != sc->psearch_result) |
1774 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH | 1791 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH |
1775 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | 1792 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, |
1776 | sc->serialization); | 1793 | sc->serialization); |
1777 | GNUNET_FS_remove_sync_dir_ (sc->h, | 1794 | GNUNET_free(sc->serialization); |
1778 | (NULL != sc->psearch_result) | 1795 | } |
1779 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH | ||
1780 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | ||
1781 | sc->serialization); | ||
1782 | GNUNET_free (sc->serialization); | ||
1783 | } | ||
1784 | pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED; | 1796 | pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED; |
1785 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, | 1797 | sc->client_info = GNUNET_FS_search_make_status_(&pi, |
1786 | sc->h, | 1798 | sc->h, |
1787 | sc); | 1799 | sc); |
1788 | GNUNET_break (NULL == sc->client_info); | 1800 | GNUNET_break(NULL == sc->client_info); |
1789 | if (NULL != sc->task) | 1801 | if (NULL != sc->task) |
1790 | { | 1802 | { |
1791 | GNUNET_SCHEDULER_cancel (sc->task); | 1803 | GNUNET_SCHEDULER_cancel(sc->task); |
1792 | sc->task = NULL; | 1804 | sc->task = NULL; |
1793 | } | 1805 | } |
1794 | if (NULL != sc->mq) | 1806 | if (NULL != sc->mq) |
1795 | { | 1807 | { |
1796 | GNUNET_MQ_destroy (sc->mq); | 1808 | GNUNET_MQ_destroy(sc->mq); |
1797 | sc->mq = NULL; | 1809 | sc->mq = NULL; |
1798 | } | 1810 | } |
1799 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1811 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, |
1800 | &search_result_free, sc); | 1812 | &search_result_free, sc); |
1801 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); | 1813 | GNUNET_CONTAINER_multihashmap_destroy(sc->master_result_map); |
1802 | if (NULL != sc->requests) | 1814 | if (NULL != sc->requests) |
1803 | { | 1815 | { |
1804 | GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); | 1816 | GNUNET_assert(GNUNET_FS_uri_test_ksk(sc->uri)); |
1805 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | 1817 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
1806 | GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); | 1818 | GNUNET_CONTAINER_multihashmap_destroy(sc->requests[i].results); |
1807 | } | 1819 | } |
1808 | GNUNET_free_non_null (sc->requests); | 1820 | GNUNET_free_non_null(sc->requests); |
1809 | GNUNET_free_non_null (sc->emsg); | 1821 | GNUNET_free_non_null(sc->emsg); |
1810 | GNUNET_FS_uri_destroy (sc->uri); | 1822 | GNUNET_FS_uri_destroy(sc->uri); |
1811 | GNUNET_free (sc); | 1823 | GNUNET_free(sc); |
1812 | } | 1824 | } |
1813 | 1825 | ||
1814 | /* end of fs_search.c */ | 1826 | /* end of fs_search.c */ |
diff --git a/src/fs/fs_sharetree.c b/src/fs/fs_sharetree.c index 282d7796a..a2cc37170 100644 --- a/src/fs/fs_sharetree.c +++ b/src/fs/fs_sharetree.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_sharetree.c | 22 | * @file fs/fs_sharetree.c |
@@ -34,9 +34,7 @@ | |||
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 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * This is a doubly-linked list | 39 | * This is a doubly-linked list |
42 | */ | 40 | */ |
@@ -56,16 +54,13 @@ struct KeywordCounter | |||
56 | * How many files have this keyword? | 54 | * How many files have this keyword? |
57 | */ | 55 | */ |
58 | unsigned int count; | 56 | unsigned int count; |
59 | |||
60 | }; | 57 | }; |
61 | 58 | ||
62 | 59 | ||
63 | /** | 60 | /** |
64 | * Aggregate information we keep for meta data in each directory. | 61 | * Aggregate information we keep for meta data in each directory. |
65 | */ | 62 | */ |
66 | struct MetaCounter | 63 | struct MetaCounter { |
67 | { | ||
68 | |||
69 | /** | 64 | /** |
70 | * This is a doubly-linked list | 65 | * This is a doubly-linked list |
71 | */ | 66 | */ |
@@ -111,7 +106,6 @@ struct MetaCounter | |||
111 | * (type and format do not have to match). | 106 | * (type and format do not have to match). |
112 | */ | 107 | */ |
113 | unsigned int count; | 108 | unsigned int count; |
114 | |||
115 | }; | 109 | }; |
116 | 110 | ||
117 | 111 | ||
@@ -119,9 +113,7 @@ struct MetaCounter | |||
119 | * A structure that forms a singly-linked list that serves as a stack | 113 | * A structure that forms a singly-linked list that serves as a stack |
120 | * for metadata-processing function. | 114 | * for metadata-processing function. |
121 | */ | 115 | */ |
122 | struct TrimContext | 116 | struct TrimContext { |
123 | { | ||
124 | |||
125 | /** | 117 | /** |
126 | * Map from the hash over the keyword to an 'struct KeywordCounter *' | 118 | * Map from the hash over the keyword to an 'struct KeywordCounter *' |
127 | * counter that says how often this keyword was | 119 | * counter that says how often this keyword was |
@@ -145,7 +137,6 @@ struct TrimContext | |||
145 | * Number of times an item has to be found to be moved to the parent. | 137 | * Number of times an item has to be found to be moved to the parent. |
146 | */ | 138 | */ |
147 | unsigned int move_threshold; | 139 | unsigned int move_threshold; |
148 | |||
149 | }; | 140 | }; |
150 | 141 | ||
151 | 142 | ||
@@ -158,26 +149,26 @@ struct TrimContext | |||
158 | * @return always GNUNET_OK | 149 | * @return always GNUNET_OK |
159 | */ | 150 | */ |
160 | static int | 151 | static int |
161 | add_to_keyword_counter (void *cls, const char *keyword, int is_mandatory) | 152 | add_to_keyword_counter(void *cls, const char *keyword, int is_mandatory) |
162 | { | 153 | { |
163 | struct GNUNET_CONTAINER_MultiHashMap *mcm = cls; | 154 | struct GNUNET_CONTAINER_MultiHashMap *mcm = cls; |
164 | struct KeywordCounter *cnt; | 155 | struct KeywordCounter *cnt; |
165 | struct GNUNET_HashCode hc; | 156 | struct GNUNET_HashCode hc; |
166 | size_t klen; | 157 | size_t klen; |
167 | 158 | ||
168 | klen = strlen (keyword) + 1; | 159 | klen = strlen(keyword) + 1; |
169 | GNUNET_CRYPTO_hash (keyword, klen - 1, &hc); | 160 | GNUNET_CRYPTO_hash(keyword, klen - 1, &hc); |
170 | cnt = GNUNET_CONTAINER_multihashmap_get (mcm, &hc); | 161 | cnt = GNUNET_CONTAINER_multihashmap_get(mcm, &hc); |
171 | if (cnt == NULL) | 162 | if (cnt == NULL) |
172 | { | 163 | { |
173 | cnt = GNUNET_malloc (sizeof (struct KeywordCounter) + klen); | 164 | cnt = GNUNET_malloc(sizeof(struct KeywordCounter) + klen); |
174 | cnt->value = (const char *) &cnt[1]; | 165 | cnt->value = (const char *)&cnt[1]; |
175 | GNUNET_memcpy (&cnt[1], keyword, klen); | 166 | GNUNET_memcpy(&cnt[1], keyword, klen); |
176 | GNUNET_assert (GNUNET_OK == | 167 | GNUNET_assert(GNUNET_OK == |
177 | GNUNET_CONTAINER_multihashmap_put (mcm, | 168 | GNUNET_CONTAINER_multihashmap_put(mcm, |
178 | &hc, cnt, | 169 | &hc, cnt, |
179 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 170 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
180 | } | 171 | } |
181 | cnt->count++; | 172 | cnt->count++; |
182 | return GNUNET_OK; | 173 | return GNUNET_OK; |
183 | } | 174 | } |
@@ -201,30 +192,30 @@ add_to_keyword_counter (void *cls, const char *keyword, int is_mandatory) | |||
201 | * @return 0 to continue extracting / iterating | 192 | * @return 0 to continue extracting / iterating |
202 | */ | 193 | */ |
203 | static int | 194 | static int |
204 | add_to_meta_counter (void *cls, const char *plugin_name, | 195 | add_to_meta_counter(void *cls, const char *plugin_name, |
205 | enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, | 196 | enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, |
206 | const char *data_mime_type, const char *data, size_t data_len) | 197 | const char *data_mime_type, const char *data, size_t data_len) |
207 | { | 198 | { |
208 | struct GNUNET_CONTAINER_MultiHashMap *map = cls; | 199 | struct GNUNET_CONTAINER_MultiHashMap *map = cls; |
209 | struct GNUNET_HashCode key; | 200 | struct GNUNET_HashCode key; |
210 | struct MetaCounter *cnt; | 201 | struct MetaCounter *cnt; |
211 | 202 | ||
212 | GNUNET_CRYPTO_hash (data, data_len, &key); | 203 | GNUNET_CRYPTO_hash(data, data_len, &key); |
213 | cnt = GNUNET_CONTAINER_multihashmap_get (map, &key); | 204 | cnt = GNUNET_CONTAINER_multihashmap_get(map, &key); |
214 | if (NULL == cnt) | 205 | if (NULL == cnt) |
215 | { | 206 | { |
216 | cnt = GNUNET_new (struct MetaCounter); | 207 | cnt = GNUNET_new(struct MetaCounter); |
217 | cnt->data = data; | 208 | cnt->data = data; |
218 | cnt->data_size = data_len; | 209 | cnt->data_size = data_len; |
219 | cnt->plugin_name = plugin_name; | 210 | cnt->plugin_name = plugin_name; |
220 | cnt->type = type; | 211 | cnt->type = type; |
221 | cnt->format = format; | 212 | cnt->format = format; |
222 | cnt->data_mime_type = data_mime_type; | 213 | cnt->data_mime_type = data_mime_type; |
223 | GNUNET_assert (GNUNET_OK == | 214 | GNUNET_assert(GNUNET_OK == |
224 | GNUNET_CONTAINER_multihashmap_put (map, | 215 | GNUNET_CONTAINER_multihashmap_put(map, |
225 | &key, cnt, | 216 | &key, cnt, |
226 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 217 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
227 | } | 218 | } |
228 | cnt->count++; | 219 | cnt->count++; |
229 | return 0; | 220 | return 0; |
230 | } | 221 | } |
@@ -239,21 +230,21 @@ add_to_meta_counter (void *cls, const char *plugin_name, | |||
239 | * @return always GNUNET_OK | 230 | * @return always GNUNET_OK |
240 | */ | 231 | */ |
241 | static int | 232 | static int |
242 | remove_high_frequency_keywords (void *cls, const char *keyword, int is_mandatory) | 233 | remove_high_frequency_keywords(void *cls, const char *keyword, int is_mandatory) |
243 | { | 234 | { |
244 | struct TrimContext *tc = cls; | 235 | struct TrimContext *tc = cls; |
245 | struct KeywordCounter *counter; | 236 | struct KeywordCounter *counter; |
246 | struct GNUNET_HashCode hc; | 237 | struct GNUNET_HashCode hc; |
247 | size_t klen; | 238 | size_t klen; |
248 | 239 | ||
249 | klen = strlen (keyword) + 1; | 240 | klen = strlen(keyword) + 1; |
250 | GNUNET_CRYPTO_hash (keyword, klen - 1, &hc); | 241 | GNUNET_CRYPTO_hash(keyword, klen - 1, &hc); |
251 | counter = GNUNET_CONTAINER_multihashmap_get (tc->keywordcounter, &hc); | 242 | counter = GNUNET_CONTAINER_multihashmap_get(tc->keywordcounter, &hc); |
252 | GNUNET_assert (NULL != counter); | 243 | GNUNET_assert(NULL != counter); |
253 | if (counter->count < tc->move_threshold) | 244 | if (counter->count < tc->move_threshold) |
254 | return GNUNET_OK; | 245 | return GNUNET_OK; |
255 | GNUNET_FS_uri_ksk_remove_keyword (tc->pos->ksk_uri, | 246 | GNUNET_FS_uri_ksk_remove_keyword(tc->pos->ksk_uri, |
256 | counter->value); | 247 | counter->value); |
257 | return GNUNET_OK; | 248 | return GNUNET_OK; |
258 | } | 249 | } |
259 | 250 | ||
@@ -268,23 +259,23 @@ remove_high_frequency_keywords (void *cls, const char *keyword, int is_mandatory | |||
268 | * @return GNUNET_YES (always) | 259 | * @return GNUNET_YES (always) |
269 | */ | 260 | */ |
270 | static int | 261 | static int |
271 | migrate_and_drop_keywords (void *cls, const struct GNUNET_HashCode * key, void *value) | 262 | migrate_and_drop_keywords(void *cls, const struct GNUNET_HashCode * key, void *value) |
272 | { | 263 | { |
273 | struct TrimContext *tc = cls; | 264 | struct TrimContext *tc = cls; |
274 | struct KeywordCounter *counter = value; | 265 | struct KeywordCounter *counter = value; |
275 | 266 | ||
276 | if (counter->count >= tc->move_threshold) | 267 | if (counter->count >= tc->move_threshold) |
277 | { | 268 | { |
278 | if (NULL == tc->pos->ksk_uri) | 269 | if (NULL == tc->pos->ksk_uri) |
279 | tc->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &counter->value); | 270 | tc->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_args(1, &counter->value); |
280 | else | 271 | else |
281 | GNUNET_FS_uri_ksk_add_keyword (tc->pos->ksk_uri, counter->value, GNUNET_NO); | 272 | GNUNET_FS_uri_ksk_add_keyword(tc->pos->ksk_uri, counter->value, GNUNET_NO); |
282 | } | 273 | } |
283 | GNUNET_assert (GNUNET_YES == | 274 | GNUNET_assert(GNUNET_YES == |
284 | GNUNET_CONTAINER_multihashmap_remove (tc->keywordcounter, | 275 | GNUNET_CONTAINER_multihashmap_remove(tc->keywordcounter, |
285 | key, | 276 | key, |
286 | counter)); | 277 | counter)); |
287 | GNUNET_free (counter); | 278 | GNUNET_free(counter); |
288 | return GNUNET_YES; | 279 | return GNUNET_YES; |
289 | } | 280 | } |
290 | 281 | ||
@@ -299,27 +290,27 @@ migrate_and_drop_keywords (void *cls, const struct GNUNET_HashCode * key, void * | |||
299 | * @return GNUNET_YES (always) | 290 | * @return GNUNET_YES (always) |
300 | */ | 291 | */ |
301 | static int | 292 | static int |
302 | migrate_and_drop_metadata (void *cls, const struct GNUNET_HashCode * key, void *value) | 293 | migrate_and_drop_metadata(void *cls, const struct GNUNET_HashCode * key, void *value) |
303 | { | 294 | { |
304 | struct TrimContext *tc = cls; | 295 | struct TrimContext *tc = cls; |
305 | struct MetaCounter *counter = value; | 296 | struct MetaCounter *counter = value; |
306 | 297 | ||
307 | if (counter->count >= tc->move_threshold) | 298 | if (counter->count >= tc->move_threshold) |
308 | { | 299 | { |
309 | if (NULL == tc->pos->meta) | 300 | if (NULL == tc->pos->meta) |
310 | tc->pos->meta = GNUNET_CONTAINER_meta_data_create (); | 301 | tc->pos->meta = GNUNET_CONTAINER_meta_data_create(); |
311 | GNUNET_CONTAINER_meta_data_insert (tc->pos->meta, | 302 | GNUNET_CONTAINER_meta_data_insert(tc->pos->meta, |
312 | counter->plugin_name, | 303 | counter->plugin_name, |
313 | counter->type, | 304 | counter->type, |
314 | counter->format, | 305 | counter->format, |
315 | counter->data_mime_type, counter->data, | 306 | counter->data_mime_type, counter->data, |
316 | counter->data_size); | 307 | counter->data_size); |
317 | } | 308 | } |
318 | GNUNET_assert (GNUNET_YES == | 309 | GNUNET_assert(GNUNET_YES == |
319 | GNUNET_CONTAINER_multihashmap_remove (tc->metacounter, | 310 | GNUNET_CONTAINER_multihashmap_remove(tc->metacounter, |
320 | key, | 311 | key, |
321 | counter)); | 312 | counter)); |
322 | GNUNET_free (counter); | 313 | GNUNET_free(counter); |
323 | return GNUNET_YES; | 314 | return GNUNET_YES; |
324 | } | 315 | } |
325 | 316 | ||
@@ -332,8 +323,8 @@ migrate_and_drop_metadata (void *cls, const struct GNUNET_HashCode * key, void * | |||
332 | * @param tree tree to trim | 323 | * @param tree tree to trim |
333 | */ | 324 | */ |
334 | static void | 325 | static void |
335 | share_tree_trim (struct TrimContext *tc, | 326 | share_tree_trim(struct TrimContext *tc, |
336 | struct GNUNET_FS_ShareTreeItem *tree) | 327 | struct GNUNET_FS_ShareTreeItem *tree) |
337 | { | 328 | { |
338 | struct GNUNET_FS_ShareTreeItem *pos; | 329 | struct GNUNET_FS_ShareTreeItem *pos; |
339 | unsigned int num_children; | 330 | unsigned int num_children; |
@@ -341,64 +332,64 @@ share_tree_trim (struct TrimContext *tc, | |||
341 | /* first, trim all children */ | 332 | /* first, trim all children */ |
342 | num_children = 0; | 333 | num_children = 0; |
343 | for (pos = tree->children_head; NULL != pos; pos = pos->next) | 334 | for (pos = tree->children_head; NULL != pos; pos = pos->next) |
344 | { | 335 | { |
345 | share_tree_trim (tc, pos); | 336 | share_tree_trim(tc, pos); |
346 | num_children++; | 337 | num_children++; |
347 | } | 338 | } |
348 | 339 | ||
349 | /* consider adding filename to directory meta data */ | 340 | /* consider adding filename to directory meta data */ |
350 | if (tree->is_directory == GNUNET_YES) | 341 | if (tree->is_directory == GNUNET_YES) |
351 | { | ||
352 | const char *user = getenv ("USER"); | ||
353 | if ( (user == NULL) || | ||
354 | (0 != strncasecmp (user, tree->short_filename, strlen(user)))) | ||
355 | { | 342 | { |
356 | /* only use filename if it doesn't match $USER */ | 343 | const char *user = getenv("USER"); |
357 | if (NULL == tree->meta) | 344 | if ((user == NULL) || |
358 | tree->meta = GNUNET_CONTAINER_meta_data_create (); | 345 | (0 != strncasecmp(user, tree->short_filename, strlen(user)))) |
359 | GNUNET_CONTAINER_meta_data_insert (tree->meta, "<libgnunetfs>", | 346 | { |
360 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | 347 | /* only use filename if it doesn't match $USER */ |
361 | EXTRACTOR_METAFORMAT_UTF8, | 348 | if (NULL == tree->meta) |
362 | "text/plain", tree->short_filename, | 349 | tree->meta = GNUNET_CONTAINER_meta_data_create(); |
363 | strlen (tree->short_filename) + 1); | 350 | GNUNET_CONTAINER_meta_data_insert(tree->meta, "<libgnunetfs>", |
351 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
352 | EXTRACTOR_METAFORMAT_UTF8, | ||
353 | "text/plain", tree->short_filename, | ||
354 | strlen(tree->short_filename) + 1); | ||
355 | } | ||
364 | } | 356 | } |
365 | } | ||
366 | 357 | ||
367 | if (1 >= num_children) | 358 | if (1 >= num_children) |
368 | return; /* nothing to trim */ | 359 | return; /* nothing to trim */ |
369 | 360 | ||
370 | /* now, count keywords and meta data in children */ | 361 | /* now, count keywords and meta data in children */ |
371 | for (pos = tree->children_head; NULL != pos; pos = pos->next) | 362 | for (pos = tree->children_head; NULL != pos; pos = pos->next) |
372 | { | 363 | { |
373 | if (NULL != pos->meta) | 364 | if (NULL != pos->meta) |
374 | GNUNET_CONTAINER_meta_data_iterate (pos->meta, &add_to_meta_counter, tc->metacounter); | 365 | GNUNET_CONTAINER_meta_data_iterate(pos->meta, &add_to_meta_counter, tc->metacounter); |
375 | if (NULL != pos->ksk_uri) | 366 | if (NULL != pos->ksk_uri) |
376 | GNUNET_FS_uri_ksk_get_keywords (pos->ksk_uri, &add_to_keyword_counter, tc->keywordcounter); | 367 | GNUNET_FS_uri_ksk_get_keywords(pos->ksk_uri, &add_to_keyword_counter, tc->keywordcounter); |
377 | } | 368 | } |
378 | 369 | ||
379 | /* calculate threshold for moving keywords / meta data */ | 370 | /* calculate threshold for moving keywords / meta data */ |
380 | tc->move_threshold = 1 + (num_children / 2); | 371 | tc->move_threshold = 1 + (num_children / 2); |
381 | 372 | ||
382 | /* remove high-frequency keywords from children */ | 373 | /* remove high-frequency keywords from children */ |
383 | for (pos = tree->children_head; NULL != pos; pos = pos->next) | 374 | for (pos = tree->children_head; NULL != pos; pos = pos->next) |
384 | { | ||
385 | tc->pos = pos; | ||
386 | if (NULL != pos->ksk_uri) | ||
387 | { | 375 | { |
388 | struct GNUNET_FS_Uri *ksk_uri_copy = GNUNET_FS_uri_dup (pos->ksk_uri); | 376 | tc->pos = pos; |
389 | GNUNET_FS_uri_ksk_get_keywords (ksk_uri_copy, &remove_high_frequency_keywords, tc); | 377 | if (NULL != pos->ksk_uri) |
390 | GNUNET_FS_uri_destroy (ksk_uri_copy); | 378 | { |
379 | struct GNUNET_FS_Uri *ksk_uri_copy = GNUNET_FS_uri_dup(pos->ksk_uri); | ||
380 | GNUNET_FS_uri_ksk_get_keywords(ksk_uri_copy, &remove_high_frequency_keywords, tc); | ||
381 | GNUNET_FS_uri_destroy(ksk_uri_copy); | ||
382 | } | ||
391 | } | 383 | } |
392 | } | ||
393 | 384 | ||
394 | /* add high-frequency meta data and keywords to parent */ | 385 | /* add high-frequency meta data and keywords to parent */ |
395 | tc->pos = tree; | 386 | tc->pos = tree; |
396 | GNUNET_CONTAINER_multihashmap_iterate (tc->keywordcounter, | 387 | GNUNET_CONTAINER_multihashmap_iterate(tc->keywordcounter, |
397 | &migrate_and_drop_keywords, | 388 | &migrate_and_drop_keywords, |
398 | tc); | 389 | tc); |
399 | GNUNET_CONTAINER_multihashmap_iterate (tc->metacounter, | 390 | GNUNET_CONTAINER_multihashmap_iterate(tc->metacounter, |
400 | &migrate_and_drop_metadata, | 391 | &migrate_and_drop_metadata, |
401 | tc); | 392 | tc); |
402 | } | 393 | } |
403 | 394 | ||
404 | 395 | ||
@@ -409,17 +400,17 @@ share_tree_trim (struct TrimContext *tc, | |||
409 | * @param toplevel toplevel directory in the tree, returned by the scanner | 400 | * @param toplevel toplevel directory in the tree, returned by the scanner |
410 | */ | 401 | */ |
411 | void | 402 | void |
412 | GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel) | 403 | GNUNET_FS_share_tree_trim(struct GNUNET_FS_ShareTreeItem *toplevel) |
413 | { | 404 | { |
414 | struct TrimContext tc; | 405 | struct TrimContext tc; |
415 | 406 | ||
416 | if (toplevel == NULL) | 407 | if (toplevel == NULL) |
417 | return; | 408 | return; |
418 | tc.keywordcounter = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); | 409 | tc.keywordcounter = GNUNET_CONTAINER_multihashmap_create(1024, GNUNET_NO); |
419 | tc.metacounter = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); | 410 | tc.metacounter = GNUNET_CONTAINER_multihashmap_create(1024, GNUNET_NO); |
420 | share_tree_trim (&tc, toplevel); | 411 | share_tree_trim(&tc, toplevel); |
421 | GNUNET_CONTAINER_multihashmap_destroy (tc.keywordcounter); | 412 | GNUNET_CONTAINER_multihashmap_destroy(tc.keywordcounter); |
422 | GNUNET_CONTAINER_multihashmap_destroy (tc.metacounter); | 413 | GNUNET_CONTAINER_multihashmap_destroy(tc.metacounter); |
423 | } | 414 | } |
424 | 415 | ||
425 | 416 | ||
@@ -429,23 +420,23 @@ GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel) | |||
429 | * @param toplevel toplevel of the tree to be freed | 420 | * @param toplevel toplevel of the tree to be freed |
430 | */ | 421 | */ |
431 | void | 422 | void |
432 | GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel) | 423 | GNUNET_FS_share_tree_free(struct GNUNET_FS_ShareTreeItem *toplevel) |
433 | { | 424 | { |
434 | struct GNUNET_FS_ShareTreeItem *pos; | 425 | struct GNUNET_FS_ShareTreeItem *pos; |
435 | 426 | ||
436 | while (NULL != (pos = toplevel->children_head)) | 427 | while (NULL != (pos = toplevel->children_head)) |
437 | GNUNET_FS_share_tree_free (pos); | 428 | GNUNET_FS_share_tree_free(pos); |
438 | if (NULL != toplevel->parent) | 429 | if (NULL != toplevel->parent) |
439 | GNUNET_CONTAINER_DLL_remove (toplevel->parent->children_head, | 430 | GNUNET_CONTAINER_DLL_remove(toplevel->parent->children_head, |
440 | toplevel->parent->children_tail, | 431 | toplevel->parent->children_tail, |
441 | toplevel); | 432 | toplevel); |
442 | if (NULL != toplevel->meta) | 433 | if (NULL != toplevel->meta) |
443 | GNUNET_CONTAINER_meta_data_destroy (toplevel->meta); | 434 | GNUNET_CONTAINER_meta_data_destroy(toplevel->meta); |
444 | if (NULL != toplevel->ksk_uri) | 435 | if (NULL != toplevel->ksk_uri) |
445 | GNUNET_FS_uri_destroy (toplevel->ksk_uri); | 436 | GNUNET_FS_uri_destroy(toplevel->ksk_uri); |
446 | GNUNET_free_non_null (toplevel->filename); | 437 | GNUNET_free_non_null(toplevel->filename); |
447 | GNUNET_free_non_null (toplevel->short_filename); | 438 | GNUNET_free_non_null(toplevel->short_filename); |
448 | GNUNET_free (toplevel); | 439 | GNUNET_free(toplevel); |
449 | } | 440 | } |
450 | 441 | ||
451 | /* end fs_sharetree.c */ | 442 | /* end fs_sharetree.c */ |
diff --git a/src/fs/fs_test_lib.c b/src/fs/fs_test_lib.c index abbda1ece..e3ab0ec88 100644 --- a/src/fs/fs_test_lib.c +++ b/src/fs/fs_test_lib.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_test_lib.c | 22 | * @file fs/fs_test_lib.c |
@@ -37,9 +37,7 @@ | |||
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 | { | ||
42 | |||
43 | /** | 41 | /** |
44 | * Handle for the operation to connect to the peer's 'fs' service. | 42 | * Handle for the operation to connect to the peer's 'fs' service. |
45 | */ | 43 | */ |
@@ -110,9 +108,7 @@ struct TestPublishOperation | |||
110 | /** | 108 | /** |
111 | * Handle for a download operation started for testing FS. | 109 | * Handle for a download operation started for testing FS. |
112 | */ | 110 | */ |
113 | struct TestDownloadOperation | 111 | struct TestDownloadOperation { |
114 | { | ||
115 | |||
116 | /** | 112 | /** |
117 | * Handle for the operation to connect to the peer's 'fs' service. | 113 | * Handle for the operation to connect to the peer's 'fs' service. |
118 | */ | 114 | */ |
@@ -172,7 +168,6 @@ struct TestDownloadOperation | |||
172 | * Verbosity level of the current operation. | 168 | * Verbosity level of the current operation. |
173 | */ | 169 | */ |
174 | unsigned int verbose; | 170 | unsigned int verbose; |
175 | |||
176 | }; | 171 | }; |
177 | 172 | ||
178 | 173 | ||
@@ -183,23 +178,23 @@ struct TestDownloadOperation | |||
183 | * @param tc scheduler context (unused) | 178 | * @param tc scheduler context (unused) |
184 | */ | 179 | */ |
185 | static void | 180 | static void |
186 | report_uri (void *cls) | 181 | report_uri(void *cls) |
187 | { | 182 | { |
188 | struct TestPublishOperation *po = cls; | 183 | struct TestPublishOperation *po = cls; |
189 | 184 | ||
190 | GNUNET_FS_publish_stop (po->publish_context); | 185 | GNUNET_FS_publish_stop(po->publish_context); |
191 | GNUNET_TESTBED_operation_done (po->fs_op); | 186 | GNUNET_TESTBED_operation_done(po->fs_op); |
192 | po->publish_cont (po->publish_cont_cls, | 187 | po->publish_cont(po->publish_cont_cls, |
193 | po->publish_uri, | 188 | po->publish_uri, |
194 | (GNUNET_YES == po->do_index) | 189 | (GNUNET_YES == po->do_index) |
195 | ? po->publish_tmp_file | 190 | ? po->publish_tmp_file |
196 | : NULL); | 191 | : NULL); |
197 | GNUNET_FS_uri_destroy (po->publish_uri); | 192 | GNUNET_FS_uri_destroy(po->publish_uri); |
198 | if ( (GNUNET_YES != po->do_index) && | 193 | if ((GNUNET_YES != po->do_index) && |
199 | (NULL != po->publish_tmp_file) ) | 194 | (NULL != po->publish_tmp_file)) |
200 | (void) GNUNET_DISK_directory_remove (po->publish_tmp_file); | 195 | (void)GNUNET_DISK_directory_remove(po->publish_tmp_file); |
201 | GNUNET_free_non_null (po->publish_tmp_file); | 196 | GNUNET_free_non_null(po->publish_tmp_file); |
202 | GNUNET_free (po); | 197 | GNUNET_free(po); |
203 | } | 198 | } |
204 | 199 | ||
205 | 200 | ||
@@ -209,19 +204,19 @@ report_uri (void *cls) | |||
209 | * @param cls the publish operation context | 204 | * @param cls the publish operation context |
210 | */ | 205 | */ |
211 | static void | 206 | static void |
212 | publish_timeout (void *cls) | 207 | publish_timeout(void *cls) |
213 | { | 208 | { |
214 | struct TestPublishOperation *po = cls; | 209 | struct TestPublishOperation *po = cls; |
215 | 210 | ||
216 | po->publish_timeout_task = NULL; | 211 | po->publish_timeout_task = NULL; |
217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 212 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
218 | "Timeout while trying to publish data\n"); | 213 | "Timeout while trying to publish data\n"); |
219 | GNUNET_TESTBED_operation_done (po->fs_op); | 214 | GNUNET_TESTBED_operation_done(po->fs_op); |
220 | GNUNET_FS_publish_stop (po->publish_context); | 215 | GNUNET_FS_publish_stop(po->publish_context); |
221 | po->publish_cont (po->publish_cont_cls, NULL, NULL); | 216 | po->publish_cont(po->publish_cont_cls, NULL, NULL); |
222 | (void) GNUNET_DISK_directory_remove (po->publish_tmp_file); | 217 | (void)GNUNET_DISK_directory_remove(po->publish_tmp_file); |
223 | GNUNET_free_non_null (po->publish_tmp_file); | 218 | GNUNET_free_non_null(po->publish_tmp_file); |
224 | GNUNET_free (po); | 219 | GNUNET_free(po); |
225 | } | 220 | } |
226 | 221 | ||
227 | 222 | ||
@@ -232,37 +227,41 @@ publish_timeout (void *cls) | |||
232 | * @param info information about the event | 227 | * @param info information about the event |
233 | */ | 228 | */ |
234 | static void * | 229 | static void * |
235 | publish_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | 230 | publish_progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) |
236 | { | 231 | { |
237 | struct TestPublishOperation *po = cls; | 232 | struct TestPublishOperation *po = cls; |
238 | 233 | ||
239 | switch (info->status) | 234 | switch (info->status) |
240 | { | 235 | { |
241 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 236 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
242 | GNUNET_SCHEDULER_cancel (po->publish_timeout_task); | 237 | GNUNET_SCHEDULER_cancel(po->publish_timeout_task); |
243 | po->publish_timeout_task = NULL; | 238 | po->publish_timeout_task = NULL; |
244 | po->publish_uri = | 239 | po->publish_uri = |
245 | GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri); | 240 | GNUNET_FS_uri_dup(info->value.publish.specifics.completed.chk_uri); |
246 | GNUNET_SCHEDULER_add_now (&report_uri, | 241 | GNUNET_SCHEDULER_add_now(&report_uri, |
247 | po); | 242 | po); |
248 | break; | 243 | break; |
249 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 244 | |
250 | if (po->verbose) | 245 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
251 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n", | 246 | if (po->verbose) |
252 | (unsigned long long) info->value.publish.completed, | 247 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n", |
253 | (unsigned long long) info->value.publish.size); | 248 | (unsigned long long)info->value.publish.completed, |
254 | break; | 249 | (unsigned long long)info->value.publish.size); |
255 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 250 | break; |
256 | break; | 251 | |
257 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 252 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
258 | if (po->verbose) | 253 | break; |
259 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n", | 254 | |
260 | (unsigned long long) info->value.download.completed, | 255 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
261 | (unsigned long long) info->value.download.size); | 256 | if (po->verbose) |
262 | break; | 257 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n", |
263 | default: | 258 | (unsigned long long)info->value.download.completed, |
264 | break; | 259 | (unsigned long long)info->value.download.size); |
265 | } | 260 | break; |
261 | |||
262 | default: | ||
263 | break; | ||
264 | } | ||
266 | return NULL; | 265 | return NULL; |
267 | } | 266 | } |
268 | 267 | ||
@@ -278,11 +277,11 @@ publish_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
278 | * @return number of bytes written to buf | 277 | * @return number of bytes written to buf |
279 | */ | 278 | */ |
280 | static size_t | 279 | static size_t |
281 | file_generator (void *cls, | 280 | file_generator(void *cls, |
282 | uint64_t offset, | 281 | uint64_t offset, |
283 | size_t max, | 282 | size_t max, |
284 | void *buf, | 283 | void *buf, |
285 | char **emsg) | 284 | char **emsg) |
286 | { | 285 | { |
287 | uint32_t *publish_seed = cls; | 286 | uint32_t *publish_seed = cls; |
288 | uint64_t pos; | 287 | uint64_t pos; |
@@ -294,14 +293,14 @@ file_generator (void *cls, | |||
294 | if (buf == NULL) | 293 | if (buf == NULL) |
295 | return 0; | 294 | return 0; |
296 | for (pos = 0; pos < 8; pos++) | 295 | for (pos = 0; pos < 8; pos++) |
297 | cbuf[pos] = (uint8_t) (offset >> pos * 8); | 296 | cbuf[pos] = (uint8_t)(offset >> pos * 8); |
298 | for (pos = 8; pos < max; pos++) | 297 | for (pos = 8; pos < max; pos++) |
299 | { | 298 | { |
300 | mod = (255 - (offset / 1024 / 32)); | 299 | mod = (255 - (offset / 1024 / 32)); |
301 | if (mod == 0) | 300 | if (mod == 0) |
302 | mod = 1; | 301 | mod = 1; |
303 | cbuf[pos] = (uint8_t) ((offset * (*publish_seed)) % mod); | 302 | cbuf[pos] = (uint8_t)((offset * (*publish_seed)) % mod); |
304 | } | 303 | } |
305 | return max; | 304 | return max; |
306 | } | 305 | } |
307 | 306 | ||
@@ -316,16 +315,16 @@ file_generator (void *cls, | |||
316 | * @return service handle to return in 'op_result', NULL on error | 315 | * @return service handle to return in 'op_result', NULL on error |
317 | */ | 316 | */ |
318 | static void * | 317 | static void * |
319 | publish_connect_adapter (void *cls, | 318 | publish_connect_adapter(void *cls, |
320 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 319 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
321 | { | 320 | { |
322 | struct TestPublishOperation *po = cls; | 321 | struct TestPublishOperation *po = cls; |
323 | 322 | ||
324 | return GNUNET_FS_start (cfg, | 323 | return GNUNET_FS_start(cfg, |
325 | "fs-test-publish", | 324 | "fs-test-publish", |
326 | &publish_progress_cb, po, | 325 | &publish_progress_cb, po, |
327 | GNUNET_FS_FLAGS_NONE, | 326 | GNUNET_FS_FLAGS_NONE, |
328 | GNUNET_FS_OPTIONS_END); | 327 | GNUNET_FS_OPTIONS_END); |
329 | } | 328 | } |
330 | 329 | ||
331 | 330 | ||
@@ -336,12 +335,12 @@ publish_connect_adapter (void *cls, | |||
336 | * @param op_result unused (different for publish/download!) | 335 | * @param op_result unused (different for publish/download!) |
337 | */ | 336 | */ |
338 | static void | 337 | static void |
339 | fs_disconnect_adapter (void *cls, | 338 | fs_disconnect_adapter(void *cls, |
340 | void *op_result) | 339 | void *op_result) |
341 | { | 340 | { |
342 | struct GNUNET_FS_Handle *fs = op_result; | 341 | struct GNUNET_FS_Handle *fs = op_result; |
343 | 342 | ||
344 | GNUNET_FS_stop (fs); | 343 | GNUNET_FS_stop(fs); |
345 | } | 344 | } |
346 | 345 | ||
347 | 346 | ||
@@ -355,10 +354,10 @@ fs_disconnect_adapter (void *cls, | |||
355 | * operation has executed successfully. | 354 | * operation has executed successfully. |
356 | */ | 355 | */ |
357 | static void | 356 | static void |
358 | publish_fs_connect_complete_cb (void *cls, | 357 | publish_fs_connect_complete_cb(void *cls, |
359 | struct GNUNET_TESTBED_Operation *op, | 358 | struct GNUNET_TESTBED_Operation *op, |
360 | void *ca_result, | 359 | void *ca_result, |
361 | const char *emsg) | 360 | const char *emsg) |
362 | { | 361 | { |
363 | struct TestPublishOperation *po = cls; | 362 | struct TestPublishOperation *po = cls; |
364 | struct GNUNET_FS_FileInformation *fi; | 363 | struct GNUNET_FS_FileInformation *fi; |
@@ -371,58 +370,58 @@ publish_fs_connect_complete_cb (void *cls, | |||
371 | 370 | ||
372 | if (NULL == ca_result) | 371 | if (NULL == ca_result) |
373 | { | 372 | { |
374 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect to FS for publishing: %s\n", emsg); | 373 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to FS for publishing: %s\n", emsg); |
375 | po->publish_cont (po->publish_cont_cls, | 374 | po->publish_cont(po->publish_cont_cls, |
376 | NULL, NULL); | 375 | NULL, NULL); |
377 | GNUNET_TESTBED_operation_done (po->fs_op); | 376 | GNUNET_TESTBED_operation_done(po->fs_op); |
378 | GNUNET_free (po); | 377 | GNUNET_free(po); |
379 | return; | 378 | return; |
380 | } | 379 | } |
381 | po->fs = ca_result; | 380 | po->fs = ca_result; |
382 | 381 | ||
383 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (CONTENT_LIFETIME); | 382 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(CONTENT_LIFETIME); |
384 | bo.anonymity_level = po->anonymity; | 383 | bo.anonymity_level = po->anonymity; |
385 | bo.content_priority = 42; | 384 | bo.content_priority = 42; |
386 | bo.replication_level = 1; | 385 | bo.replication_level = 1; |
387 | if (GNUNET_YES == po->do_index) | 386 | if (GNUNET_YES == po->do_index) |
388 | { | ||
389 | po->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index"); | ||
390 | GNUNET_assert (po->publish_tmp_file != NULL); | ||
391 | fh = GNUNET_DISK_file_open (po->publish_tmp_file, | ||
392 | GNUNET_DISK_OPEN_WRITE | | ||
393 | GNUNET_DISK_OPEN_CREATE, | ||
394 | GNUNET_DISK_PERM_USER_READ | | ||
395 | GNUNET_DISK_PERM_USER_WRITE); | ||
396 | GNUNET_assert (NULL != fh); | ||
397 | off = 0; | ||
398 | while (off < po->size) | ||
399 | { | 387 | { |
400 | bsize = GNUNET_MIN (sizeof (buf), po->size - off); | 388 | po->publish_tmp_file = GNUNET_DISK_mktemp("fs-test-publish-index"); |
401 | emsg = NULL; | 389 | GNUNET_assert(po->publish_tmp_file != NULL); |
402 | GNUNET_assert (bsize == file_generator (&po->publish_seed, off, bsize, buf, &em)); | 390 | fh = GNUNET_DISK_file_open(po->publish_tmp_file, |
403 | GNUNET_assert (em == NULL); | 391 | GNUNET_DISK_OPEN_WRITE | |
404 | GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize)); | 392 | GNUNET_DISK_OPEN_CREATE, |
405 | off += bsize; | 393 | GNUNET_DISK_PERM_USER_READ | |
394 | GNUNET_DISK_PERM_USER_WRITE); | ||
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); | ||
406 | } | 412 | } |
407 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); | ||
408 | fi = GNUNET_FS_file_information_create_from_file (po->fs, po, | ||
409 | po->publish_tmp_file, | ||
410 | NULL, NULL, po->do_index, | ||
411 | &bo); | ||
412 | GNUNET_assert (NULL != fi); | ||
413 | } | ||
414 | else | 413 | else |
415 | { | 414 | { |
416 | fi = GNUNET_FS_file_information_create_from_reader (po->fs, po, | 415 | fi = GNUNET_FS_file_information_create_from_reader(po->fs, po, |
417 | po->size, | 416 | po->size, |
418 | &file_generator, &po->publish_seed, | 417 | &file_generator, &po->publish_seed, |
419 | NULL, NULL, | 418 | NULL, NULL, |
420 | po->do_index, &bo); | 419 | po->do_index, &bo); |
421 | GNUNET_assert (NULL != fi); | 420 | GNUNET_assert(NULL != fi); |
422 | } | 421 | } |
423 | po->publish_context = | 422 | po->publish_context = |
424 | GNUNET_FS_publish_start (po->fs, fi, NULL, NULL, NULL, | 423 | GNUNET_FS_publish_start(po->fs, fi, NULL, NULL, NULL, |
425 | GNUNET_FS_PUBLISH_OPTION_NONE); | 424 | GNUNET_FS_PUBLISH_OPTION_NONE); |
426 | } | 425 | } |
427 | 426 | ||
428 | 427 | ||
@@ -442,15 +441,15 @@ publish_fs_connect_complete_cb (void *cls, | |||
442 | * @param cont_cls closure for cont | 441 | * @param cont_cls closure for cont |
443 | */ | 442 | */ |
444 | void | 443 | void |
445 | GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, | 444 | GNUNET_FS_TEST_publish(struct GNUNET_TESTBED_Peer *peer, |
446 | struct GNUNET_TIME_Relative timeout, uint32_t anonymity, | 445 | struct GNUNET_TIME_Relative timeout, uint32_t anonymity, |
447 | int do_index, uint64_t size, uint32_t seed, | 446 | int do_index, uint64_t size, uint32_t seed, |
448 | unsigned int verbose, | 447 | unsigned int verbose, |
449 | GNUNET_FS_TEST_UriContinuation cont, void *cont_cls) | 448 | GNUNET_FS_TEST_UriContinuation cont, void *cont_cls) |
450 | { | 449 | { |
451 | struct TestPublishOperation *po; | 450 | struct TestPublishOperation *po; |
452 | 451 | ||
453 | po = GNUNET_new (struct TestPublishOperation); | 452 | po = GNUNET_new(struct TestPublishOperation); |
454 | po->publish_cont = cont; | 453 | po->publish_cont = cont; |
455 | po->publish_cont_cls = cont_cls; | 454 | po->publish_cont_cls = cont_cls; |
456 | po->publish_seed = seed; | 455 | po->publish_seed = seed; |
@@ -458,16 +457,16 @@ GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, | |||
458 | po->size = size; | 457 | po->size = size; |
459 | po->verbose = verbose; | 458 | po->verbose = verbose; |
460 | po->do_index = do_index; | 459 | po->do_index = do_index; |
461 | po->fs_op = GNUNET_TESTBED_service_connect (po, | 460 | po->fs_op = GNUNET_TESTBED_service_connect(po, |
462 | peer, | 461 | peer, |
463 | "fs", | 462 | "fs", |
464 | &publish_fs_connect_complete_cb, | 463 | &publish_fs_connect_complete_cb, |
465 | po, | 464 | po, |
466 | &publish_connect_adapter, | 465 | &publish_connect_adapter, |
467 | &fs_disconnect_adapter, | 466 | &fs_disconnect_adapter, |
468 | po); | 467 | po); |
469 | po->publish_timeout_task = | 468 | po->publish_timeout_task = |
470 | GNUNET_SCHEDULER_add_delayed (timeout, &publish_timeout, po); | 469 | GNUNET_SCHEDULER_add_delayed(timeout, &publish_timeout, po); |
471 | } | 470 | } |
472 | 471 | ||
473 | 472 | ||
@@ -480,20 +479,20 @@ GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, | |||
480 | * @param cls the download operation context | 479 | * @param cls the download operation context |
481 | */ | 480 | */ |
482 | static void | 481 | static void |
483 | download_timeout (void *cls) | 482 | download_timeout(void *cls) |
484 | { | 483 | { |
485 | struct TestDownloadOperation *dop = cls; | 484 | struct TestDownloadOperation *dop = cls; |
486 | 485 | ||
487 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 486 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
488 | "Timeout while trying to download file\n"); | 487 | "Timeout while trying to download file\n"); |
489 | dop->download_timeout_task = NULL; | 488 | dop->download_timeout_task = NULL; |
490 | GNUNET_FS_download_stop (dop->download_context, | 489 | GNUNET_FS_download_stop(dop->download_context, |
491 | GNUNET_YES); | 490 | GNUNET_YES); |
492 | GNUNET_SCHEDULER_add_now (dop->download_cont, | 491 | GNUNET_SCHEDULER_add_now(dop->download_cont, |
493 | dop->download_cont_cls); | 492 | dop->download_cont_cls); |
494 | GNUNET_TESTBED_operation_done (dop->fs_op); | 493 | GNUNET_TESTBED_operation_done(dop->fs_op); |
495 | GNUNET_FS_uri_destroy (dop->uri); | 494 | GNUNET_FS_uri_destroy(dop->uri); |
496 | GNUNET_free (dop); | 495 | GNUNET_free(dop); |
497 | } | 496 | } |
498 | 497 | ||
499 | 498 | ||
@@ -503,17 +502,17 @@ download_timeout (void *cls) | |||
503 | * @param cls the download operation context | 502 | * @param cls the download operation context |
504 | */ | 503 | */ |
505 | static void | 504 | static void |
506 | report_success (void *cls) | 505 | report_success(void *cls) |
507 | { | 506 | { |
508 | struct TestDownloadOperation *dop = cls; | 507 | struct TestDownloadOperation *dop = cls; |
509 | 508 | ||
510 | GNUNET_FS_download_stop (dop->download_context, | 509 | GNUNET_FS_download_stop(dop->download_context, |
511 | GNUNET_YES); | 510 | GNUNET_YES); |
512 | GNUNET_SCHEDULER_add_now (dop->download_cont, | 511 | GNUNET_SCHEDULER_add_now(dop->download_cont, |
513 | dop->download_cont_cls); | 512 | dop->download_cont_cls); |
514 | GNUNET_TESTBED_operation_done (dop->fs_op); | 513 | GNUNET_TESTBED_operation_done(dop->fs_op); |
515 | GNUNET_FS_uri_destroy (dop->uri); | 514 | GNUNET_FS_uri_destroy(dop->uri); |
516 | GNUNET_free (dop); | 515 | GNUNET_free(dop); |
517 | } | 516 | } |
518 | 517 | ||
519 | 518 | ||
@@ -524,34 +523,37 @@ report_success (void *cls) | |||
524 | * @param info information about the event | 523 | * @param info information about the event |
525 | */ | 524 | */ |
526 | static void * | 525 | static void * |
527 | download_progress_cb (void *cls, | 526 | download_progress_cb(void *cls, |
528 | const struct GNUNET_FS_ProgressInfo *info) | 527 | const struct GNUNET_FS_ProgressInfo *info) |
529 | { | 528 | { |
530 | struct TestDownloadOperation *dop = cls; | 529 | struct TestDownloadOperation *dop = cls; |
531 | 530 | ||
532 | switch (info->status) | 531 | switch (info->status) |
533 | { | 532 | { |
534 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 533 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
535 | if (dop->verbose) | 534 | if (dop->verbose) |
536 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 535 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
537 | "Download at %llu/%llu bytes\n", | 536 | "Download at %llu/%llu bytes\n", |
538 | (unsigned long long) info->value.download.completed, | 537 | (unsigned long long)info->value.download.completed, |
539 | (unsigned long long) info->value.download.size); | 538 | (unsigned long long)info->value.download.size); |
540 | break; | 539 | break; |
541 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 540 | |
542 | GNUNET_SCHEDULER_cancel (dop->download_timeout_task); | 541 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
543 | dop->download_timeout_task = NULL; | 542 | GNUNET_SCHEDULER_cancel(dop->download_timeout_task); |
544 | GNUNET_SCHEDULER_add_now (&report_success, dop); | 543 | dop->download_timeout_task = NULL; |
545 | break; | 544 | GNUNET_SCHEDULER_add_now(&report_success, dop); |
546 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | 545 | break; |
547 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | 546 | |
548 | break; | 547 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: |
548 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | ||
549 | break; | ||
550 | |||
549 | /* FIXME: monitor data correctness during download progress */ | 551 | /* FIXME: monitor data correctness during download progress */ |
550 | /* FIXME: do performance reports given sufficient verbosity */ | 552 | /* FIXME: do performance reports given sufficient verbosity */ |
551 | /* FIXME: advance timeout task to "immediate" on error */ | 553 | /* FIXME: advance timeout task to "immediate" on error */ |
552 | default: | 554 | default: |
553 | break; | 555 | break; |
554 | } | 556 | } |
555 | return NULL; | 557 | return NULL; |
556 | } | 558 | } |
557 | 559 | ||
@@ -566,16 +568,16 @@ download_progress_cb (void *cls, | |||
566 | * @return service handle to return in 'op_result', NULL on error | 568 | * @return service handle to return in 'op_result', NULL on error |
567 | */ | 569 | */ |
568 | static void * | 570 | static void * |
569 | download_connect_adapter (void *cls, | 571 | download_connect_adapter(void *cls, |
570 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 572 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
571 | { | 573 | { |
572 | struct TestPublishOperation *po = cls; | 574 | struct TestPublishOperation *po = cls; |
573 | 575 | ||
574 | return GNUNET_FS_start (cfg, | 576 | return GNUNET_FS_start(cfg, |
575 | "fs-test-download", | 577 | "fs-test-download", |
576 | &download_progress_cb, po, | 578 | &download_progress_cb, po, |
577 | GNUNET_FS_FLAGS_NONE, | 579 | GNUNET_FS_FLAGS_NONE, |
578 | GNUNET_FS_OPTIONS_END); | 580 | GNUNET_FS_OPTIONS_END); |
579 | } | 581 | } |
580 | 582 | ||
581 | 583 | ||
@@ -589,19 +591,19 @@ download_connect_adapter (void *cls, | |||
589 | * operation has executed successfully. | 591 | * operation has executed successfully. |
590 | */ | 592 | */ |
591 | static void | 593 | static void |
592 | download_fs_connect_complete_cb (void *cls, | 594 | download_fs_connect_complete_cb(void *cls, |
593 | struct GNUNET_TESTBED_Operation *op, | 595 | struct GNUNET_TESTBED_Operation *op, |
594 | void *ca_result, | 596 | void *ca_result, |
595 | const char *emsg) | 597 | const char *emsg) |
596 | { | 598 | { |
597 | struct TestDownloadOperation *dop = cls; | 599 | struct TestDownloadOperation *dop = cls; |
598 | 600 | ||
599 | dop->fs = ca_result; | 601 | dop->fs = ca_result; |
600 | GNUNET_assert (NULL != dop->fs); | 602 | GNUNET_assert(NULL != dop->fs); |
601 | dop->download_context = | 603 | dop->download_context = |
602 | GNUNET_FS_download_start (dop->fs, dop->uri, NULL, NULL, NULL, 0, dop->size, | 604 | GNUNET_FS_download_start(dop->fs, dop->uri, NULL, NULL, NULL, 0, dop->size, |
603 | dop->anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE, | 605 | dop->anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE, |
604 | NULL, NULL); | 606 | NULL, NULL); |
605 | } | 607 | } |
606 | 608 | ||
607 | 609 | ||
@@ -619,33 +621,33 @@ download_fs_connect_complete_cb (void *cls, | |||
619 | * @param cont_cls closure for cont | 621 | * @param cont_cls closure for cont |
620 | */ | 622 | */ |
621 | void | 623 | void |
622 | GNUNET_FS_TEST_download (struct GNUNET_TESTBED_Peer *peer, | 624 | GNUNET_FS_TEST_download(struct GNUNET_TESTBED_Peer *peer, |
623 | struct GNUNET_TIME_Relative timeout, | 625 | struct GNUNET_TIME_Relative timeout, |
624 | uint32_t anonymity, uint32_t seed, | 626 | uint32_t anonymity, uint32_t seed, |
625 | const struct GNUNET_FS_Uri *uri, unsigned int verbose, | 627 | const struct GNUNET_FS_Uri *uri, unsigned int verbose, |
626 | GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) | 628 | GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) |
627 | { | 629 | { |
628 | struct TestDownloadOperation *dop; | 630 | struct TestDownloadOperation *dop; |
629 | 631 | ||
630 | dop = GNUNET_new (struct TestDownloadOperation); | 632 | dop = GNUNET_new(struct TestDownloadOperation); |
631 | dop->uri = GNUNET_FS_uri_dup (uri); | 633 | dop->uri = GNUNET_FS_uri_dup(uri); |
632 | dop->size = GNUNET_FS_uri_chk_get_file_size (uri); | 634 | dop->size = GNUNET_FS_uri_chk_get_file_size(uri); |
633 | dop->verbose = verbose; | 635 | dop->verbose = verbose; |
634 | dop->anonymity = anonymity; | 636 | dop->anonymity = anonymity; |
635 | dop->download_cont = cont; | 637 | dop->download_cont = cont; |
636 | dop->download_cont_cls = cont_cls; | 638 | dop->download_cont_cls = cont_cls; |
637 | dop->download_seed = seed; | 639 | dop->download_seed = seed; |
638 | 640 | ||
639 | dop->fs_op = GNUNET_TESTBED_service_connect (dop, | 641 | dop->fs_op = GNUNET_TESTBED_service_connect(dop, |
640 | peer, | 642 | peer, |
641 | "fs", | 643 | "fs", |
642 | &download_fs_connect_complete_cb, | 644 | &download_fs_connect_complete_cb, |
643 | dop, | 645 | dop, |
644 | &download_connect_adapter, | 646 | &download_connect_adapter, |
645 | &fs_disconnect_adapter, | 647 | &fs_disconnect_adapter, |
646 | dop); | 648 | dop); |
647 | dop->download_timeout_task = | 649 | dop->download_timeout_task = |
648 | GNUNET_SCHEDULER_add_delayed (timeout, &download_timeout, dop); | 650 | GNUNET_SCHEDULER_add_delayed(timeout, &download_timeout, dop); |
649 | } | 651 | } |
650 | 652 | ||
651 | 653 | ||
diff --git a/src/fs/fs_test_lib.h b/src/fs/fs_test_lib.h index 4bf0c7caa..e1c43bea7 100644 --- a/src/fs/fs_test_lib.h +++ b/src/fs/fs_test_lib.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_test_lib.h | 22 | * @file 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 203de3c7e..5d486a8c9 100644 --- a/src/fs/fs_tree.c +++ b/src/fs/fs_tree.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/fs_tree.c | 21 | * @file fs/fs_tree.c |
22 | * @brief Merkle-tree-ish-CHK file encoding for GNUnet | 22 | * @brief Merkle-tree-ish-CHK file encoding for GNUnet |
@@ -32,9 +32,7 @@ | |||
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 | { | ||
37 | |||
38 | /** | 36 | /** |
39 | * Global FS context. | 37 | * Global FS context. |
40 | */ | 38 | */ |
@@ -123,7 +121,7 @@ struct GNUNET_FS_TreeEncoder | |||
123 | * @return depth of the tree, always > 0. A depth of 1 means only a DBLOCK. | 121 | * @return depth of the tree, always > 0. A depth of 1 means only a DBLOCK. |
124 | */ | 122 | */ |
125 | unsigned int | 123 | unsigned int |
126 | GNUNET_FS_compute_depth (uint64_t flen) | 124 | GNUNET_FS_compute_depth(uint64_t flen) |
127 | { | 125 | { |
128 | unsigned int treeDepth; | 126 | unsigned int treeDepth; |
129 | uint64_t fl; | 127 | uint64_t fl; |
@@ -131,15 +129,15 @@ GNUNET_FS_compute_depth (uint64_t flen) | |||
131 | treeDepth = 1; | 129 | treeDepth = 1; |
132 | fl = DBLOCK_SIZE; | 130 | fl = DBLOCK_SIZE; |
133 | while (fl < flen) | 131 | while (fl < flen) |
134 | { | ||
135 | treeDepth++; | ||
136 | if (fl * CHK_PER_INODE < fl) | ||
137 | { | 132 | { |
138 | /* integer overflow, this is a HUGE file... */ | 133 | treeDepth++; |
139 | return treeDepth; | 134 | if (fl * CHK_PER_INODE < fl) |
135 | { | ||
136 | /* integer overflow, this is a HUGE file... */ | ||
137 | return treeDepth; | ||
138 | } | ||
139 | fl = fl * CHK_PER_INODE; | ||
140 | } | 140 | } |
141 | fl = fl * CHK_PER_INODE; | ||
142 | } | ||
143 | return treeDepth; | 141 | return treeDepth; |
144 | } | 142 | } |
145 | 143 | ||
@@ -154,7 +152,7 @@ GNUNET_FS_compute_depth (uint64_t flen) | |||
154 | * @return number of bytes of payload a subtree of this depth may correspond to | 152 | * @return number of bytes of payload a subtree of this depth may correspond to |
155 | */ | 153 | */ |
156 | uint64_t | 154 | uint64_t |
157 | GNUNET_FS_tree_compute_tree_size (unsigned int depth) | 155 | GNUNET_FS_tree_compute_tree_size(unsigned int depth) |
158 | { | 156 | { |
159 | uint64_t rsize; | 157 | uint64_t rsize; |
160 | unsigned int i; | 158 | unsigned int i; |
@@ -181,30 +179,30 @@ GNUNET_FS_tree_compute_tree_size (unsigned int depth) | |||
181 | * @return size of the corresponding IBlock | 179 | * @return size of the corresponding IBlock |
182 | */ | 180 | */ |
183 | static uint16_t | 181 | static uint16_t |
184 | GNUNET_FS_tree_compute_iblock_size (unsigned int depth, uint64_t end_offset) | 182 | GNUNET_FS_tree_compute_iblock_size(unsigned int depth, uint64_t end_offset) |
185 | { | 183 | { |
186 | unsigned int ret; | 184 | unsigned int ret; |
187 | uint64_t mod; | 185 | uint64_t mod; |
188 | uint64_t bds; | 186 | uint64_t bds; |
189 | 187 | ||
190 | GNUNET_assert (depth > 0); | 188 | GNUNET_assert(depth > 0); |
191 | GNUNET_assert (end_offset > 0); | 189 | GNUNET_assert(end_offset > 0); |
192 | bds = GNUNET_FS_tree_compute_tree_size (depth); | 190 | bds = GNUNET_FS_tree_compute_tree_size(depth); |
193 | mod = end_offset % bds; | 191 | mod = end_offset % bds; |
194 | if (0 == mod) | 192 | if (0 == mod) |
195 | { | 193 | { |
196 | /* we were triggered at the end of a full block */ | 194 | /* we were triggered at the end of a full block */ |
197 | ret = CHK_PER_INODE; | 195 | ret = CHK_PER_INODE; |
198 | } | 196 | } |
199 | else | 197 | else |
200 | { | 198 | { |
201 | /* we were triggered at the end of the file */ | 199 | /* we were triggered at the end of the file */ |
202 | bds /= CHK_PER_INODE; | 200 | bds /= CHK_PER_INODE; |
203 | ret = mod / bds; | 201 | ret = mod / bds; |
204 | if (0 != mod % bds) | 202 | if (0 != mod % bds) |
205 | ret++; | 203 | ret++; |
206 | } | 204 | } |
207 | return (uint16_t) (ret * sizeof (struct ContentHashKey)); | 205 | return (uint16_t)(ret * sizeof(struct ContentHashKey)); |
208 | } | 206 | } |
209 | 207 | ||
210 | 208 | ||
@@ -220,32 +218,32 @@ GNUNET_FS_tree_compute_iblock_size (unsigned int depth, uint64_t end_offset) | |||
220 | * @return number of bytes stored in this node | 218 | * @return number of bytes stored in this node |
221 | */ | 219 | */ |
222 | size_t | 220 | size_t |
223 | GNUNET_FS_tree_calculate_block_size (uint64_t fsize, uint64_t offset, | 221 | GNUNET_FS_tree_calculate_block_size(uint64_t fsize, uint64_t offset, |
224 | unsigned int depth) | 222 | unsigned int depth) |
225 | { | 223 | { |
226 | size_t ret; | 224 | size_t ret; |
227 | uint64_t rsize; | 225 | uint64_t rsize; |
228 | uint64_t epos; | 226 | uint64_t epos; |
229 | unsigned int chks; | 227 | unsigned int chks; |
230 | 228 | ||
231 | GNUNET_assert (fsize > 0); | 229 | GNUNET_assert(fsize > 0); |
232 | GNUNET_assert (offset <= fsize); | 230 | GNUNET_assert(offset <= fsize); |
233 | if (depth == 0) | 231 | if (depth == 0) |
234 | { | 232 | { |
235 | ret = DBLOCK_SIZE; | 233 | ret = DBLOCK_SIZE; |
236 | if ((offset + ret > fsize) || (offset + ret < offset)) | 234 | if ((offset + ret > fsize) || (offset + ret < offset)) |
237 | ret = (size_t) (fsize - offset); | 235 | ret = (size_t)(fsize - offset); |
238 | return ret; | 236 | return ret; |
239 | } | 237 | } |
240 | 238 | ||
241 | rsize = GNUNET_FS_tree_compute_tree_size (depth - 1); | 239 | rsize = GNUNET_FS_tree_compute_tree_size(depth - 1); |
242 | epos = offset + rsize * CHK_PER_INODE; | 240 | epos = offset + rsize * CHK_PER_INODE; |
243 | if ((epos < offset) || (epos > fsize)) | 241 | if ((epos < offset) || (epos > fsize)) |
244 | epos = fsize; | 242 | epos = fsize; |
245 | /* round up when computing #CHKs in our IBlock */ | 243 | /* round up when computing #CHKs in our IBlock */ |
246 | chks = (epos - offset + rsize - 1) / rsize; | 244 | chks = (epos - offset + rsize - 1) / rsize; |
247 | GNUNET_assert (chks <= CHK_PER_INODE); | 245 | GNUNET_assert(chks <= CHK_PER_INODE); |
248 | return chks * sizeof (struct ContentHashKey); | 246 | return chks * sizeof(struct ContentHashKey); |
249 | } | 247 | } |
250 | 248 | ||
251 | 249 | ||
@@ -267,16 +265,16 @@ GNUNET_FS_tree_calculate_block_size (uint64_t fsize, uint64_t offset, | |||
267 | * @param cont function to call when done | 265 | * @param cont function to call when done |
268 | */ | 266 | */ |
269 | struct GNUNET_FS_TreeEncoder * | 267 | struct GNUNET_FS_TreeEncoder * |
270 | GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size, | 268 | GNUNET_FS_tree_encoder_create(struct GNUNET_FS_Handle *h, uint64_t size, |
271 | void *cls, | 269 | void *cls, |
272 | GNUNET_FS_DataReader reader, | 270 | GNUNET_FS_DataReader reader, |
273 | GNUNET_FS_TreeBlockProcessor proc, | 271 | GNUNET_FS_TreeBlockProcessor proc, |
274 | GNUNET_FS_TreeProgressCallback progress, | 272 | GNUNET_FS_TreeProgressCallback progress, |
275 | GNUNET_SCHEDULER_TaskCallback cont) | 273 | GNUNET_SCHEDULER_TaskCallback cont) |
276 | { | 274 | { |
277 | struct GNUNET_FS_TreeEncoder *te; | 275 | struct GNUNET_FS_TreeEncoder *te; |
278 | 276 | ||
279 | te = GNUNET_new (struct GNUNET_FS_TreeEncoder); | 277 | te = GNUNET_new(struct GNUNET_FS_TreeEncoder); |
280 | te->h = h; | 278 | te->h = h; |
281 | te->size = size; | 279 | te->size = size; |
282 | te->cls = cls; | 280 | te->cls = cls; |
@@ -284,14 +282,14 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size, | |||
284 | te->proc = proc; | 282 | te->proc = proc; |
285 | te->progress = progress; | 283 | te->progress = progress; |
286 | te->cont = cont; | 284 | te->cont = cont; |
287 | te->chk_tree_depth = GNUNET_FS_compute_depth (size); | 285 | te->chk_tree_depth = GNUNET_FS_compute_depth(size); |
288 | te->chk_tree | 286 | te->chk_tree |
289 | = GNUNET_new_array (te->chk_tree_depth * CHK_PER_INODE, | 287 | = GNUNET_new_array(te->chk_tree_depth * CHK_PER_INODE, |
290 | struct ContentHashKey); | 288 | struct ContentHashKey); |
291 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 289 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
292 | "Created tree encoder for file with %llu bytes and depth %u\n", | 290 | "Created tree encoder for file with %llu bytes and depth %u\n", |
293 | (unsigned long long) size, | 291 | (unsigned long long)size, |
294 | te->chk_tree_depth); | 292 | te->chk_tree_depth); |
295 | return te; | 293 | return te; |
296 | } | 294 | } |
297 | 295 | ||
@@ -308,12 +306,12 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size, | |||
308 | * @return (array of CHKs') offset in the above IBlock | 306 | * @return (array of CHKs') offset in the above IBlock |
309 | */ | 307 | */ |
310 | static unsigned int | 308 | static unsigned int |
311 | compute_chk_offset (unsigned int depth, uint64_t end_offset) | 309 | compute_chk_offset(unsigned int depth, uint64_t end_offset) |
312 | { | 310 | { |
313 | uint64_t bds; | 311 | uint64_t bds; |
314 | unsigned int ret; | 312 | unsigned int ret; |
315 | 313 | ||
316 | bds = GNUNET_FS_tree_compute_tree_size (depth); | 314 | bds = GNUNET_FS_tree_compute_tree_size(depth); |
317 | if (depth > 0) | 315 | if (depth > 0) |
318 | end_offset--; /* round down since for depth > 0 offset is at the END of the block */ | 316 | end_offset--; /* round down since for depth > 0 offset is at the END of the block */ |
319 | ret = end_offset / bds; | 317 | ret = end_offset / bds; |
@@ -329,7 +327,7 @@ compute_chk_offset (unsigned int depth, uint64_t end_offset) | |||
329 | * @param te tree encoder to use | 327 | * @param te tree encoder to use |
330 | */ | 328 | */ |
331 | void | 329 | void |
332 | GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) | 330 | GNUNET_FS_tree_encoder_next(struct GNUNET_FS_TreeEncoder *te) |
333 | { | 331 | { |
334 | struct ContentHashKey *mychk; | 332 | struct ContentHashKey *mychk; |
335 | const void *pt_block; | 333 | const void *pt_block; |
@@ -340,77 +338,77 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) | |||
340 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 338 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
341 | unsigned int off; | 339 | unsigned int off; |
342 | 340 | ||
343 | GNUNET_assert (GNUNET_NO == te->in_next); | 341 | GNUNET_assert(GNUNET_NO == te->in_next); |
344 | te->in_next = GNUNET_YES; | 342 | te->in_next = GNUNET_YES; |
345 | if (te->chk_tree_depth == te->current_depth) | 343 | if (te->chk_tree_depth == te->current_depth) |
346 | { | ||
347 | off = CHK_PER_INODE * (te->chk_tree_depth - 1); | ||
348 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TE done, reading CHK `%s' from %u\n", | ||
349 | GNUNET_h2s (&te->chk_tree[off].query), off); | ||
350 | te->uri = GNUNET_new (struct GNUNET_FS_Uri); | ||
351 | te->uri->type = GNUNET_FS_URI_CHK; | ||
352 | te->uri->data.chk.chk = te->chk_tree[off]; | ||
353 | te->uri->data.chk.file_length = GNUNET_htonll (te->size); | ||
354 | te->in_next = GNUNET_NO; | ||
355 | te->cont (te->cls); | ||
356 | return; | ||
357 | } | ||
358 | if (0 == te->current_depth) | ||
359 | { | ||
360 | /* read DBLOCK */ | ||
361 | pt_size = GNUNET_MIN (DBLOCK_SIZE, te->size - te->publish_offset); | ||
362 | if (pt_size != | ||
363 | te->reader (te->cls, te->publish_offset, pt_size, iob, &te->emsg)) | ||
364 | { | 344 | { |
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); | ||
365 | te->in_next = GNUNET_NO; | 352 | te->in_next = GNUNET_NO; |
366 | te->cont (te->cls); | 353 | te->cont(te->cls); |
367 | return; | 354 | return; |
368 | } | 355 | } |
369 | pt_block = iob; | 356 | if (0 == te->current_depth) |
370 | } | 357 | { |
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 | } | ||
371 | else | 369 | else |
372 | { | 370 | { |
373 | pt_size = | 371 | pt_size = |
374 | GNUNET_FS_tree_compute_iblock_size (te->current_depth, | 372 | GNUNET_FS_tree_compute_iblock_size(te->current_depth, |
375 | te->publish_offset); | 373 | te->publish_offset); |
376 | pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE]; | 374 | pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE]; |
377 | } | 375 | } |
378 | off = compute_chk_offset (te->current_depth, te->publish_offset); | 376 | off = compute_chk_offset(te->current_depth, te->publish_offset); |
379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 377 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
380 | "TE is at offset %llu and depth %u with block size %u and target-CHK-offset %u\n", | 378 | "TE is at offset %llu and depth %u with block size %u and target-CHK-offset %u\n", |
381 | (unsigned long long) te->publish_offset, te->current_depth, | 379 | (unsigned long long)te->publish_offset, te->current_depth, |
382 | (unsigned int) pt_size, (unsigned int) off); | 380 | (unsigned int)pt_size, (unsigned int)off); |
383 | mychk = &te->chk_tree[te->current_depth * CHK_PER_INODE + off]; | 381 | mychk = &te->chk_tree[te->current_depth * CHK_PER_INODE + off]; |
384 | GNUNET_CRYPTO_hash (pt_block, pt_size, &mychk->key); | 382 | GNUNET_CRYPTO_hash(pt_block, pt_size, &mychk->key); |
385 | GNUNET_CRYPTO_hash_to_aes_key (&mychk->key, &sk, &iv); | 383 | GNUNET_CRYPTO_hash_to_aes_key(&mychk->key, &sk, &iv); |
386 | GNUNET_CRYPTO_symmetric_encrypt (pt_block, pt_size, &sk, &iv, enc); | 384 | GNUNET_CRYPTO_symmetric_encrypt(pt_block, pt_size, &sk, &iv, enc); |
387 | GNUNET_CRYPTO_hash (enc, pt_size, &mychk->query); | 385 | GNUNET_CRYPTO_hash(enc, pt_size, &mychk->query); |
388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 386 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
389 | "TE calculates query to be `%s', stored at %u\n", | 387 | "TE calculates query to be `%s', stored at %u\n", |
390 | GNUNET_h2s (&mychk->query), | 388 | GNUNET_h2s(&mychk->query), |
391 | te->current_depth * CHK_PER_INODE + off); | 389 | te->current_depth * CHK_PER_INODE + off); |
392 | if (NULL != te->proc) | 390 | if (NULL != te->proc) |
393 | te->proc (te->cls, mychk, te->publish_offset, te->current_depth, | 391 | te->proc(te->cls, mychk, te->publish_offset, te->current_depth, |
394 | (0 == | 392 | (0 == |
395 | te->current_depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK : | 393 | te->current_depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK : |
396 | GNUNET_BLOCK_TYPE_FS_IBLOCK, enc, pt_size); | 394 | GNUNET_BLOCK_TYPE_FS_IBLOCK, enc, pt_size); |
397 | if (NULL != te->progress) | 395 | if (NULL != te->progress) |
398 | te->progress (te->cls, te->publish_offset, pt_block, pt_size, | 396 | te->progress(te->cls, te->publish_offset, pt_block, pt_size, |
399 | te->current_depth); | 397 | te->current_depth); |
400 | if (0 == te->current_depth) | 398 | if (0 == te->current_depth) |
401 | { | 399 | { |
402 | te->publish_offset += pt_size; | 400 | te->publish_offset += pt_size; |
403 | if ((te->publish_offset == te->size) || | 401 | if ((te->publish_offset == te->size) || |
404 | (0 == te->publish_offset % (CHK_PER_INODE * DBLOCK_SIZE))) | 402 | (0 == te->publish_offset % (CHK_PER_INODE * DBLOCK_SIZE))) |
405 | te->current_depth++; | 403 | te->current_depth++; |
406 | } | 404 | } |
407 | else | 405 | else |
408 | { | 406 | { |
409 | if ((off == CHK_PER_INODE) || (te->publish_offset == te->size)) | 407 | if ((off == CHK_PER_INODE) || (te->publish_offset == te->size)) |
410 | te->current_depth++; | 408 | te->current_depth++; |
411 | else | 409 | else |
412 | te->current_depth = 0; | 410 | te->current_depth = 0; |
413 | } | 411 | } |
414 | te->in_next = GNUNET_NO; | 412 | te->in_next = GNUNET_NO; |
415 | } | 413 | } |
416 | 414 | ||
@@ -422,10 +420,10 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) | |||
422 | * @return uri set to the resulting URI (if encoding finished), NULL otherwise | 420 | * @return uri set to the resulting URI (if encoding finished), NULL otherwise |
423 | */ | 421 | */ |
424 | struct GNUNET_FS_Uri * | 422 | struct GNUNET_FS_Uri * |
425 | GNUNET_FS_tree_encoder_get_uri (struct GNUNET_FS_TreeEncoder *te) | 423 | GNUNET_FS_tree_encoder_get_uri(struct GNUNET_FS_TreeEncoder *te) |
426 | { | 424 | { |
427 | if (NULL != te->uri) | 425 | if (NULL != te->uri) |
428 | return GNUNET_FS_uri_dup (te->uri); | 426 | return GNUNET_FS_uri_dup(te->uri); |
429 | return NULL; | 427 | return NULL; |
430 | } | 428 | } |
431 | 429 | ||
@@ -441,23 +439,23 @@ GNUNET_FS_tree_encoder_get_uri (struct GNUNET_FS_TreeEncoder *te) | |||
441 | * both "*emsg" will be set to NULL). | 439 | * both "*emsg" will be set to NULL). |
442 | */ | 440 | */ |
443 | void | 441 | void |
444 | GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, | 442 | GNUNET_FS_tree_encoder_finish(struct GNUNET_FS_TreeEncoder *te, |
445 | char **emsg) | 443 | char **emsg) |
446 | { | 444 | { |
447 | if (NULL != te->reader) | 445 | if (NULL != te->reader) |
448 | { | 446 | { |
449 | (void) te->reader (te->cls, UINT64_MAX, 0, 0, NULL); | 447 | (void)te->reader(te->cls, UINT64_MAX, 0, 0, NULL); |
450 | te->reader = NULL; | 448 | te->reader = NULL; |
451 | } | 449 | } |
452 | GNUNET_assert (GNUNET_NO == te->in_next); | 450 | GNUNET_assert(GNUNET_NO == te->in_next); |
453 | if (NULL != te->uri) | 451 | if (NULL != te->uri) |
454 | GNUNET_FS_uri_destroy (te->uri); | 452 | GNUNET_FS_uri_destroy(te->uri); |
455 | if (emsg != NULL) | 453 | if (emsg != NULL) |
456 | *emsg = te->emsg; | 454 | *emsg = te->emsg; |
457 | else | 455 | else |
458 | GNUNET_free_non_null (te->emsg); | 456 | GNUNET_free_non_null(te->emsg); |
459 | GNUNET_free (te->chk_tree); | 457 | GNUNET_free(te->chk_tree); |
460 | GNUNET_free (te); | 458 | GNUNET_free(te); |
461 | } | 459 | } |
462 | 460 | ||
463 | /* end of fs_tree.c */ | 461 | /* end of fs_tree.c */ |
diff --git a/src/fs/fs_tree.h b/src/fs/fs_tree.h index 13a8603c5..7ce7e461b 100644 --- a/src/fs/fs_tree.h +++ b/src/fs/fs_tree.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_tree.h | 22 | * @file 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 | /** |
@@ -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 b013902c9..be2dbbddd 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_unindex.c | 22 | * @file 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,47 +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 | case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: | 382 | |
383 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 383 | case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: |
384 | _("Internal error scanning `%s'.\n"), | 384 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
385 | uc->filename); | 385 | _("Internal error scanning `%s'.\n"), |
386 | GNUNET_FS_directory_scan_abort (uc->dscan); | 386 | uc->filename); |
387 | uc->dscan = NULL; | 387 | GNUNET_FS_directory_scan_abort(uc->dscan); |
388 | uc->emsg = GNUNET_strdup (_("Failed to get KSKs from directory scan.")); | 388 | uc->dscan = NULL; |
389 | GNUNET_FS_unindex_sync_ (uc); | 389 | uc->emsg = GNUNET_strdup(_("Failed to get KSKs from directory scan.")); |
390 | unindex_finish (uc); | 390 | GNUNET_FS_unindex_sync_(uc); |
391 | break; | 391 | unindex_finish(uc); |
392 | default: | 392 | break; |
393 | break; | 393 | |
394 | } | 394 | default: |
395 | break; | ||
396 | } | ||
395 | } | 397 | } |
396 | 398 | ||
397 | 399 | ||
@@ -401,18 +403,18 @@ unindex_directory_scan_cb (void *cls, | |||
401 | * @param uc context for the unindex operation. | 403 | * @param uc context for the unindex operation. |
402 | */ | 404 | */ |
403 | void | 405 | void |
404 | GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc) | 406 | GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc) |
405 | { | 407 | { |
406 | char *ex; | 408 | char *ex; |
407 | 409 | ||
408 | if (GNUNET_OK != | 410 | if (GNUNET_OK != |
409 | GNUNET_CONFIGURATION_get_value_string (uc->h->cfg, "FS", "EXTRACTORS", &ex)) | 411 | GNUNET_CONFIGURATION_get_value_string(uc->h->cfg, "FS", "EXTRACTORS", &ex)) |
410 | ex = NULL; | 412 | ex = NULL; |
411 | uc->dscan = GNUNET_FS_directory_scan_start (uc->filename, | 413 | uc->dscan = GNUNET_FS_directory_scan_start(uc->filename, |
412 | GNUNET_NO, ex, | 414 | GNUNET_NO, ex, |
413 | &unindex_directory_scan_cb, | 415 | &unindex_directory_scan_cb, |
414 | uc); | 416 | uc); |
415 | GNUNET_free_non_null (ex); | 417 | GNUNET_free_non_null(ex); |
416 | } | 418 | } |
417 | 419 | ||
418 | 420 | ||
@@ -430,20 +432,20 @@ GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc) | |||
430 | * @param msg NULL on success, otherwise an error message | 432 | * @param msg NULL on success, otherwise an error message |
431 | */ | 433 | */ |
432 | static void | 434 | static void |
433 | continue_after_remove (void *cls, | 435 | continue_after_remove(void *cls, |
434 | int32_t success, | 436 | int32_t success, |
435 | struct GNUNET_TIME_Absolute min_expiration, | 437 | struct GNUNET_TIME_Absolute min_expiration, |
436 | const char *msg) | 438 | const char *msg) |
437 | { | 439 | { |
438 | struct GNUNET_FS_UnindexContext *uc = cls; | 440 | struct GNUNET_FS_UnindexContext *uc = cls; |
439 | 441 | ||
440 | uc->dqe = NULL; | 442 | uc->dqe = NULL; |
441 | if (success != GNUNET_YES) | 443 | if (success != GNUNET_YES) |
442 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 444 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
443 | _("Failed to remove UBlock: %s\n"), | 445 | _("Failed to remove UBlock: %s\n"), |
444 | msg); | 446 | msg); |
445 | uc->ksk_offset++; | 447 | uc->ksk_offset++; |
446 | GNUNET_FS_unindex_do_remove_kblocks_ (uc); | 448 | GNUNET_FS_unindex_do_remove_kblocks_(uc); |
447 | } | 449 | } |
448 | 450 | ||
449 | 451 | ||
@@ -470,16 +472,16 @@ continue_after_remove (void *cls, | |||
470 | * maybe 0 if no unique identifier is available | 472 | * maybe 0 if no unique identifier is available |
471 | */ | 473 | */ |
472 | static void | 474 | static void |
473 | process_kblock_for_unindex (void *cls, | 475 | process_kblock_for_unindex(void *cls, |
474 | const struct GNUNET_HashCode *key, | 476 | const struct GNUNET_HashCode *key, |
475 | size_t size, | 477 | size_t size, |
476 | const void *data, | 478 | const void *data, |
477 | enum GNUNET_BLOCK_Type type, | 479 | enum GNUNET_BLOCK_Type type, |
478 | uint32_t priority, | 480 | uint32_t priority, |
479 | uint32_t anonymity, | 481 | uint32_t anonymity, |
480 | uint32_t replication, | 482 | uint32_t replication, |
481 | struct GNUNET_TIME_Absolute expiration, | 483 | struct GNUNET_TIME_Absolute expiration, |
482 | uint64_t uid) | 484 | uint64_t uid) |
483 | { | 485 | { |
484 | struct GNUNET_FS_UnindexContext *uc = cls; | 486 | struct GNUNET_FS_UnindexContext *uc = cls; |
485 | const struct UBlock *ub; | 487 | const struct UBlock *ub; |
@@ -488,82 +490,82 @@ process_kblock_for_unindex (void *cls, | |||
488 | 490 | ||
489 | uc->dqe = NULL; | 491 | uc->dqe = NULL; |
490 | if (NULL == data) | 492 | if (NULL == data) |
491 | { | 493 | { |
492 | /* no result */ | 494 | /* no result */ |
493 | uc->ksk_offset++; | 495 | uc->ksk_offset++; |
494 | GNUNET_FS_unindex_do_remove_kblocks_ (uc); | 496 | GNUNET_FS_unindex_do_remove_kblocks_(uc); |
495 | return; | 497 | return; |
496 | } | 498 | } |
497 | GNUNET_assert (GNUNET_BLOCK_TYPE_FS_UBLOCK == type); | 499 | GNUNET_assert(GNUNET_BLOCK_TYPE_FS_UBLOCK == type); |
498 | if (size < sizeof (struct UBlock)) | 500 | if (size < sizeof(struct UBlock)) |
499 | { | 501 | { |
500 | GNUNET_break (0); | 502 | GNUNET_break(0); |
501 | goto get_next; | 503 | goto get_next; |
502 | } | 504 | } |
503 | ub = data; | 505 | ub = data; |
504 | GNUNET_CRYPTO_hash (&ub->verification_key, | 506 | GNUNET_CRYPTO_hash(&ub->verification_key, |
505 | sizeof (ub->verification_key), | 507 | sizeof(ub->verification_key), |
506 | &query); | 508 | &query); |
507 | if (0 != memcmp (&query, | 509 | if (0 != memcmp(&query, |
508 | key, | 510 | key, |
509 | sizeof (struct GNUNET_HashCode))) | 511 | sizeof(struct GNUNET_HashCode))) |
510 | { | 512 | { |
511 | /* result does not match our keyword, skip */ | 513 | /* result does not match our keyword, skip */ |
512 | goto get_next; | 514 | goto get_next; |
513 | } | 515 | } |
514 | { | 516 | { |
515 | char pt[size - sizeof (struct UBlock)]; | 517 | char pt[size - sizeof(struct UBlock)]; |
516 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; | 518 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; |
517 | const char *keyword; | 519 | const char *keyword; |
518 | 520 | ||
519 | GNUNET_CRYPTO_ecdsa_key_get_public (GNUNET_CRYPTO_ecdsa_key_get_anonymous (), | 521 | GNUNET_CRYPTO_ecdsa_key_get_public(GNUNET_CRYPTO_ecdsa_key_get_anonymous(), |
520 | &anon_pub); | 522 | &anon_pub); |
521 | keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; | 523 | keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; |
522 | GNUNET_FS_ublock_decrypt_ (&ub[1], size - sizeof (struct UBlock), | 524 | GNUNET_FS_ublock_decrypt_(&ub[1], size - sizeof(struct UBlock), |
523 | &anon_pub, | 525 | &anon_pub, |
524 | keyword, | 526 | keyword, |
525 | pt); | 527 | pt); |
526 | if (NULL == memchr (&pt[1], 0, sizeof (pt) - 1)) | 528 | if (NULL == memchr(&pt[1], 0, sizeof(pt) - 1)) |
527 | { | 529 | { |
528 | GNUNET_break_op (0); /* malformed UBlock */ | 530 | GNUNET_break_op(0); /* malformed UBlock */ |
529 | goto get_next; | 531 | goto get_next; |
530 | } | 532 | } |
531 | chk_uri = GNUNET_FS_uri_parse (&pt[1], NULL); | 533 | chk_uri = GNUNET_FS_uri_parse(&pt[1], NULL); |
532 | if (NULL == chk_uri) | 534 | 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))) | ||
533 | { | 543 | { |
534 | GNUNET_break_op (0); /* malformed UBlock */ | 544 | /* different CHK, ignore */ |
545 | GNUNET_FS_uri_destroy(chk_uri); | ||
535 | goto get_next; | 546 | goto get_next; |
536 | } | 547 | } |
537 | } | 548 | GNUNET_FS_uri_destroy(chk_uri); |
538 | if (0 != memcmp (&uc->chk, | ||
539 | &chk_uri->data.chk.chk, | ||
540 | sizeof (struct ContentHashKey))) | ||
541 | { | ||
542 | /* different CHK, ignore */ | ||
543 | GNUNET_FS_uri_destroy (chk_uri); | ||
544 | goto get_next; | ||
545 | } | ||
546 | GNUNET_FS_uri_destroy (chk_uri); | ||
547 | /* matches! */ | 549 | /* matches! */ |
548 | uc->dqe = GNUNET_DATASTORE_remove (uc->dsh, | 550 | uc->dqe = GNUNET_DATASTORE_remove(uc->dsh, |
549 | key, | 551 | key, |
550 | size, | 552 | size, |
551 | data, | 553 | 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, | ||
552 | 0 /* priority */, | 565 | 0 /* priority */, |
553 | 1 /* queue size */, | 566 | 1 /* queue size */, |
554 | &continue_after_remove, | 567 | &process_kblock_for_unindex, |
555 | uc); | 568 | uc); |
556 | return; | ||
557 | get_next: | ||
558 | uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, | ||
559 | uid + 1 /* next_uid */, | ||
560 | false /* random */, | ||
561 | &uc->uquery, | ||
562 | GNUNET_BLOCK_TYPE_FS_UBLOCK, | ||
563 | 0 /* priority */, | ||
564 | 1 /* queue size */, | ||
565 | &process_kblock_for_unindex, | ||
566 | uc); | ||
567 | } | 569 | } |
568 | 570 | ||
569 | 571 | ||
@@ -573,7 +575,7 @@ process_kblock_for_unindex (void *cls, | |||
573 | * @param uc context for the unindex operation. | 575 | * @param uc context for the unindex operation. |
574 | */ | 576 | */ |
575 | void | 577 | void |
576 | GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) | 578 | GNUNET_FS_unindex_do_remove_kblocks_(struct GNUNET_FS_UnindexContext *uc) |
577 | { | 579 | { |
578 | const char *keyword; | 580 | const char *keyword; |
579 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; | 581 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; |
@@ -581,41 +583,41 @@ GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) | |||
581 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; | 583 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; |
582 | 584 | ||
583 | if (NULL == uc->dsh) | 585 | if (NULL == uc->dsh) |
584 | uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); | 586 | uc->dsh = GNUNET_DATASTORE_connect(uc->h->cfg); |
585 | if (NULL == uc->dsh) | 587 | if (NULL == uc->dsh) |
586 | { | 588 | { |
587 | uc->state = UNINDEX_STATE_ERROR; | 589 | uc->state = UNINDEX_STATE_ERROR; |
588 | uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service.")); | 590 | uc->emsg = GNUNET_strdup(_("Failed to connect to `datastore' service.")); |
589 | GNUNET_FS_unindex_sync_ (uc); | 591 | GNUNET_FS_unindex_sync_(uc); |
590 | signal_unindex_error (uc); | 592 | signal_unindex_error(uc); |
591 | return; | 593 | return; |
592 | } | 594 | } |
593 | if ( (NULL == uc->ksk_uri) || | 595 | if ((NULL == uc->ksk_uri) || |
594 | (uc->ksk_offset >= uc->ksk_uri->data.ksk.keywordCount) ) | 596 | (uc->ksk_offset >= uc->ksk_uri->data.ksk.keywordCount)) |
595 | { | 597 | { |
596 | unindex_finish (uc); | 598 | unindex_finish(uc); |
597 | return; | 599 | return; |
598 | } | 600 | } |
599 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); | 601 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous(); |
600 | GNUNET_CRYPTO_ecdsa_key_get_public (anon, | 602 | GNUNET_CRYPTO_ecdsa_key_get_public(anon, |
601 | &anon_pub); | 603 | &anon_pub); |
602 | keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; | 604 | keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; |
603 | GNUNET_CRYPTO_ecdsa_public_key_derive (&anon_pub, | 605 | GNUNET_CRYPTO_ecdsa_public_key_derive(&anon_pub, |
604 | keyword, | 606 | keyword, |
605 | "fs-ublock", | 607 | "fs-ublock", |
606 | &dpub); | 608 | &dpub); |
607 | GNUNET_CRYPTO_hash (&dpub, | 609 | GNUNET_CRYPTO_hash(&dpub, |
608 | sizeof (dpub), | 610 | sizeof(dpub), |
609 | &uc->uquery); | 611 | &uc->uquery); |
610 | uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, | 612 | uc->dqe = GNUNET_DATASTORE_get_key(uc->dsh, |
611 | 0 /* next_uid */, | 613 | 0 /* next_uid */, |
612 | false /* random */, | 614 | false /* random */, |
613 | &uc->uquery, | 615 | &uc->uquery, |
614 | GNUNET_BLOCK_TYPE_FS_UBLOCK, | 616 | GNUNET_BLOCK_TYPE_FS_UBLOCK, |
615 | 0 /* priority */, | 617 | 0 /* priority */, |
616 | 1 /* queue size */, | 618 | 1 /* queue size */, |
617 | &process_kblock_for_unindex, | 619 | &process_kblock_for_unindex, |
618 | uc); | 620 | uc); |
619 | } | 621 | } |
620 | 622 | ||
621 | 623 | ||
@@ -626,13 +628,13 @@ GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) | |||
626 | * @param cls our unindexing context | 628 | * @param cls our unindexing context |
627 | */ | 629 | */ |
628 | static void | 630 | static void |
629 | unindex_extract_keywords (void *cls) | 631 | unindex_extract_keywords(void *cls) |
630 | { | 632 | { |
631 | struct GNUNET_FS_UnindexContext *uc = cls; | 633 | struct GNUNET_FS_UnindexContext *uc = cls; |
632 | 634 | ||
633 | uc->state = UNINDEX_STATE_EXTRACT_KEYWORDS; | 635 | uc->state = UNINDEX_STATE_EXTRACT_KEYWORDS; |
634 | GNUNET_FS_unindex_sync_ (uc); | 636 | GNUNET_FS_unindex_sync_(uc); |
635 | GNUNET_FS_unindex_do_extract_keywords_ (uc); | 637 | GNUNET_FS_unindex_do_extract_keywords_(uc); |
636 | } | 638 | } |
637 | 639 | ||
638 | 640 | ||
@@ -642,40 +644,40 @@ unindex_extract_keywords (void *cls) | |||
642 | * @param uc context for the unindex operation. | 644 | * @param uc context for the unindex operation. |
643 | */ | 645 | */ |
644 | void | 646 | void |
645 | GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc) | 647 | GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc) |
646 | { | 648 | { |
647 | if (NULL == uc->dsh) | 649 | if (NULL == uc->dsh) |
648 | uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); | 650 | uc->dsh = GNUNET_DATASTORE_connect(uc->h->cfg); |
649 | if (NULL == uc->dsh) | 651 | if (NULL == uc->dsh) |
650 | { | 652 | { |
651 | uc->state = UNINDEX_STATE_ERROR; | 653 | uc->state = UNINDEX_STATE_ERROR; |
652 | uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service.")); | 654 | uc->emsg = GNUNET_strdup(_("Failed to connect to `datastore' service.")); |
653 | GNUNET_FS_unindex_sync_ (uc); | 655 | GNUNET_FS_unindex_sync_(uc); |
654 | signal_unindex_error (uc); | 656 | signal_unindex_error(uc); |
655 | return; | 657 | return; |
656 | } | 658 | } |
657 | uc->fh = | 659 | uc->fh = |
658 | GNUNET_DISK_file_open (uc->filename, GNUNET_DISK_OPEN_READ, | 660 | GNUNET_DISK_file_open(uc->filename, GNUNET_DISK_OPEN_READ, |
659 | GNUNET_DISK_PERM_NONE); | 661 | GNUNET_DISK_PERM_NONE); |
660 | if (NULL == uc->fh) | 662 | if (NULL == uc->fh) |
661 | { | 663 | { |
662 | GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); | 664 | GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); |
663 | uc->dsh = NULL; | 665 | uc->dsh = NULL; |
664 | uc->state = UNINDEX_STATE_ERROR; | 666 | uc->state = UNINDEX_STATE_ERROR; |
665 | uc->emsg = GNUNET_strdup (_("Failed to open file for unindexing.")); | 667 | uc->emsg = GNUNET_strdup(_("Failed to open file for unindexing.")); |
666 | GNUNET_FS_unindex_sync_ (uc); | 668 | GNUNET_FS_unindex_sync_(uc); |
667 | signal_unindex_error (uc); | 669 | signal_unindex_error(uc); |
668 | return; | 670 | return; |
669 | } | 671 | } |
670 | uc->tc = | 672 | uc->tc = |
671 | GNUNET_FS_tree_encoder_create (uc->h, | 673 | GNUNET_FS_tree_encoder_create(uc->h, |
672 | uc->file_size, | 674 | uc->file_size, |
673 | uc, | 675 | uc, |
674 | &unindex_reader, | 676 | &unindex_reader, |
675 | &unindex_process, | 677 | &unindex_process, |
676 | &unindex_progress, | 678 | &unindex_progress, |
677 | &unindex_extract_keywords); | 679 | &unindex_extract_keywords); |
678 | GNUNET_FS_tree_encoder_next (uc->tc); | 680 | GNUNET_FS_tree_encoder_next(uc->tc); |
679 | } | 681 | } |
680 | 682 | ||
681 | 683 | ||
@@ -687,29 +689,29 @@ GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc) | |||
687 | * @param file_id computed hash, NULL on error | 689 | * @param file_id computed hash, NULL on error |
688 | */ | 690 | */ |
689 | void | 691 | void |
690 | GNUNET_FS_unindex_process_hash_ (void *cls, | 692 | GNUNET_FS_unindex_process_hash_(void *cls, |
691 | const struct GNUNET_HashCode *file_id) | 693 | const struct GNUNET_HashCode *file_id) |
692 | { | 694 | { |
693 | struct GNUNET_FS_UnindexContext *uc = cls; | 695 | struct GNUNET_FS_UnindexContext *uc = cls; |
694 | 696 | ||
695 | uc->fhc = NULL; | 697 | uc->fhc = NULL; |
696 | if (uc->state != UNINDEX_STATE_HASHING) | 698 | if (uc->state != UNINDEX_STATE_HASHING) |
697 | { | 699 | { |
698 | GNUNET_FS_unindex_stop (uc); | 700 | GNUNET_FS_unindex_stop(uc); |
699 | return; | 701 | return; |
700 | } | 702 | } |
701 | if (file_id == NULL) | 703 | if (file_id == NULL) |
702 | { | 704 | { |
703 | uc->state = UNINDEX_STATE_ERROR; | 705 | uc->state = UNINDEX_STATE_ERROR; |
704 | uc->emsg = GNUNET_strdup (_("Failed to compute hash of file.")); | 706 | uc->emsg = GNUNET_strdup(_("Failed to compute hash of file.")); |
705 | GNUNET_FS_unindex_sync_ (uc); | 707 | GNUNET_FS_unindex_sync_(uc); |
706 | signal_unindex_error (uc); | 708 | signal_unindex_error(uc); |
707 | return; | 709 | return; |
708 | } | 710 | } |
709 | uc->file_id = *file_id; | 711 | uc->file_id = *file_id; |
710 | uc->state = UNINDEX_STATE_DS_REMOVE; | 712 | uc->state = UNINDEX_STATE_DS_REMOVE; |
711 | GNUNET_FS_unindex_sync_ (uc); | 713 | GNUNET_FS_unindex_sync_(uc); |
712 | GNUNET_FS_unindex_do_remove_ (uc); | 714 | GNUNET_FS_unindex_do_remove_(uc); |
713 | } | 715 | } |
714 | 716 | ||
715 | 717 | ||
@@ -720,62 +722,62 @@ GNUNET_FS_unindex_process_hash_ (void *cls, | |||
720 | * @param cls the `struct GNUNET_FS_UnindexContext` to signal for | 722 | * @param cls the `struct GNUNET_FS_UnindexContext` to signal for |
721 | */ | 723 | */ |
722 | void | 724 | void |
723 | GNUNET_FS_unindex_signal_suspend_ (void *cls) | 725 | GNUNET_FS_unindex_signal_suspend_(void *cls) |
724 | { | 726 | { |
725 | struct GNUNET_FS_UnindexContext *uc = cls; | 727 | struct GNUNET_FS_UnindexContext *uc = cls; |
726 | struct GNUNET_FS_ProgressInfo pi; | 728 | struct GNUNET_FS_ProgressInfo pi; |
727 | 729 | ||
728 | /* FIXME: lots of duplication with unindex_stop here! */ | 730 | /* FIXME: lots of duplication with unindex_stop here! */ |
729 | if (uc->dscan != NULL) | 731 | if (uc->dscan != NULL) |
730 | { | 732 | { |
731 | GNUNET_FS_directory_scan_abort (uc->dscan); | 733 | GNUNET_FS_directory_scan_abort(uc->dscan); |
732 | uc->dscan = NULL; | 734 | uc->dscan = NULL; |
733 | } | 735 | } |
734 | if (NULL != uc->dqe) | 736 | if (NULL != uc->dqe) |
735 | { | 737 | { |
736 | GNUNET_DATASTORE_cancel (uc->dqe); | 738 | GNUNET_DATASTORE_cancel(uc->dqe); |
737 | uc->dqe = NULL; | 739 | uc->dqe = NULL; |
738 | } | 740 | } |
739 | if (uc->fhc != NULL) | 741 | if (uc->fhc != NULL) |
740 | { | 742 | { |
741 | GNUNET_CRYPTO_hash_file_cancel (uc->fhc); | 743 | GNUNET_CRYPTO_hash_file_cancel(uc->fhc); |
742 | uc->fhc = NULL; | 744 | uc->fhc = NULL; |
743 | } | 745 | } |
744 | if (NULL != uc->ksk_uri) | 746 | if (NULL != uc->ksk_uri) |
745 | { | 747 | { |
746 | GNUNET_FS_uri_destroy (uc->ksk_uri); | 748 | GNUNET_FS_uri_destroy(uc->ksk_uri); |
747 | uc->ksk_uri = NULL; | 749 | uc->ksk_uri = NULL; |
748 | } | 750 | } |
749 | if (NULL != uc->mq) | 751 | if (NULL != uc->mq) |
750 | { | 752 | { |
751 | GNUNET_MQ_destroy (uc->mq); | 753 | GNUNET_MQ_destroy(uc->mq); |
752 | uc->mq = NULL; | 754 | uc->mq = NULL; |
753 | } | 755 | } |
754 | if (NULL != uc->dsh) | 756 | if (NULL != uc->dsh) |
755 | { | 757 | { |
756 | GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); | 758 | GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); |
757 | uc->dsh = NULL; | 759 | uc->dsh = NULL; |
758 | } | 760 | } |
759 | if (NULL != uc->tc) | 761 | if (NULL != uc->tc) |
760 | { | 762 | { |
761 | GNUNET_FS_tree_encoder_finish (uc->tc, NULL); | 763 | GNUNET_FS_tree_encoder_finish(uc->tc, NULL); |
762 | uc->tc = NULL; | 764 | uc->tc = NULL; |
763 | } | 765 | } |
764 | if (uc->fh != NULL) | 766 | if (uc->fh != NULL) |
765 | { | 767 | { |
766 | GNUNET_DISK_file_close (uc->fh); | 768 | GNUNET_DISK_file_close(uc->fh); |
767 | uc->fh = NULL; | 769 | uc->fh = NULL; |
768 | } | 770 | } |
769 | GNUNET_FS_end_top (uc->h, uc->top); | 771 | GNUNET_FS_end_top(uc->h, uc->top); |
770 | pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; | 772 | pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; |
771 | GNUNET_FS_unindex_make_status_ (&pi, uc, | 773 | GNUNET_FS_unindex_make_status_(&pi, uc, |
772 | (uc->state == | 774 | (uc->state == |
773 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); | 775 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); |
774 | GNUNET_break (NULL == uc->client_info); | 776 | GNUNET_break(NULL == uc->client_info); |
775 | GNUNET_free (uc->filename); | 777 | GNUNET_free(uc->filename); |
776 | GNUNET_free_non_null (uc->serialization); | 778 | GNUNET_free_non_null(uc->serialization); |
777 | GNUNET_free_non_null (uc->emsg); | 779 | GNUNET_free_non_null(uc->emsg); |
778 | GNUNET_free (uc); | 780 | GNUNET_free(uc); |
779 | } | 781 | } |
780 | 782 | ||
781 | 783 | ||
@@ -788,38 +790,38 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls) | |||
788 | * @return NULL on error, otherwise handle | 790 | * @return NULL on error, otherwise handle |
789 | */ | 791 | */ |
790 | struct GNUNET_FS_UnindexContext * | 792 | struct GNUNET_FS_UnindexContext * |
791 | GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, | 793 | GNUNET_FS_unindex_start(struct GNUNET_FS_Handle *h, |
792 | const char *filename, | 794 | const char *filename, |
793 | void *cctx) | 795 | void *cctx) |
794 | { | 796 | { |
795 | struct GNUNET_FS_UnindexContext *uc; | 797 | struct GNUNET_FS_UnindexContext *uc; |
796 | struct GNUNET_FS_ProgressInfo pi; | 798 | struct GNUNET_FS_ProgressInfo pi; |
797 | uint64_t size; | 799 | uint64_t size; |
798 | 800 | ||
799 | if (GNUNET_OK != | 801 | if (GNUNET_OK != |
800 | GNUNET_DISK_file_size (filename, | 802 | GNUNET_DISK_file_size(filename, |
801 | &size, | 803 | &size, |
802 | GNUNET_YES, | 804 | GNUNET_YES, |
803 | GNUNET_YES)) | 805 | GNUNET_YES)) |
804 | return NULL; | 806 | return NULL; |
805 | uc = GNUNET_new (struct GNUNET_FS_UnindexContext); | 807 | uc = GNUNET_new(struct GNUNET_FS_UnindexContext); |
806 | uc->h = h; | 808 | uc->h = h; |
807 | uc->filename = GNUNET_strdup (filename); | 809 | uc->filename = GNUNET_strdup(filename); |
808 | uc->start_time = GNUNET_TIME_absolute_get (); | 810 | uc->start_time = GNUNET_TIME_absolute_get(); |
809 | uc->file_size = size; | 811 | uc->file_size = size; |
810 | uc->client_info = cctx; | 812 | uc->client_info = cctx; |
811 | GNUNET_FS_unindex_sync_ (uc); | 813 | GNUNET_FS_unindex_sync_(uc); |
812 | pi.status = GNUNET_FS_STATUS_UNINDEX_START; | 814 | pi.status = GNUNET_FS_STATUS_UNINDEX_START; |
813 | pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 815 | pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
814 | GNUNET_FS_unindex_make_status_ (&pi, uc, 0); | 816 | GNUNET_FS_unindex_make_status_(&pi, uc, 0); |
815 | uc->fhc = | 817 | uc->fhc = |
816 | GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, | 818 | GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, |
817 | filename, | 819 | filename, |
818 | HASHING_BLOCKSIZE, | 820 | HASHING_BLOCKSIZE, |
819 | &GNUNET_FS_unindex_process_hash_, uc); | 821 | &GNUNET_FS_unindex_process_hash_, uc); |
820 | uc->top = GNUNET_FS_make_top (h, | 822 | uc->top = GNUNET_FS_make_top(h, |
821 | &GNUNET_FS_unindex_signal_suspend_, | 823 | &GNUNET_FS_unindex_signal_suspend_, |
822 | uc); | 824 | uc); |
823 | return uc; | 825 | return uc; |
824 | } | 826 | } |
825 | 827 | ||
@@ -830,67 +832,67 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, | |||
830 | * @param uc handle | 832 | * @param uc handle |
831 | */ | 833 | */ |
832 | void | 834 | void |
833 | GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) | 835 | GNUNET_FS_unindex_stop(struct GNUNET_FS_UnindexContext *uc) |
834 | { | 836 | { |
835 | struct GNUNET_FS_ProgressInfo pi; | 837 | struct GNUNET_FS_ProgressInfo pi; |
836 | 838 | ||
837 | if (NULL != uc->dscan) | 839 | if (NULL != uc->dscan) |
838 | { | 840 | { |
839 | GNUNET_FS_directory_scan_abort (uc->dscan); | 841 | GNUNET_FS_directory_scan_abort(uc->dscan); |
840 | uc->dscan = NULL; | 842 | uc->dscan = NULL; |
841 | } | 843 | } |
842 | if (NULL != uc->dqe) | 844 | if (NULL != uc->dqe) |
843 | { | 845 | { |
844 | GNUNET_DATASTORE_cancel (uc->dqe); | 846 | GNUNET_DATASTORE_cancel(uc->dqe); |
845 | uc->dqe = NULL; | 847 | uc->dqe = NULL; |
846 | } | 848 | } |
847 | if (NULL != uc->fhc) | 849 | if (NULL != uc->fhc) |
848 | { | 850 | { |
849 | GNUNET_CRYPTO_hash_file_cancel (uc->fhc); | 851 | GNUNET_CRYPTO_hash_file_cancel(uc->fhc); |
850 | uc->fhc = NULL; | 852 | uc->fhc = NULL; |
851 | } | 853 | } |
852 | if (NULL != uc->mq) | 854 | if (NULL != uc->mq) |
853 | { | 855 | { |
854 | GNUNET_MQ_destroy (uc->mq); | 856 | GNUNET_MQ_destroy(uc->mq); |
855 | uc->mq = NULL; | 857 | uc->mq = NULL; |
856 | } | 858 | } |
857 | if (NULL != uc->dsh) | 859 | if (NULL != uc->dsh) |
858 | { | 860 | { |
859 | GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); | 861 | GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); |
860 | uc->dsh = NULL; | 862 | uc->dsh = NULL; |
861 | } | 863 | } |
862 | if (NULL != uc->ksk_uri) | 864 | if (NULL != uc->ksk_uri) |
863 | { | 865 | { |
864 | GNUNET_FS_uri_destroy (uc->ksk_uri); | 866 | GNUNET_FS_uri_destroy(uc->ksk_uri); |
865 | uc->ksk_uri = NULL; | 867 | uc->ksk_uri = NULL; |
866 | } | 868 | } |
867 | if (NULL != uc->tc) | 869 | if (NULL != uc->tc) |
868 | { | 870 | { |
869 | GNUNET_FS_tree_encoder_finish (uc->tc, NULL); | 871 | GNUNET_FS_tree_encoder_finish(uc->tc, NULL); |
870 | uc->tc = NULL; | 872 | uc->tc = NULL; |
871 | } | 873 | } |
872 | if (uc->fh != NULL) | 874 | if (uc->fh != NULL) |
873 | { | 875 | { |
874 | GNUNET_DISK_file_close (uc->fh); | 876 | GNUNET_DISK_file_close(uc->fh); |
875 | uc->fh = NULL; | 877 | uc->fh = NULL; |
876 | } | 878 | } |
877 | GNUNET_FS_end_top (uc->h, uc->top); | 879 | GNUNET_FS_end_top(uc->h, uc->top); |
878 | if (uc->serialization != NULL) | 880 | if (uc->serialization != NULL) |
879 | { | 881 | { |
880 | GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 882 | GNUNET_FS_remove_sync_file_(uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
881 | uc->serialization); | 883 | uc->serialization); |
882 | GNUNET_free (uc->serialization); | 884 | GNUNET_free(uc->serialization); |
883 | uc->serialization = NULL; | 885 | uc->serialization = NULL; |
884 | } | 886 | } |
885 | pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; | 887 | pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; |
886 | pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; | 888 | pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; |
887 | GNUNET_FS_unindex_make_status_ (&pi, uc, | 889 | GNUNET_FS_unindex_make_status_(&pi, uc, |
888 | (uc->state == | 890 | (uc->state == |
889 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); | 891 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); |
890 | GNUNET_break (NULL == uc->client_info); | 892 | GNUNET_break(NULL == uc->client_info); |
891 | GNUNET_free_non_null (uc->emsg); | 893 | GNUNET_free_non_null(uc->emsg); |
892 | GNUNET_free (uc->filename); | 894 | GNUNET_free(uc->filename); |
893 | GNUNET_free (uc); | 895 | GNUNET_free(uc); |
894 | } | 896 | } |
895 | 897 | ||
896 | /* end of fs_unindex.c */ | 898 | /* end of fs_unindex.c */ |
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 5a67afbc0..c9ce19114 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_uri.c | 22 | * @file fs/fs_uri.c |
@@ -100,43 +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 | case GNUNET_FS_URI_SKS: | ||
112 | GNUNET_CRYPTO_hash (uri->data.sks.identifier, | ||
113 | strlen (uri->data.sks.identifier), | ||
114 | key); | ||
115 | return GNUNET_OK; | ||
116 | case GNUNET_FS_URI_KSK: | ||
117 | if (uri->data.ksk.keywordCount > 0) | ||
118 | { | 107 | { |
119 | GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], | 108 | case GNUNET_FS_URI_CHK: |
120 | strlen (uri->data.ksk.keywords[0]), | 109 | *key = uri->data.chk.chk.query; |
121 | key); | ||
122 | return GNUNET_OK; | 110 | return GNUNET_OK; |
123 | } | 111 | |
124 | else | 112 | case GNUNET_FS_URI_SKS: |
125 | { | 113 | GNUNET_CRYPTO_hash(uri->data.sks.identifier, |
126 | memset (key, 0, sizeof (struct GNUNET_HashCode)); | 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) | ||
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)); | ||
127 | return GNUNET_SYSERR; | 142 | return GNUNET_SYSERR; |
128 | } | 143 | } |
129 | break; | ||
130 | case GNUNET_FS_URI_LOC: | ||
131 | GNUNET_CRYPTO_hash (&uri->data.loc.fi, | ||
132 | sizeof (struct FileIdentifier) + | ||
133 | sizeof (struct GNUNET_PeerIdentity), | ||
134 | key); | ||
135 | return GNUNET_OK; | ||
136 | default: | ||
137 | memset (key, 0, sizeof (struct GNUNET_HashCode)); | ||
138 | return GNUNET_SYSERR; | ||
139 | } | ||
140 | } | 144 | } |
141 | 145 | ||
142 | 146 | ||
@@ -148,7 +152,7 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, | |||
148 | * @return string with the keywords | 152 | * @return string with the keywords |
149 | */ | 153 | */ |
150 | char * | 154 | char * |
151 | 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) |
152 | { | 156 | { |
153 | size_t n; | 157 | size_t n; |
154 | char *ret; | 158 | char *ret; |
@@ -158,45 +162,45 @@ GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri) | |||
158 | unsigned int keywordCount; | 162 | unsigned int keywordCount; |
159 | 163 | ||
160 | if ((NULL == uri) || (GNUNET_FS_URI_KSK != uri->type)) | 164 | if ((NULL == uri) || (GNUNET_FS_URI_KSK != uri->type)) |
161 | { | 165 | { |
162 | GNUNET_break (0); | 166 | GNUNET_break(0); |
163 | return NULL; | 167 | return NULL; |
164 | } | 168 | } |
165 | keywords = uri->data.ksk.keywords; | 169 | keywords = uri->data.ksk.keywords; |
166 | keywordCount = uri->data.ksk.keywordCount; | 170 | keywordCount = uri->data.ksk.keywordCount; |
167 | n = keywordCount + 1; | 171 | n = keywordCount + 1; |
168 | for (i = 0; i < keywordCount; i++) | 172 | for (i = 0; i < keywordCount; i++) |
169 | { | ||
170 | keyword = keywords[i]; | ||
171 | n += strlen (keyword) - 1; | ||
172 | if (NULL != strstr (&keyword[1], " ")) | ||
173 | n += 2; | ||
174 | if (keyword[0] == '+') | ||
175 | n++; | ||
176 | } | ||
177 | ret = GNUNET_malloc (n); | ||
178 | strcpy (ret, ""); | ||
179 | for (i = 0; i < keywordCount; i++) | ||
180 | { | ||
181 | keyword = keywords[i]; | ||
182 | if (NULL != strstr (&keyword[1], " ")) | ||
183 | { | 173 | { |
184 | strcat (ret, "\""); | 174 | keyword = keywords[i]; |
175 | n += strlen(keyword) - 1; | ||
176 | if (NULL != strstr(&keyword[1], " ")) | ||
177 | n += 2; | ||
185 | if (keyword[0] == '+') | 178 | if (keyword[0] == '+') |
186 | strcat (ret, keyword); | 179 | n++; |
187 | else | ||
188 | strcat (ret, &keyword[1]); | ||
189 | strcat (ret, "\""); | ||
190 | } | 180 | } |
191 | else | 181 | ret = GNUNET_malloc(n); |
182 | strcpy(ret, ""); | ||
183 | for (i = 0; i < keywordCount; i++) | ||
192 | { | 184 | { |
193 | if (keyword[0] == '+') | 185 | keyword = keywords[i]; |
194 | strcat (ret, keyword); | 186 | if (NULL != strstr(&keyword[1], " ")) |
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 | 195 | else |
196 | strcat (ret, &keyword[1]); | 196 | { |
197 | if (keyword[0] == '+') | ||
198 | strcat(ret, keyword); | ||
199 | else | ||
200 | strcat(ret, &keyword[1]); | ||
201 | } | ||
202 | strcat(ret, " "); | ||
197 | } | 203 | } |
198 | strcat (ret, " "); | ||
199 | } | ||
200 | return ret; | 204 | return ret; |
201 | } | 205 | } |
202 | 206 | ||
@@ -212,7 +216,7 @@ GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri) | |||
212 | * @return decodded string with leading space (or preserved plus) | 216 | * @return decodded string with leading space (or preserved plus) |
213 | */ | 217 | */ |
214 | static char * | 218 | static char * |
215 | percent_decode_keyword (const char *in, char **emsg) | 219 | percent_decode_keyword(const char *in, char **emsg) |
216 | { | 220 | { |
217 | char *out; | 221 | char *out; |
218 | char *ret; | 222 | char *ret; |
@@ -220,44 +224,44 @@ percent_decode_keyword (const char *in, char **emsg) | |||
220 | unsigned int wpos; | 224 | unsigned int wpos; |
221 | unsigned int hx; | 225 | unsigned int hx; |
222 | 226 | ||
223 | out = GNUNET_strdup (in); | 227 | out = GNUNET_strdup(in); |
224 | rpos = 0; | 228 | rpos = 0; |
225 | wpos = 0; | 229 | wpos = 0; |
226 | while (out[rpos] != '\0') | 230 | while (out[rpos] != '\0') |
227 | { | ||
228 | if (out[rpos] == '%') | ||
229 | { | ||
230 | if (1 != sscanf (&out[rpos + 1], "%2X", &hx)) | ||
231 | { | ||
232 | GNUNET_free (out); | ||
233 | *emsg = GNUNET_strdup ( | ||
234 | _ (/* xgettext:no-c-format */ | ||
235 | "Malformed KSK URI (`%' must be followed by HEX number)")); | ||
236 | return NULL; | ||
237 | } | ||
238 | rpos += 3; | ||
239 | if (hx == '"') | ||
240 | continue; /* skip double quote */ | ||
241 | out[wpos++] = (char) hx; | ||
242 | } | ||
243 | else | ||
244 | { | 231 | { |
245 | out[wpos++] = out[rpos++]; | 232 | if (out[rpos] == '%') |
233 | { | ||
234 | if (1 != sscanf(&out[rpos + 1], "%2X", &hx)) | ||
235 | { | ||
236 | GNUNET_free(out); | ||
237 | *emsg = GNUNET_strdup( | ||
238 | _(/* xgettext:no-c-format */ | ||
239 | "Malformed KSK URI (`%' must be followed by HEX number)")); | ||
240 | return NULL; | ||
241 | } | ||
242 | rpos += 3; | ||
243 | if (hx == '"') | ||
244 | continue; /* skip double quote */ | ||
245 | out[wpos++] = (char)hx; | ||
246 | } | ||
247 | else | ||
248 | { | ||
249 | out[wpos++] = out[rpos++]; | ||
250 | } | ||
246 | } | 251 | } |
247 | } | ||
248 | out[wpos] = '\0'; | 252 | out[wpos] = '\0'; |
249 | if (out[0] == '+') | 253 | if (out[0] == '+') |
250 | { | 254 | { |
251 | ret = GNUNET_strdup (out); | 255 | ret = GNUNET_strdup(out); |
252 | } | 256 | } |
253 | else | 257 | else |
254 | { | 258 | { |
255 | /* need to prefix with space */ | 259 | /* need to prefix with space */ |
256 | ret = GNUNET_malloc (strlen (out) + 2); | 260 | ret = GNUNET_malloc(strlen(out) + 2); |
257 | strcpy (ret, " "); | 261 | strcpy(ret, " "); |
258 | strcat (ret, out); | 262 | strcat(ret, out); |
259 | } | 263 | } |
260 | GNUNET_free (out); | 264 | GNUNET_free(out); |
261 | return ret; | 265 | return ret; |
262 | } | 266 | } |
263 | 267 | ||
@@ -271,7 +275,7 @@ percent_decode_keyword (const char *in, char **emsg) | |||
271 | * @return NULL on error, otherwise the KSK URI | 275 | * @return NULL on error, otherwise the KSK URI |
272 | */ | 276 | */ |
273 | static struct GNUNET_FS_Uri * | 277 | static struct GNUNET_FS_Uri * |
274 | uri_ksk_parse (const char *s, char **emsg) | 278 | uri_ksk_parse(const char *s, char **emsg) |
275 | { | 279 | { |
276 | struct GNUNET_FS_Uri *ret; | 280 | struct GNUNET_FS_Uri *ret; |
277 | char **keywords; | 281 | char **keywords; |
@@ -283,74 +287,74 @@ uri_ksk_parse (const char *s, char **emsg) | |||
283 | char *dup; | 287 | char *dup; |
284 | int saw_quote; | 288 | int saw_quote; |
285 | 289 | ||
286 | slen = strlen (s); | 290 | slen = strlen(s); |
287 | pos = strlen (GNUNET_FS_URI_KSK_PREFIX); | 291 | pos = strlen(GNUNET_FS_URI_KSK_PREFIX); |
288 | 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))) |
289 | return NULL; /* not KSK URI */ | 293 | return NULL; /* not KSK URI */ |
290 | if ((s[slen - 1] == '+') || (s[pos] == '+')) | 294 | if ((s[slen - 1] == '+') || (s[pos] == '+')) |
291 | { | 295 | { |
292 | *emsg = | 296 | *emsg = |
293 | GNUNET_strdup (_ ("Malformed KSK URI (must not begin or end with `+')")); | 297 | GNUNET_strdup(_("Malformed KSK URI (must not begin or end with `+')")); |
294 | return NULL; | 298 | return NULL; |
295 | } | 299 | } |
296 | max = 1; | 300 | max = 1; |
297 | saw_quote = 0; | 301 | saw_quote = 0; |
298 | for (i = pos; i < slen; i++) | 302 | for (i = pos; i < slen; i++) |
299 | { | ||
300 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) | ||
301 | { | ||
302 | saw_quote = (saw_quote + 1) % 2; | ||
303 | i += 3; | ||
304 | continue; | ||
305 | } | ||
306 | if ((s[i] == '+') && (saw_quote == 0)) | ||
307 | { | 303 | { |
308 | max++; | 304 | if ((s[i] == '%') && (&s[i] == strstr(&s[i], "%22"))) |
309 | if (s[i - 1] == '+') | 305 | { |
310 | { | 306 | saw_quote = (saw_quote + 1) % 2; |
311 | *emsg = GNUNET_strdup (_ ("Malformed KSK URI (`++' not allowed)")); | 307 | i += 3; |
312 | return NULL; | 308 | continue; |
313 | } | 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 | } | ||
314 | } | 319 | } |
315 | } | ||
316 | if (saw_quote == 1) | 320 | if (saw_quote == 1) |
317 | { | ||
318 | *emsg = GNUNET_strdup (_ ("Malformed KSK URI (quotes not balanced)")); | ||
319 | return NULL; | ||
320 | } | ||
321 | iret = max; | ||
322 | dup = GNUNET_strdup (s); | ||
323 | keywords = GNUNET_new_array (max, char *); | ||
324 | for (i = slen - 1; i >= (int) pos; i--) | ||
325 | { | ||
326 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) | ||
327 | { | 321 | { |
328 | saw_quote = (saw_quote + 1) % 2; | 322 | *emsg = GNUNET_strdup(_("Malformed KSK URI (quotes not balanced)")); |
329 | continue; | 323 | return NULL; |
330 | } | 324 | } |
331 | if ((dup[i] == '+') && (saw_quote == 0)) | 325 | iret = max; |
326 | dup = GNUNET_strdup(s); | ||
327 | keywords = GNUNET_new_array(max, char *); | ||
328 | for (i = slen - 1; i >= (int)pos; i--) | ||
332 | { | 329 | { |
333 | keywords[--max] = percent_decode_keyword (&dup[i + 1], emsg); | 330 | if ((s[i] == '%') && (&s[i] == strstr(&s[i], "%22"))) |
334 | if (NULL == keywords[max]) | 331 | { |
335 | goto CLEANUP; | 332 | saw_quote = (saw_quote + 1) % 2; |
336 | dup[i] = '\0'; | 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 | } | ||
337 | } | 342 | } |
338 | } | 343 | keywords[--max] = percent_decode_keyword(&dup[pos], emsg); |
339 | keywords[--max] = percent_decode_keyword (&dup[pos], emsg); | ||
340 | if (NULL == keywords[max]) | 344 | if (NULL == keywords[max]) |
341 | goto CLEANUP; | 345 | goto CLEANUP; |
342 | GNUNET_assert (0 == max); | 346 | GNUNET_assert(0 == max); |
343 | GNUNET_free (dup); | 347 | GNUNET_free(dup); |
344 | ret = GNUNET_new (struct GNUNET_FS_Uri); | 348 | ret = GNUNET_new(struct GNUNET_FS_Uri); |
345 | ret->type = GNUNET_FS_URI_KSK; | 349 | ret->type = GNUNET_FS_URI_KSK; |
346 | ret->data.ksk.keywordCount = iret; | 350 | ret->data.ksk.keywordCount = iret; |
347 | ret->data.ksk.keywords = keywords; | 351 | ret->data.ksk.keywords = keywords; |
348 | return ret; | 352 | return ret; |
349 | CLEANUP: | 353 | CLEANUP: |
350 | for (i = 0; i < max; i++) | 354 | for (i = 0; i < max; i++) |
351 | GNUNET_free_non_null (keywords[i]); | 355 | GNUNET_free_non_null(keywords[i]); |
352 | GNUNET_free (keywords); | 356 | GNUNET_free(keywords); |
353 | GNUNET_free (dup); | 357 | GNUNET_free(dup); |
354 | return NULL; | 358 | return NULL; |
355 | } | 359 | } |
356 | 360 | ||
@@ -365,31 +369,31 @@ CLEANUP: | |||
365 | * @return NULL on error, SKS URI otherwise | 369 | * @return NULL on error, SKS URI otherwise |
366 | */ | 370 | */ |
367 | static struct GNUNET_FS_Uri * | 371 | static struct GNUNET_FS_Uri * |
368 | uri_sks_parse (const char *s, char **emsg) | 372 | uri_sks_parse(const char *s, char **emsg) |
369 | { | 373 | { |
370 | struct GNUNET_FS_Uri *ret; | 374 | struct GNUNET_FS_Uri *ret; |
371 | struct GNUNET_CRYPTO_EcdsaPublicKey ns; | 375 | struct GNUNET_CRYPTO_EcdsaPublicKey ns; |
372 | size_t pos; | 376 | size_t pos; |
373 | char *end; | 377 | char *end; |
374 | 378 | ||
375 | pos = strlen (GNUNET_FS_URI_SKS_PREFIX); | 379 | pos = strlen(GNUNET_FS_URI_SKS_PREFIX); |
376 | 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))) |
377 | return NULL; /* not an SKS URI */ | 381 | return NULL; /* not an SKS URI */ |
378 | end = strchr (&s[pos], '/'); | 382 | end = strchr(&s[pos], '/'); |
379 | if ((NULL == end) || | 383 | if ((NULL == end) || |
380 | (GNUNET_OK != GNUNET_STRINGS_string_to_data (&s[pos], | 384 | (GNUNET_OK != GNUNET_STRINGS_string_to_data(&s[pos], |
381 | end - &s[pos], | 385 | end - &s[pos], |
382 | &ns, | 386 | &ns, |
383 | sizeof (ns)))) | 387 | sizeof(ns)))) |
384 | { | 388 | { |
385 | *emsg = GNUNET_strdup (_ ("Malformed SKS URI (wrong syntax)")); | 389 | *emsg = GNUNET_strdup(_("Malformed SKS URI (wrong syntax)")); |
386 | return NULL; /* malformed */ | 390 | return NULL; /* malformed */ |
387 | } | 391 | } |
388 | end++; /* skip over '/' */ | 392 | end++; /* skip over '/' */ |
389 | ret = GNUNET_new (struct GNUNET_FS_Uri); | 393 | ret = GNUNET_new(struct GNUNET_FS_Uri); |
390 | ret->type = GNUNET_FS_URI_SKS; | 394 | ret->type = GNUNET_FS_URI_SKS; |
391 | ret->data.sks.ns = ns; | 395 | ret->data.sks.ns = ns; |
392 | ret->data.sks.identifier = GNUNET_strdup (end); | 396 | ret->data.sks.identifier = GNUNET_strdup(end); |
393 | return ret; | 397 | return ret; |
394 | } | 398 | } |
395 | 399 | ||
@@ -404,46 +408,46 @@ uri_sks_parse (const char *s, char **emsg) | |||
404 | * @return NULL on error, CHK URI otherwise | 408 | * @return NULL on error, CHK URI otherwise |
405 | */ | 409 | */ |
406 | static struct GNUNET_FS_Uri * | 410 | static struct GNUNET_FS_Uri * |
407 | uri_chk_parse (const char *s, char **emsg) | 411 | uri_chk_parse(const char *s, char **emsg) |
408 | { | 412 | { |
409 | struct GNUNET_FS_Uri *ret; | 413 | struct GNUNET_FS_Uri *ret; |
410 | struct FileIdentifier fi; | 414 | struct FileIdentifier fi; |
411 | unsigned int pos; | 415 | unsigned int pos; |
412 | unsigned long long flen; | 416 | unsigned long long flen; |
413 | size_t slen; | 417 | size_t slen; |
414 | char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 418 | char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
415 | char h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 419 | char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
416 | 420 | ||
417 | slen = strlen (s); | 421 | slen = strlen(s); |
418 | pos = strlen (GNUNET_FS_URI_CHK_PREFIX); | 422 | pos = strlen(GNUNET_FS_URI_CHK_PREFIX); |
419 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | 423 | if ((slen < pos + 2 * sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || |
420 | (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos))) | 424 | (0 != strncmp(s, GNUNET_FS_URI_CHK_PREFIX, pos))) |
421 | return NULL; /* not a CHK URI */ | 425 | return NULL; /* not a CHK URI */ |
422 | if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || | 426 | if ((s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || |
423 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) | 427 | (s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) |
424 | { | 428 | { |
425 | *emsg = GNUNET_strdup (_ ("Malformed CHK URI (wrong syntax)")); | 429 | *emsg = GNUNET_strdup(_("Malformed CHK URI (wrong syntax)")); |
426 | return NULL; | 430 | return NULL; |
427 | } | 431 | } |
428 | GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 432 | GNUNET_memcpy(h1, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); |
429 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 433 | h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
430 | GNUNET_memcpy (h2, | 434 | GNUNET_memcpy(h2, |
431 | &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], | 435 | &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], |
432 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 436 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); |
433 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 437 | h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
434 | 438 | ||
435 | 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)) || |
436 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) || | 440 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h2, &fi.chk.query)) || |
437 | (1 != | 441 | (1 != |
438 | sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | 442 | sscanf(&s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], |
439 | "%llu", | 443 | "%llu", |
440 | &flen))) | 444 | &flen))) |
441 | { | 445 | { |
442 | *emsg = GNUNET_strdup (_ ("Malformed CHK URI (failed to decode CHK)")); | 446 | *emsg = GNUNET_strdup(_("Malformed CHK URI (failed to decode CHK)")); |
443 | return NULL; | 447 | return NULL; |
444 | } | 448 | } |
445 | fi.file_length = GNUNET_htonll (flen); | 449 | fi.file_length = GNUNET_htonll(flen); |
446 | ret = GNUNET_new (struct GNUNET_FS_Uri); | 450 | ret = GNUNET_new(struct GNUNET_FS_Uri); |
447 | ret->type = GNUNET_FS_URI_CHK; | 451 | ret->type = GNUNET_FS_URI_CHK; |
448 | ret->data.chk = fi; | 452 | ret->data.chk = fi; |
449 | return ret; | 453 | return ret; |
@@ -456,8 +460,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
456 | * 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 |
457 | * URI. | 461 | * URI. |
458 | */ | 462 | */ |
459 | struct LocUriAssembly | 463 | struct LocUriAssembly { |
460 | { | ||
461 | /** | 464 | /** |
462 | * What is being signed (rest of this struct). | 465 | * What is being signed (rest of this struct). |
463 | */ | 466 | */ |
@@ -494,11 +497,11 @@ GNUNET_NETWORK_STRUCT_END | |||
494 | * @return NULL on error, valid LOC URI otherwise | 497 | * @return NULL on error, valid LOC URI otherwise |
495 | */ | 498 | */ |
496 | static struct GNUNET_FS_Uri * | 499 | static struct GNUNET_FS_Uri * |
497 | uri_loc_parse (const char *s, char **emsg) | 500 | uri_loc_parse(const char *s, char **emsg) |
498 | { | 501 | { |
499 | struct GNUNET_FS_Uri *uri; | 502 | struct GNUNET_FS_Uri *uri; |
500 | char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 503 | char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
501 | char h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 504 | char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
502 | unsigned int pos; | 505 | unsigned int pos; |
503 | unsigned int npos; | 506 | unsigned int npos; |
504 | unsigned long long exptime; | 507 | unsigned long long exptime; |
@@ -508,113 +511,113 @@ uri_loc_parse (const char *s, char **emsg) | |||
508 | struct LocUriAssembly ass; | 511 | struct LocUriAssembly ass; |
509 | size_t slen; | 512 | size_t slen; |
510 | 513 | ||
511 | slen = strlen (s); | 514 | slen = strlen(s); |
512 | pos = strlen (GNUNET_FS_URI_LOC_PREFIX); | 515 | pos = strlen(GNUNET_FS_URI_LOC_PREFIX); |
513 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | 516 | if ((slen < pos + 2 * sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || |
514 | (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos))) | 517 | (0 != strncmp(s, GNUNET_FS_URI_LOC_PREFIX, pos))) |
515 | return NULL; /* not a LOC URI */ | 518 | return NULL; /* not a LOC URI */ |
516 | if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || | 519 | if ((s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || |
517 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) | 520 | (s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) |
518 | { | 521 | { |
519 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (wrong syntax)")); | 522 | *emsg = GNUNET_strdup(_("LOC URI malformed (wrong syntax)")); |
520 | return NULL; | 523 | return NULL; |
521 | } | 524 | } |
522 | GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 525 | GNUNET_memcpy(h1, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); |
523 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 526 | h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
524 | GNUNET_memcpy (h2, | 527 | GNUNET_memcpy(h2, |
525 | &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], | 528 | &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], |
526 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 529 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); |
527 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 530 | h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
528 | 531 | ||
529 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) || | 532 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h1, &ass.fi.chk.key)) || |
530 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) || | 533 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h2, &ass.fi.chk.query)) || |
531 | (1 != | 534 | (1 != |
532 | sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | 535 | sscanf(&s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], |
533 | "%llu", | 536 | "%llu", |
534 | &flen))) | 537 | &flen))) |
535 | { | 538 | { |
536 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (no CHK)")); | 539 | *emsg = GNUNET_strdup(_("LOC URI malformed (no CHK)")); |
537 | return NULL; | 540 | return NULL; |
538 | } | 541 | } |
539 | ass.fi.file_length = GNUNET_htonll (flen); | 542 | ass.fi.file_length = GNUNET_htonll(flen); |
540 | 543 | ||
541 | npos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2; | 544 | npos = pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2; |
542 | while ((s[npos] != '\0') && (s[npos] != '.')) | 545 | while ((s[npos] != '\0') && (s[npos] != '.')) |
543 | npos++; | 546 | npos++; |
544 | if (s[npos] == '\0') | 547 | if (s[npos] == '\0') |
545 | { | 548 | { |
546 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (missing LOC)")); | 549 | *emsg = GNUNET_strdup(_("LOC URI malformed (missing LOC)")); |
547 | goto ERR; | 550 | goto ERR; |
548 | } | 551 | } |
549 | npos++; | 552 | npos++; |
550 | if ((strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || | 553 | if ((strlen(&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || |
551 | ('.' != s[npos + GNUNET_CRYPTO_PKEY_ASCII_LENGTH])) | 554 | ('.' != s[npos + GNUNET_CRYPTO_PKEY_ASCII_LENGTH])) |
552 | { | 555 | { |
553 | *emsg = | 556 | *emsg = |
554 | GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for public key)")); | 557 | GNUNET_strdup(_("LOC URI malformed (wrong syntax for public key)")); |
555 | } | 558 | } |
556 | if ( | 559 | if ( |
557 | GNUNET_OK != | 560 | GNUNET_OK != |
558 | GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos], | 561 | GNUNET_CRYPTO_eddsa_public_key_from_string(&s[npos], |
559 | GNUNET_CRYPTO_PKEY_ASCII_LENGTH, | 562 | GNUNET_CRYPTO_PKEY_ASCII_LENGTH, |
560 | &ass.peer.public_key)) | 563 | &ass.peer.public_key)) |
561 | { | 564 | { |
562 | *emsg = | 565 | *emsg = |
563 | GNUNET_strdup (_ ("LOC URI malformed (could not decode public key)")); | 566 | GNUNET_strdup(_("LOC URI malformed (could not decode public key)")); |
564 | goto ERR; | 567 | goto ERR; |
565 | } | 568 | } |
566 | npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; | 569 | npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; |
567 | if (s[npos++] != '.') | 570 | if (s[npos++] != '.') |
568 | { | 571 | { |
569 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (could not find signature)")); | 572 | *emsg = GNUNET_strdup(_("LOC URI malformed (could not find signature)")); |
570 | goto ERR; | 573 | goto ERR; |
571 | } | 574 | } |
572 | if ((strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || | 575 | if ((strlen(&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || |
573 | ('.' != s[npos + SIGNATURE_ASCII_LENGTH])) | 576 | ('.' != s[npos + SIGNATURE_ASCII_LENGTH])) |
574 | { | 577 | { |
575 | *emsg = | 578 | *emsg = |
576 | GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for signature)")); | 579 | GNUNET_strdup(_("LOC URI malformed (wrong syntax for signature)")); |
577 | goto ERR; | 580 | goto ERR; |
578 | } | 581 | } |
579 | if (GNUNET_OK != | 582 | if (GNUNET_OK != |
580 | GNUNET_STRINGS_string_to_data (&s[npos], | 583 | GNUNET_STRINGS_string_to_data(&s[npos], |
581 | SIGNATURE_ASCII_LENGTH, | 584 | SIGNATURE_ASCII_LENGTH, |
582 | &sig, | 585 | &sig, |
583 | sizeof ( | 586 | sizeof( |
584 | struct GNUNET_CRYPTO_EddsaSignature))) | 587 | struct GNUNET_CRYPTO_EddsaSignature))) |
585 | { | 588 | { |
586 | *emsg = | 589 | *emsg = |
587 | GNUNET_strdup (_ ("LOC URI malformed (could not decode signature)")); | 590 | GNUNET_strdup(_("LOC URI malformed (could not decode signature)")); |
588 | goto ERR; | 591 | goto ERR; |
589 | } | 592 | } |
590 | npos += SIGNATURE_ASCII_LENGTH; | 593 | npos += SIGNATURE_ASCII_LENGTH; |
591 | if (s[npos++] != '.') | 594 | if (s[npos++] != '.') |
592 | { | 595 | { |
593 | *emsg = GNUNET_strdup ( | 596 | *emsg = GNUNET_strdup( |
594 | _ ("LOC URI malformed (wrong syntax for expiration time)")); | 597 | _("LOC URI malformed (wrong syntax for expiration time)")); |
595 | goto ERR; | 598 | goto ERR; |
596 | } | 599 | } |
597 | if (1 != sscanf (&s[npos], "%llu", &exptime)) | 600 | if (1 != sscanf(&s[npos], "%llu", &exptime)) |
598 | { | 601 | { |
599 | *emsg = | 602 | *emsg = |
600 | GNUNET_strdup (_ ("LOC URI malformed (could not parse expiration time)")); | 603 | GNUNET_strdup(_("LOC URI malformed (could not parse expiration time)")); |
601 | goto ERR; | 604 | goto ERR; |
602 | } | 605 | } |
603 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); | 606 | ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); |
604 | ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | 607 | ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); |
605 | et.abs_value_us = exptime * 1000LL * 1000LL; | 608 | et.abs_value_us = exptime * 1000LL * 1000LL; |
606 | ass.exptime = GNUNET_TIME_absolute_hton (et); | 609 | ass.exptime = GNUNET_TIME_absolute_hton(et); |
607 | if (GNUNET_OK != | 610 | if (GNUNET_OK != |
608 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, | 611 | GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, |
609 | &ass.purpose, | 612 | &ass.purpose, |
610 | &sig, | 613 | &sig, |
611 | &ass.peer.public_key)) | 614 | &ass.peer.public_key)) |
612 | { | 615 | { |
613 | *emsg = | 616 | *emsg = |
614 | GNUNET_strdup (_ ("LOC URI malformed (signature failed validation)")); | 617 | GNUNET_strdup(_("LOC URI malformed (signature failed validation)")); |
615 | goto ERR; | 618 | goto ERR; |
616 | } | 619 | } |
617 | uri = GNUNET_new (struct GNUNET_FS_Uri); | 620 | uri = GNUNET_new(struct GNUNET_FS_Uri); |
618 | uri->type = GNUNET_FS_URI_LOC; | 621 | uri->type = GNUNET_FS_URI_LOC; |
619 | uri->data.loc.fi = ass.fi; | 622 | uri->data.loc.fi = ass.fi; |
620 | uri->data.loc.peer = ass.peer; | 623 | uri->data.loc.peer = ass.peer; |
@@ -635,30 +638,30 @@ ERR: | |||
635 | * @return NULL on error | 638 | * @return NULL on error |
636 | */ | 639 | */ |
637 | struct GNUNET_FS_Uri * | 640 | struct GNUNET_FS_Uri * |
638 | GNUNET_FS_uri_parse (const char *uri, char **emsg) | 641 | GNUNET_FS_uri_parse(const char *uri, char **emsg) |
639 | { | 642 | { |
640 | struct GNUNET_FS_Uri *ret; | 643 | struct GNUNET_FS_Uri *ret; |
641 | char *msg; | 644 | char *msg; |
642 | 645 | ||
643 | if (NULL == uri) | 646 | if (NULL == uri) |
644 | { | 647 | { |
645 | GNUNET_break (0); | 648 | GNUNET_break(0); |
646 | if (NULL != emsg) | 649 | if (NULL != emsg) |
647 | *emsg = GNUNET_strdup (_ ("invalid argument")); | 650 | *emsg = GNUNET_strdup(_("invalid argument")); |
648 | return NULL; | 651 | return NULL; |
649 | } | 652 | } |
650 | if (NULL == emsg) | 653 | if (NULL == emsg) |
651 | emsg = &msg; | 654 | emsg = &msg; |
652 | *emsg = NULL; | 655 | *emsg = NULL; |
653 | if ((NULL != (ret = uri_chk_parse (uri, emsg))) || | 656 | if ((NULL != (ret = uri_chk_parse(uri, emsg))) || |
654 | (NULL != (ret = uri_ksk_parse (uri, emsg))) || | 657 | (NULL != (ret = uri_ksk_parse(uri, emsg))) || |
655 | (NULL != (ret = uri_sks_parse (uri, emsg))) || | 658 | (NULL != (ret = uri_sks_parse(uri, emsg))) || |
656 | (NULL != (ret = uri_loc_parse (uri, emsg)))) | 659 | (NULL != (ret = uri_loc_parse(uri, emsg)))) |
657 | return ret; | 660 | return ret; |
658 | if (NULL == *emsg) | 661 | if (NULL == *emsg) |
659 | *emsg = GNUNET_strdup (_ ("Unrecognized URI type")); | 662 | *emsg = GNUNET_strdup(_("Unrecognized URI type")); |
660 | if (emsg == &msg) | 663 | if (emsg == &msg) |
661 | GNUNET_free (msg); | 664 | GNUNET_free(msg); |
662 | return NULL; | 665 | return NULL; |
663 | } | 666 | } |
664 | 667 | ||
@@ -669,27 +672,30 @@ GNUNET_FS_uri_parse (const char *uri, char **emsg) | |||
669 | * @param uri uri to free | 672 | * @param uri uri to free |
670 | */ | 673 | */ |
671 | void | 674 | void |
672 | GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri) | 675 | GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri) |
673 | { | 676 | { |
674 | unsigned int i; | 677 | unsigned int i; |
675 | 678 | ||
676 | switch (uri->type) | 679 | switch (uri->type) |
677 | { | 680 | { |
678 | case GNUNET_FS_URI_KSK: | 681 | case GNUNET_FS_URI_KSK: |
679 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 682 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
680 | GNUNET_free (uri->data.ksk.keywords[i]); | 683 | GNUNET_free(uri->data.ksk.keywords[i]); |
681 | GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, 0); | 684 | GNUNET_array_grow(uri->data.ksk.keywords, uri->data.ksk.keywordCount, 0); |
682 | break; | 685 | break; |
683 | case GNUNET_FS_URI_SKS: | 686 | |
684 | GNUNET_free (uri->data.sks.identifier); | 687 | case GNUNET_FS_URI_SKS: |
685 | break; | 688 | GNUNET_free(uri->data.sks.identifier); |
686 | case GNUNET_FS_URI_LOC: | 689 | break; |
687 | break; | 690 | |
688 | default: | 691 | case GNUNET_FS_URI_LOC: |
689 | /* do nothing */ | 692 | break; |
690 | break; | 693 | |
691 | } | 694 | default: |
692 | GNUNET_free (uri); | 695 | /* do nothing */ |
696 | break; | ||
697 | } | ||
698 | GNUNET_free(uri); | ||
693 | } | 699 | } |
694 | 700 | ||
695 | 701 | ||
@@ -700,7 +706,7 @@ GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri) | |||
700 | * @return 0 if this is not a keyword URI | 706 | * @return 0 if this is not a keyword URI |
701 | */ | 707 | */ |
702 | unsigned int | 708 | unsigned int |
703 | GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri) | 709 | GNUNET_FS_uri_ksk_get_keyword_count(const struct GNUNET_FS_Uri *uri) |
704 | { | 710 | { |
705 | if (uri->type != GNUNET_FS_URI_KSK) | 711 | if (uri->type != GNUNET_FS_URI_KSK) |
706 | return 0; | 712 | return 0; |
@@ -718,9 +724,9 @@ GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri) | |||
718 | * keywords iterated over until iterator aborted | 724 | * keywords iterated over until iterator aborted |
719 | */ | 725 | */ |
720 | int | 726 | int |
721 | GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, | 727 | GNUNET_FS_uri_ksk_get_keywords(const struct GNUNET_FS_Uri *uri, |
722 | GNUNET_FS_KeywordIterator iterator, | 728 | GNUNET_FS_KeywordIterator iterator, |
723 | void *iterator_cls) | 729 | void *iterator_cls) |
724 | { | 730 | { |
725 | unsigned int i; | 731 | unsigned int i; |
726 | char *keyword; | 732 | char *keyword; |
@@ -730,13 +736,13 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, | |||
730 | if (NULL == iterator) | 736 | if (NULL == iterator) |
731 | return uri->data.ksk.keywordCount; | 737 | return uri->data.ksk.keywordCount; |
732 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 738 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
733 | { | 739 | { |
734 | keyword = uri->data.ksk.keywords[i]; | 740 | keyword = uri->data.ksk.keywords[i]; |
735 | /* first character of keyword indicates | 741 | /* first character of keyword indicates |
736 | * if it is mandatory or not */ | 742 | * if it is mandatory or not */ |
737 | if (GNUNET_OK != iterator (iterator_cls, &keyword[1], keyword[0] == '+')) | 743 | if (GNUNET_OK != iterator(iterator_cls, &keyword[1], keyword[0] == '+')) |
738 | return i; | 744 | return i; |
739 | } | 745 | } |
740 | return i; | 746 | return i; |
741 | } | 747 | } |
742 | 748 | ||
@@ -750,23 +756,23 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, | |||
750 | * @param is_mandatory is this keyword mandatory? | 756 | * @param is_mandatory is this keyword mandatory? |
751 | */ | 757 | */ |
752 | void | 758 | void |
753 | GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, | 759 | GNUNET_FS_uri_ksk_add_keyword(struct GNUNET_FS_Uri *uri, |
754 | const char *keyword, | 760 | const char *keyword, |
755 | int is_mandatory) | 761 | int is_mandatory) |
756 | { | 762 | { |
757 | unsigned int i; | 763 | unsigned int i; |
758 | const char *old; | 764 | const char *old; |
759 | char *n; | 765 | char *n; |
760 | 766 | ||
761 | GNUNET_assert (uri->type == GNUNET_FS_URI_KSK); | 767 | GNUNET_assert(uri->type == GNUNET_FS_URI_KSK); |
762 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 768 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
763 | { | 769 | { |
764 | old = uri->data.ksk.keywords[i]; | 770 | old = uri->data.ksk.keywords[i]; |
765 | if (0 == strcmp (&old[1], keyword)) | 771 | if (0 == strcmp(&old[1], keyword)) |
766 | return; | 772 | return; |
767 | } | 773 | } |
768 | GNUNET_asprintf (&n, is_mandatory ? "+%s" : " %s", keyword); | 774 | GNUNET_asprintf(&n, is_mandatory ? "+%s" : " %s", keyword); |
769 | GNUNET_array_append (uri->data.ksk.keywords, uri->data.ksk.keywordCount, n); | 775 | GNUNET_array_append(uri->data.ksk.keywords, uri->data.ksk.keywordCount, n); |
770 | } | 776 | } |
771 | 777 | ||
772 | 778 | ||
@@ -778,27 +784,27 @@ GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, | |||
778 | * @param keyword keyword to add | 784 | * @param keyword keyword to add |
779 | */ | 785 | */ |
780 | void | 786 | void |
781 | GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, | 787 | GNUNET_FS_uri_ksk_remove_keyword(struct GNUNET_FS_Uri *uri, |
782 | const char *keyword) | 788 | const char *keyword) |
783 | { | 789 | { |
784 | unsigned int i; | 790 | unsigned int i; |
785 | char *old; | 791 | char *old; |
786 | 792 | ||
787 | GNUNET_assert (uri->type == GNUNET_FS_URI_KSK); | 793 | GNUNET_assert(uri->type == GNUNET_FS_URI_KSK); |
788 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 794 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
789 | { | ||
790 | old = uri->data.ksk.keywords[i]; | ||
791 | if (0 == strcmp (&old[1], keyword)) | ||
792 | { | 795 | { |
793 | uri->data.ksk.keywords[i] = | 796 | old = uri->data.ksk.keywords[i]; |
794 | uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; | 797 | if (0 == strcmp(&old[1], keyword)) |
795 | GNUNET_array_grow (uri->data.ksk.keywords, | 798 | { |
796 | uri->data.ksk.keywordCount, | 799 | uri->data.ksk.keywords[i] = |
797 | uri->data.ksk.keywordCount - 1); | 800 | uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; |
798 | GNUNET_free (old); | 801 | GNUNET_array_grow(uri->data.ksk.keywords, |
799 | return; | 802 | uri->data.ksk.keywordCount, |
803 | uri->data.ksk.keywordCount - 1); | ||
804 | GNUNET_free(old); | ||
805 | return; | ||
806 | } | ||
800 | } | 807 | } |
801 | } | ||
802 | } | 808 | } |
803 | 809 | ||
804 | 810 | ||
@@ -810,8 +816,8 @@ GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, | |||
810 | * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK | 816 | * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK |
811 | */ | 817 | */ |
812 | int | 818 | int |
813 | GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri, | 819 | GNUNET_FS_uri_loc_get_peer_identity(const struct GNUNET_FS_Uri *uri, |
814 | struct GNUNET_PeerIdentity *peer) | 820 | struct GNUNET_PeerIdentity *peer) |
815 | { | 821 | { |
816 | if (uri->type != GNUNET_FS_URI_LOC) | 822 | if (uri->type != GNUNET_FS_URI_LOC) |
817 | return GNUNET_SYSERR; | 823 | return GNUNET_SYSERR; |
@@ -827,9 +833,9 @@ GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri, | |||
827 | * @return expiration time of the URI | 833 | * @return expiration time of the URI |
828 | */ | 834 | */ |
829 | struct GNUNET_TIME_Absolute | 835 | struct GNUNET_TIME_Absolute |
830 | GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri) | 836 | GNUNET_FS_uri_loc_get_expiration(const struct GNUNET_FS_Uri *uri) |
831 | { | 837 | { |
832 | GNUNET_assert (uri->type == GNUNET_FS_URI_LOC); | 838 | GNUNET_assert(uri->type == GNUNET_FS_URI_LOC); |
833 | return uri->data.loc.expirationTime; | 839 | return uri->data.loc.expirationTime; |
834 | } | 840 | } |
835 | 841 | ||
@@ -841,13 +847,13 @@ GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri) | |||
841 | * @return NULL if argument is not a location URI | 847 | * @return NULL if argument is not a location URI |
842 | */ | 848 | */ |
843 | struct GNUNET_FS_Uri * | 849 | struct GNUNET_FS_Uri * |
844 | GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri) | 850 | GNUNET_FS_uri_loc_get_uri(const struct GNUNET_FS_Uri *uri) |
845 | { | 851 | { |
846 | struct GNUNET_FS_Uri *ret; | 852 | struct GNUNET_FS_Uri *ret; |
847 | 853 | ||
848 | if (uri->type != GNUNET_FS_URI_LOC) | 854 | if (uri->type != GNUNET_FS_URI_LOC) |
849 | return NULL; | 855 | return NULL; |
850 | ret = GNUNET_new (struct GNUNET_FS_Uri); | 856 | ret = GNUNET_new(struct GNUNET_FS_Uri); |
851 | ret->type = GNUNET_FS_URI_CHK; | 857 | ret->type = GNUNET_FS_URI_CHK; |
852 | ret->data.chk = uri->data.loc.fi; | 858 | ret->data.chk = uri->data.loc.fi; |
853 | return ret; | 859 | return ret; |
@@ -867,9 +873,9 @@ GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri) | |||
867 | * @return the location URI, NULL on error | 873 | * @return the location URI, NULL on error |
868 | */ | 874 | */ |
869 | struct GNUNET_FS_Uri * | 875 | struct GNUNET_FS_Uri * |
870 | GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, | 876 | GNUNET_FS_uri_loc_create(const struct GNUNET_FS_Uri *base_uri, |
871 | const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key, | 877 | const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key, |
872 | struct GNUNET_TIME_Absolute expiration_time) | 878 | struct GNUNET_TIME_Absolute expiration_time) |
873 | { | 879 | { |
874 | struct GNUNET_FS_Uri *uri; | 880 | struct GNUNET_FS_Uri *uri; |
875 | struct GNUNET_CRYPTO_EddsaPublicKey my_public_key; | 881 | struct GNUNET_CRYPTO_EddsaPublicKey my_public_key; |
@@ -880,21 +886,21 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, | |||
880 | return NULL; | 886 | return NULL; |
881 | /* we round expiration time to full seconds for SKS URIs */ | 887 | /* we round expiration time to full seconds for SKS URIs */ |
882 | et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL; | 888 | et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL; |
883 | GNUNET_CRYPTO_eddsa_key_get_public (sign_key, &my_public_key); | 889 | GNUNET_CRYPTO_eddsa_key_get_public(sign_key, &my_public_key); |
884 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); | 890 | ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); |
885 | ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | 891 | ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); |
886 | ass.exptime = GNUNET_TIME_absolute_hton (et); | 892 | ass.exptime = GNUNET_TIME_absolute_hton(et); |
887 | ass.fi = base_uri->data.chk; | 893 | ass.fi = base_uri->data.chk; |
888 | ass.peer.public_key = my_public_key; | 894 | ass.peer.public_key = my_public_key; |
889 | uri = GNUNET_new (struct GNUNET_FS_Uri); | 895 | uri = GNUNET_new(struct GNUNET_FS_Uri); |
890 | uri->type = GNUNET_FS_URI_LOC; | 896 | uri->type = GNUNET_FS_URI_LOC; |
891 | uri->data.loc.fi = base_uri->data.chk; | 897 | uri->data.loc.fi = base_uri->data.chk; |
892 | uri->data.loc.expirationTime = et; | 898 | uri->data.loc.expirationTime = et; |
893 | uri->data.loc.peer.public_key = my_public_key; | 899 | uri->data.loc.peer.public_key = my_public_key; |
894 | GNUNET_assert (GNUNET_OK == | 900 | GNUNET_assert(GNUNET_OK == |
895 | GNUNET_CRYPTO_eddsa_sign (sign_key, | 901 | GNUNET_CRYPTO_eddsa_sign(sign_key, |
896 | &ass.purpose, | 902 | &ass.purpose, |
897 | &uri->data.loc.contentSignature)); | 903 | &uri->data.loc.contentSignature)); |
898 | return uri; | 904 | return uri; |
899 | } | 905 | } |
900 | 906 | ||
@@ -907,15 +913,15 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, | |||
907 | * @return an FS URI for the given namespace and identifier | 913 | * @return an FS URI for the given namespace and identifier |
908 | */ | 914 | */ |
909 | struct GNUNET_FS_Uri * | 915 | struct GNUNET_FS_Uri * |
910 | GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, | 916 | GNUNET_FS_uri_sks_create(const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, |
911 | const char *id) | 917 | const char *id) |
912 | { | 918 | { |
913 | struct GNUNET_FS_Uri *ns_uri; | 919 | struct GNUNET_FS_Uri *ns_uri; |
914 | 920 | ||
915 | ns_uri = GNUNET_new (struct GNUNET_FS_Uri); | 921 | ns_uri = GNUNET_new(struct GNUNET_FS_Uri); |
916 | ns_uri->type = GNUNET_FS_URI_SKS; | 922 | ns_uri->type = GNUNET_FS_URI_SKS; |
917 | ns_uri->data.sks.ns = *ns; | 923 | ns_uri->data.sks.ns = *ns; |
918 | ns_uri->data.sks.identifier = GNUNET_strdup (id); | 924 | ns_uri->data.sks.identifier = GNUNET_strdup(id); |
919 | return ns_uri; | 925 | return ns_uri; |
920 | } | 926 | } |
921 | 927 | ||
@@ -930,8 +936,8 @@ GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, | |||
930 | * @return merged URI, NULL on error | 936 | * @return merged URI, NULL on error |
931 | */ | 937 | */ |
932 | struct GNUNET_FS_Uri * | 938 | struct GNUNET_FS_Uri * |
933 | GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, | 939 | GNUNET_FS_uri_ksk_merge(const struct GNUNET_FS_Uri *u1, |
934 | const struct GNUNET_FS_Uri *u2) | 940 | const struct GNUNET_FS_Uri *u2) |
935 | { | 941 | { |
936 | struct GNUNET_FS_Uri *ret; | 942 | struct GNUNET_FS_Uri *ret; |
937 | unsigned int kc; | 943 | unsigned int kc; |
@@ -944,34 +950,34 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, | |||
944 | if ((u1 == NULL) && (u2 == NULL)) | 950 | if ((u1 == NULL) && (u2 == NULL)) |
945 | return NULL; | 951 | return NULL; |
946 | if (u1 == NULL) | 952 | if (u1 == NULL) |
947 | return GNUNET_FS_uri_dup (u2); | 953 | return GNUNET_FS_uri_dup(u2); |
948 | if (u2 == NULL) | 954 | if (u2 == NULL) |
949 | return GNUNET_FS_uri_dup (u1); | 955 | return GNUNET_FS_uri_dup(u1); |
950 | if ((u1->type != GNUNET_FS_URI_KSK) || (u2->type != GNUNET_FS_URI_KSK)) | 956 | if ((u1->type != GNUNET_FS_URI_KSK) || (u2->type != GNUNET_FS_URI_KSK)) |
951 | { | 957 | { |
952 | GNUNET_break (0); | 958 | GNUNET_break(0); |
953 | return NULL; | 959 | return NULL; |
954 | } | 960 | } |
955 | kc = u1->data.ksk.keywordCount; | 961 | kc = u1->data.ksk.keywordCount; |
956 | kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, char *); | 962 | kl = GNUNET_new_array(kc + u2->data.ksk.keywordCount, char *); |
957 | for (i = 0; i < u1->data.ksk.keywordCount; i++) | 963 | for (i = 0; i < u1->data.ksk.keywordCount; i++) |
958 | kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]); | 964 | kl[i] = GNUNET_strdup(u1->data.ksk.keywords[i]); |
959 | for (i = 0; i < u2->data.ksk.keywordCount; i++) | 965 | for (i = 0; i < u2->data.ksk.keywordCount; i++) |
960 | { | 966 | { |
961 | kp = u2->data.ksk.keywords[i]; | 967 | kp = u2->data.ksk.keywords[i]; |
962 | found = 0; | 968 | found = 0; |
963 | for (j = 0; j < u1->data.ksk.keywordCount; j++) | 969 | for (j = 0; j < u1->data.ksk.keywordCount; j++) |
964 | if (0 == strcmp (kp + 1, kl[j] + 1)) | 970 | if (0 == strcmp(kp + 1, kl[j] + 1)) |
965 | { | 971 | { |
966 | found = 1; | 972 | found = 1; |
967 | if (kp[0] == '+') | 973 | if (kp[0] == '+') |
968 | kl[j][0] = '+'; | 974 | kl[j][0] = '+'; |
969 | break; | 975 | break; |
970 | } | 976 | } |
971 | if (0 == found) | 977 | if (0 == found) |
972 | kl[kc++] = GNUNET_strdup (kp); | 978 | kl[kc++] = GNUNET_strdup(kp); |
973 | } | 979 | } |
974 | ret = GNUNET_new (struct GNUNET_FS_Uri); | 980 | ret = GNUNET_new(struct GNUNET_FS_Uri); |
975 | ret->type = GNUNET_FS_URI_KSK; | 981 | ret->type = GNUNET_FS_URI_KSK; |
976 | ret->data.ksk.keywordCount = kc; | 982 | ret->data.ksk.keywordCount = kc; |
977 | ret->data.ksk.keywords = kl; | 983 | ret->data.ksk.keywords = kl; |
@@ -986,43 +992,46 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, | |||
986 | * @return copy of the URI | 992 | * @return copy of the URI |
987 | */ | 993 | */ |
988 | struct GNUNET_FS_Uri * | 994 | struct GNUNET_FS_Uri * |
989 | GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) | 995 | GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri) |
990 | { | 996 | { |
991 | struct GNUNET_FS_Uri *ret; | 997 | struct GNUNET_FS_Uri *ret; |
992 | unsigned int i; | 998 | unsigned int i; |
993 | 999 | ||
994 | if (uri == NULL) | 1000 | if (uri == NULL) |
995 | return NULL; | 1001 | return NULL; |
996 | ret = GNUNET_new (struct GNUNET_FS_Uri); | 1002 | ret = GNUNET_new(struct GNUNET_FS_Uri); |
997 | GNUNET_memcpy (ret, uri, sizeof (struct GNUNET_FS_Uri)); | 1003 | GNUNET_memcpy(ret, uri, sizeof(struct GNUNET_FS_Uri)); |
998 | switch (ret->type) | 1004 | switch (ret->type) |
999 | { | ||
1000 | case GNUNET_FS_URI_KSK: | ||
1001 | if (ret->data.ksk.keywordCount >= | ||
1002 | GNUNET_MAX_MALLOC_CHECKED / sizeof (char *)) | ||
1003 | { | 1005 | { |
1004 | GNUNET_break (0); | 1006 | case GNUNET_FS_URI_KSK: |
1005 | GNUNET_free (ret); | 1007 | if (ret->data.ksk.keywordCount >= |
1006 | return NULL; | 1008 | GNUNET_MAX_MALLOC_CHECKED / sizeof(char *)) |
1007 | } | 1009 | { |
1008 | if (ret->data.ksk.keywordCount > 0) | 1010 | GNUNET_break(0); |
1009 | { | 1011 | GNUNET_free(ret); |
1010 | ret->data.ksk.keywords = | 1012 | return NULL; |
1011 | GNUNET_new_array (ret->data.ksk.keywordCount, char *); | 1013 | } |
1012 | for (i = 0; i < ret->data.ksk.keywordCount; i++) | 1014 | if (ret->data.ksk.keywordCount > 0) |
1013 | ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); | 1015 | { |
1016 | ret->data.ksk.keywords = | ||
1017 | GNUNET_new_array(ret->data.ksk.keywordCount, char *); | ||
1018 | for (i = 0; i < ret->data.ksk.keywordCount; i++) | ||
1019 | ret->data.ksk.keywords[i] = GNUNET_strdup(uri->data.ksk.keywords[i]); | ||
1020 | } | ||
1021 | else | ||
1022 | ret->data.ksk.keywords = NULL; /* just to be sure */ | ||
1023 | break; | ||
1024 | |||
1025 | case GNUNET_FS_URI_SKS: | ||
1026 | ret->data.sks.identifier = GNUNET_strdup(uri->data.sks.identifier); | ||
1027 | break; | ||
1028 | |||
1029 | case GNUNET_FS_URI_LOC: | ||
1030 | break; | ||
1031 | |||
1032 | default: | ||
1033 | break; | ||
1014 | } | 1034 | } |
1015 | else | ||
1016 | ret->data.ksk.keywords = NULL; /* just to be sure */ | ||
1017 | break; | ||
1018 | case GNUNET_FS_URI_SKS: | ||
1019 | ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier); | ||
1020 | break; | ||
1021 | case GNUNET_FS_URI_LOC: | ||
1022 | break; | ||
1023 | default: | ||
1024 | break; | ||
1025 | } | ||
1026 | return ret; | 1035 | return ret; |
1027 | } | 1036 | } |
1028 | 1037 | ||
@@ -1045,7 +1054,7 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) | |||
1045 | * if keywords is not legal (i.e. empty). | 1054 | * if keywords is not legal (i.e. empty). |
1046 | */ | 1055 | */ |
1047 | struct GNUNET_FS_Uri * | 1056 | struct GNUNET_FS_Uri * |
1048 | GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg) | 1057 | GNUNET_FS_uri_ksk_create(const char *keywords, char **emsg) |
1049 | { | 1058 | { |
1050 | char **keywordarr; | 1059 | char **keywordarr; |
1051 | unsigned int num_Words; | 1060 | unsigned int num_Words; |
@@ -1056,68 +1065,68 @@ GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg) | |||
1056 | int saw_quote; | 1065 | int saw_quote; |
1057 | 1066 | ||
1058 | if (keywords == NULL) | 1067 | if (keywords == NULL) |
1059 | { | 1068 | { |
1060 | *emsg = GNUNET_strdup (_ ("No keywords specified!\n")); | 1069 | *emsg = GNUNET_strdup(_("No keywords specified!\n")); |
1061 | GNUNET_break (0); | 1070 | GNUNET_break(0); |
1062 | return NULL; | 1071 | return NULL; |
1063 | } | 1072 | } |
1064 | searchString = GNUNET_strdup (keywords); | 1073 | searchString = GNUNET_strdup(keywords); |
1065 | num_Words = 0; | 1074 | num_Words = 0; |
1066 | inWord = 0; | 1075 | inWord = 0; |
1067 | saw_quote = 0; | 1076 | saw_quote = 0; |
1068 | pos = searchString; | 1077 | pos = searchString; |
1069 | while ('\0' != *pos) | 1078 | while ('\0' != *pos) |
1070 | { | ||
1071 | if ((saw_quote == 0) && (isspace ((unsigned char) *pos))) | ||
1072 | { | 1079 | { |
1073 | inWord = 0; | 1080 | if ((saw_quote == 0) && (isspace((unsigned char)*pos))) |
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++; | ||
1074 | } | 1092 | } |
1075 | else if (0 == inWord) | 1093 | if (num_Words == 0) |
1076 | { | 1094 | { |
1077 | inWord = 1; | 1095 | GNUNET_free(searchString); |
1078 | ++num_Words; | 1096 | *emsg = GNUNET_strdup(_("No keywords specified!\n")); |
1097 | return NULL; | ||
1079 | } | 1098 | } |
1080 | if ('"' == *pos) | ||
1081 | saw_quote = (saw_quote + 1) % 2; | ||
1082 | pos++; | ||
1083 | } | ||
1084 | if (num_Words == 0) | ||
1085 | { | ||
1086 | GNUNET_free (searchString); | ||
1087 | *emsg = GNUNET_strdup (_ ("No keywords specified!\n")); | ||
1088 | return NULL; | ||
1089 | } | ||
1090 | if (saw_quote != 0) | 1099 | if (saw_quote != 0) |
1091 | { | 1100 | { |
1092 | GNUNET_free (searchString); | 1101 | GNUNET_free(searchString); |
1093 | *emsg = GNUNET_strdup (_ ("Number of double-quotes not balanced!\n")); | 1102 | *emsg = GNUNET_strdup(_("Number of double-quotes not balanced!\n")); |
1094 | return NULL; | 1103 | return NULL; |
1095 | } | 1104 | } |
1096 | keywordarr = GNUNET_new_array (num_Words, char *); | 1105 | keywordarr = GNUNET_new_array(num_Words, char *); |
1097 | num_Words = 0; | 1106 | num_Words = 0; |
1098 | inWord = 0; | 1107 | inWord = 0; |
1099 | pos = searchString; | 1108 | pos = searchString; |
1100 | while ('\0' != *pos) | 1109 | while ('\0' != *pos) |
1101 | { | ||
1102 | if ((saw_quote == 0) && (isspace ((unsigned char) *pos))) | ||
1103 | { | ||
1104 | inWord = 0; | ||
1105 | *pos = '\0'; | ||
1106 | } | ||
1107 | else if (0 == inWord) | ||
1108 | { | 1110 | { |
1109 | keywordarr[num_Words] = pos; | 1111 | if ((saw_quote == 0) && (isspace((unsigned char)*pos))) |
1110 | inWord = 1; | 1112 | { |
1111 | ++num_Words; | 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++; | ||
1112 | } | 1125 | } |
1113 | if ('"' == *pos) | ||
1114 | saw_quote = (saw_quote + 1) % 2; | ||
1115 | pos++; | ||
1116 | } | ||
1117 | uri = | 1126 | uri = |
1118 | GNUNET_FS_uri_ksk_create_from_args (num_Words, (const char **) keywordarr); | 1127 | GNUNET_FS_uri_ksk_create_from_args(num_Words, (const char **)keywordarr); |
1119 | GNUNET_free (keywordarr); | 1128 | GNUNET_free(keywordarr); |
1120 | GNUNET_free (searchString); | 1129 | GNUNET_free(searchString); |
1121 | return uri; | 1130 | return uri; |
1122 | } | 1131 | } |
1123 | 1132 | ||
@@ -1140,7 +1149,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg) | |||
1140 | * if keywords is not legal (i.e. empty). | 1149 | * if keywords is not legal (i.e. empty). |
1141 | */ | 1150 | */ |
1142 | struct GNUNET_FS_Uri * | 1151 | struct GNUNET_FS_Uri * |
1143 | GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) | 1152 | GNUNET_FS_uri_ksk_create_from_args(unsigned int argc, const char **argv) |
1144 | { | 1153 | { |
1145 | unsigned int i; | 1154 | unsigned int i; |
1146 | struct GNUNET_FS_Uri *uri; | 1155 | struct GNUNET_FS_Uri *uri; |
@@ -1155,36 +1164,36 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) | |||
1155 | /* allow URI to be given as one and only keyword and | 1164 | /* allow URI to be given as one and only keyword and |
1156 | * handle accordingly */ | 1165 | * handle accordingly */ |
1157 | emsg = NULL; | 1166 | emsg = NULL; |
1158 | if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) && | 1167 | if ((argc == 1) && (strlen(argv[0]) > strlen(GNUNET_FS_URI_PREFIX)) && |
1159 | (0 == strncmp (argv[0], | 1168 | (0 == strncmp(argv[0], |
1160 | GNUNET_FS_URI_PREFIX, | 1169 | GNUNET_FS_URI_PREFIX, |
1161 | strlen (GNUNET_FS_URI_PREFIX))) && | 1170 | strlen(GNUNET_FS_URI_PREFIX))) && |
1162 | (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) | 1171 | (NULL != (uri = GNUNET_FS_uri_parse(argv[0], &emsg)))) |
1163 | return uri; | 1172 | return uri; |
1164 | GNUNET_free_non_null (emsg); | 1173 | GNUNET_free_non_null(emsg); |
1165 | uri = GNUNET_new (struct GNUNET_FS_Uri); | 1174 | uri = GNUNET_new(struct GNUNET_FS_Uri); |
1166 | uri->type = GNUNET_FS_URI_KSK; | 1175 | uri->type = GNUNET_FS_URI_KSK; |
1167 | uri->data.ksk.keywordCount = argc; | 1176 | uri->data.ksk.keywordCount = argc; |
1168 | uri->data.ksk.keywords = GNUNET_new_array (argc, char *); | 1177 | uri->data.ksk.keywords = GNUNET_new_array(argc, char *); |
1169 | for (i = 0; i < argc; i++) | 1178 | for (i = 0; i < argc; i++) |
1170 | { | ||
1171 | keyword = argv[i]; | ||
1172 | if (keyword[0] == '+') | ||
1173 | val = GNUNET_strdup (keyword); | ||
1174 | else | ||
1175 | GNUNET_asprintf (&val, " %s", keyword); | ||
1176 | r = val; | ||
1177 | w = val; | ||
1178 | while ('\0' != *r) | ||
1179 | { | 1179 | { |
1180 | if ('"' == *r) | 1180 | keyword = argv[i]; |
1181 | r++; | 1181 | if (keyword[0] == '+') |
1182 | val = GNUNET_strdup(keyword); | ||
1182 | else | 1183 | else |
1183 | *(w++) = *(r++); | 1184 | GNUNET_asprintf(&val, " %s", keyword); |
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; | ||
1184 | } | 1196 | } |
1185 | *w = '\0'; | ||
1186 | uri->data.ksk.keywords[i] = val; | ||
1187 | } | ||
1188 | return uri; | 1197 | return uri; |
1189 | } | 1198 | } |
1190 | 1199 | ||
@@ -1197,62 +1206,66 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) | |||
1197 | * @return #GNUNET_YES if the URIs are equal | 1206 | * @return #GNUNET_YES if the URIs are equal |
1198 | */ | 1207 | */ |
1199 | int | 1208 | int |
1200 | GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, | 1209 | GNUNET_FS_uri_test_equal(const struct GNUNET_FS_Uri *u1, |
1201 | const struct GNUNET_FS_Uri *u2) | 1210 | const struct GNUNET_FS_Uri *u2) |
1202 | { | 1211 | { |
1203 | int ret; | 1212 | int ret; |
1204 | unsigned int i; | 1213 | unsigned int i; |
1205 | unsigned int j; | 1214 | unsigned int j; |
1206 | 1215 | ||
1207 | GNUNET_assert (u1 != NULL); | 1216 | GNUNET_assert(u1 != NULL); |
1208 | GNUNET_assert (u2 != NULL); | 1217 | GNUNET_assert(u2 != NULL); |
1209 | if (u1->type != u2->type) | 1218 | if (u1->type != u2->type) |
1210 | return GNUNET_NO; | 1219 | return GNUNET_NO; |
1211 | switch (u1->type) | 1220 | switch (u1->type) |
1212 | { | 1221 | { |
1213 | case GNUNET_FS_URI_CHK: | 1222 | case GNUNET_FS_URI_CHK: |
1214 | if (0 == | 1223 | if (0 == |
1215 | memcmp (&u1->data.chk, &u2->data.chk, sizeof (struct FileIdentifier))) | 1224 | memcmp(&u1->data.chk, &u2->data.chk, sizeof(struct FileIdentifier))) |
1216 | return GNUNET_YES; | 1225 | return GNUNET_YES; |
1217 | return GNUNET_NO; | 1226 | return GNUNET_NO; |
1218 | case GNUNET_FS_URI_SKS: | ||
1219 | if ((0 == memcmp (&u1->data.sks.ns, | ||
1220 | &u2->data.sks.ns, | ||
1221 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) && | ||
1222 | (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) | ||
1223 | 1227 | ||
1224 | return GNUNET_YES; | 1228 | case GNUNET_FS_URI_SKS: |
1225 | return GNUNET_NO; | 1229 | if ((0 == memcmp(&u1->data.sks.ns, |
1226 | case GNUNET_FS_URI_KSK: | 1230 | &u2->data.sks.ns, |
1227 | if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount) | 1231 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) && |
1232 | (0 == strcmp(u1->data.sks.identifier, u2->data.sks.identifier))) | ||
1233 | |||
1234 | return GNUNET_YES; | ||
1228 | return GNUNET_NO; | 1235 | return GNUNET_NO; |
1229 | for (i = 0; i < u1->data.ksk.keywordCount; i++) | 1236 | |
1230 | { | 1237 | case GNUNET_FS_URI_KSK: |
1231 | ret = GNUNET_NO; | 1238 | if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount) |
1232 | for (j = 0; j < u2->data.ksk.keywordCount; j++) | 1239 | return GNUNET_NO; |
1233 | { | 1240 | for (i = 0; i < u1->data.ksk.keywordCount; i++) |
1234 | if (0 == strcmp (u1->data.ksk.keywords[i], u2->data.ksk.keywords[j])) | ||
1235 | { | 1241 | { |
1236 | ret = GNUNET_YES; | 1242 | ret = GNUNET_NO; |
1237 | break; | 1243 | for (j = 0; j < u2->data.ksk.keywordCount; j++) |
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; | ||
1238 | } | 1253 | } |
1239 | } | 1254 | return GNUNET_YES; |
1240 | if (ret == GNUNET_NO) | 1255 | |
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) | ||
1241 | return GNUNET_NO; | 1263 | return GNUNET_NO; |
1242 | } | 1264 | return GNUNET_YES; |
1243 | return GNUNET_YES; | 1265 | |
1244 | case GNUNET_FS_URI_LOC: | 1266 | default: |
1245 | if (memcmp (&u1->data.loc, | ||
1246 | &u2->data.loc, | ||
1247 | sizeof (struct FileIdentifier) + | ||
1248 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + | ||
1249 | sizeof (struct GNUNET_TIME_Absolute) + | ||
1250 | sizeof (unsigned short) + sizeof (unsigned short)) != 0) | ||
1251 | return GNUNET_NO; | 1267 | return GNUNET_NO; |
1252 | return GNUNET_YES; | 1268 | } |
1253 | default: | ||
1254 | return GNUNET_NO; | ||
1255 | } | ||
1256 | } | 1269 | } |
1257 | 1270 | ||
1258 | 1271 | ||
@@ -1263,7 +1276,7 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, | |||
1263 | * @return #GNUNET_YES if this is an SKS uri | 1276 | * @return #GNUNET_YES if this is an SKS uri |
1264 | */ | 1277 | */ |
1265 | int | 1278 | int |
1266 | GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri) | 1279 | GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri) |
1267 | { | 1280 | { |
1268 | return uri->type == GNUNET_FS_URI_SKS; | 1281 | return uri->type == GNUNET_FS_URI_SKS; |
1269 | } | 1282 | } |
@@ -1278,14 +1291,14 @@ GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri) | |||
1278 | * @return #GNUNET_OK on success | 1291 | * @return #GNUNET_OK on success |
1279 | */ | 1292 | */ |
1280 | int | 1293 | int |
1281 | GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, | 1294 | GNUNET_FS_uri_sks_get_namespace(const struct GNUNET_FS_Uri *uri, |
1282 | struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) | 1295 | struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) |
1283 | { | 1296 | { |
1284 | if (! GNUNET_FS_uri_test_sks (uri)) | 1297 | if (!GNUNET_FS_uri_test_sks(uri)) |
1285 | { | 1298 | { |
1286 | GNUNET_break (0); | 1299 | GNUNET_break(0); |
1287 | return GNUNET_SYSERR; | 1300 | return GNUNET_SYSERR; |
1288 | } | 1301 | } |
1289 | *pseudonym = uri->data.sks.ns; | 1302 | *pseudonym = uri->data.sks.ns; |
1290 | return GNUNET_OK; | 1303 | return GNUNET_OK; |
1291 | } | 1304 | } |
@@ -1298,14 +1311,14 @@ GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, | |||
1298 | * @return NULL on error (not a valid SKS URI) | 1311 | * @return NULL on error (not a valid SKS URI) |
1299 | */ | 1312 | */ |
1300 | char * | 1313 | char * |
1301 | GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) | 1314 | GNUNET_FS_uri_sks_get_content_id(const struct GNUNET_FS_Uri *uri) |
1302 | { | 1315 | { |
1303 | if (! GNUNET_FS_uri_test_sks (uri)) | 1316 | if (!GNUNET_FS_uri_test_sks(uri)) |
1304 | { | 1317 | { |
1305 | GNUNET_break (0); | 1318 | GNUNET_break(0); |
1306 | return NULL; | 1319 | return NULL; |
1307 | } | 1320 | } |
1308 | return GNUNET_strdup (uri->data.sks.identifier); | 1321 | return GNUNET_strdup(uri->data.sks.identifier); |
1309 | } | 1322 | } |
1310 | 1323 | ||
1311 | 1324 | ||
@@ -1316,16 +1329,16 @@ GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) | |||
1316 | * @return #GNUNET_YES if this is a KSK uri | 1329 | * @return #GNUNET_YES if this is a KSK uri |
1317 | */ | 1330 | */ |
1318 | int | 1331 | int |
1319 | GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) | 1332 | GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri) |
1320 | { | 1333 | { |
1321 | #if EXTRA_CHECKS | 1334 | #if EXTRA_CHECKS |
1322 | unsigned int i; | 1335 | unsigned int i; |
1323 | 1336 | ||
1324 | if (uri->type == GNUNET_FS_URI_KSK) | 1337 | if (uri->type == GNUNET_FS_URI_KSK) |
1325 | { | 1338 | { |
1326 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 1339 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
1327 | GNUNET_assert (uri->data.ksk.keywords[i] != NULL); | 1340 | GNUNET_assert(uri->data.ksk.keywords[i] != NULL); |
1328 | } | 1341 | } |
1329 | #endif | 1342 | #endif |
1330 | return uri->type == GNUNET_FS_URI_KSK; | 1343 | return uri->type == GNUNET_FS_URI_KSK; |
1331 | } | 1344 | } |
@@ -1338,7 +1351,7 @@ GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) | |||
1338 | * @return #GNUNET_YES if this is a CHK uri | 1351 | * @return #GNUNET_YES if this is a CHK uri |
1339 | */ | 1352 | */ |
1340 | int | 1353 | int |
1341 | GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) | 1354 | GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri) |
1342 | { | 1355 | { |
1343 | return uri->type == GNUNET_FS_URI_CHK; | 1356 | return uri->type == GNUNET_FS_URI_CHK; |
1344 | } | 1357 | } |
@@ -1352,17 +1365,19 @@ GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) | |||
1352 | * @return size of the file as specified in the CHK URI | 1365 | * @return size of the file as specified in the CHK URI |
1353 | */ | 1366 | */ |
1354 | uint64_t | 1367 | uint64_t |
1355 | GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri) | 1368 | GNUNET_FS_uri_chk_get_file_size(const struct GNUNET_FS_Uri *uri) |
1356 | { | 1369 | { |
1357 | switch (uri->type) | 1370 | switch (uri->type) |
1358 | { | 1371 | { |
1359 | case GNUNET_FS_URI_CHK: | 1372 | case GNUNET_FS_URI_CHK: |
1360 | return GNUNET_ntohll (uri->data.chk.file_length); | 1373 | return GNUNET_ntohll(uri->data.chk.file_length); |
1361 | case GNUNET_FS_URI_LOC: | 1374 | |
1362 | return GNUNET_ntohll (uri->data.loc.fi.file_length); | 1375 | case GNUNET_FS_URI_LOC: |
1363 | default: | 1376 | return GNUNET_ntohll(uri->data.loc.fi.file_length); |
1364 | GNUNET_assert (0); | 1377 | |
1365 | } | 1378 | default: |
1379 | GNUNET_assert(0); | ||
1380 | } | ||
1366 | return 0; /* unreachable */ | 1381 | return 0; /* unreachable */ |
1367 | } | 1382 | } |
1368 | 1383 | ||
@@ -1374,7 +1389,7 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri) | |||
1374 | * @return #GNUNET_YES if this is a LOC uri | 1389 | * @return #GNUNET_YES if this is a LOC uri |
1375 | */ | 1390 | */ |
1376 | int | 1391 | int |
1377 | GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) | 1392 | GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri) |
1378 | { | 1393 | { |
1379 | return uri->type == GNUNET_FS_URI_LOC; | 1394 | return uri->type == GNUNET_FS_URI_LOC; |
1380 | } | 1395 | } |
@@ -1390,13 +1405,13 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) | |||
1390 | * @param index offset where to add the keyword | 1405 | * @param index offset where to add the keyword |
1391 | */ | 1406 | */ |
1392 | static void | 1407 | static void |
1393 | insert_non_mandatory_keyword (const char *s, char **array, int index) | 1408 | insert_non_mandatory_keyword(const char *s, char **array, int index) |
1394 | { | 1409 | { |
1395 | char *nkword; | 1410 | char *nkword; |
1396 | 1411 | ||
1397 | GNUNET_asprintf (&nkword, | 1412 | GNUNET_asprintf(&nkword, |
1398 | " %s", /* space to mark as 'non mandatory' */ | 1413 | " %s", /* space to mark as 'non mandatory' */ |
1399 | s); | 1414 | s); |
1400 | array[index] = nkword; | 1415 | array[index] = nkword; |
1401 | } | 1416 | } |
1402 | 1417 | ||
@@ -1411,12 +1426,12 @@ insert_non_mandatory_keyword (const char *s, char **array, int index) | |||
1411 | * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not | 1426 | * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not |
1412 | */ | 1427 | */ |
1413 | static int | 1428 | static int |
1414 | find_duplicate (const char *s, const char **array, int array_length) | 1429 | find_duplicate(const char *s, const char **array, int array_length) |
1415 | { | 1430 | { |
1416 | int j; | 1431 | int j; |
1417 | 1432 | ||
1418 | for (j = array_length - 1; j >= 0; j--) | 1433 | for (j = array_length - 1; j >= 0; j--) |
1419 | if (0 == strcmp (&array[j][1], s)) | 1434 | if (0 == strcmp(&array[j][1], s)) |
1420 | return GNUNET_YES; | 1435 | return GNUNET_YES; |
1421 | return GNUNET_NO; | 1436 | return GNUNET_NO; |
1422 | } | 1437 | } |
@@ -1426,53 +1441,54 @@ find_duplicate (const char *s, const char **array, int array_length) | |||
1426 | * FIXME: comment | 1441 | * FIXME: comment |
1427 | */ | 1442 | */ |
1428 | static char * | 1443 | static char * |
1429 | normalize_metadata (enum EXTRACTOR_MetaFormat format, | 1444 | normalize_metadata(enum EXTRACTOR_MetaFormat format, |
1430 | const char *data, | 1445 | const char *data, |
1431 | size_t data_len) | 1446 | size_t data_len) |
1432 | { | 1447 | { |
1433 | uint8_t *free_str = NULL; | 1448 | uint8_t *free_str = NULL; |
1434 | uint8_t *str_to_normalize = (uint8_t *) data; | 1449 | uint8_t *str_to_normalize = (uint8_t *)data; |
1435 | uint8_t *normalized; | 1450 | uint8_t *normalized; |
1436 | size_t r_len; | 1451 | size_t r_len; |
1452 | |||
1437 | if (str_to_normalize == NULL) | 1453 | if (str_to_normalize == NULL) |
1438 | return NULL; | 1454 | return NULL; |
1439 | /* Don't trust libextractor */ | 1455 | /* Don't trust libextractor */ |
1440 | if (format == EXTRACTOR_METAFORMAT_UTF8) | 1456 | if (format == EXTRACTOR_METAFORMAT_UTF8) |
1441 | { | 1457 | { |
1442 | free_str = (uint8_t *) u8_check ((const uint8_t *) data, data_len); | 1458 | free_str = (uint8_t *)u8_check((const uint8_t *)data, data_len); |
1443 | if (free_str == NULL) | 1459 | if (free_str == NULL) |
1444 | free_str = NULL; | 1460 | free_str = NULL; |
1445 | else | 1461 | else |
1446 | format = EXTRACTOR_METAFORMAT_C_STRING; | 1462 | format = EXTRACTOR_METAFORMAT_C_STRING; |
1447 | } | 1463 | } |
1448 | if (format == EXTRACTOR_METAFORMAT_C_STRING) | 1464 | if (format == EXTRACTOR_METAFORMAT_C_STRING) |
1449 | { | 1465 | { |
1450 | free_str = u8_strconv_from_encoding (data, | 1466 | free_str = u8_strconv_from_encoding(data, |
1451 | locale_charset (), | 1467 | locale_charset(), |
1452 | iconveh_escape_sequence); | 1468 | iconveh_escape_sequence); |
1453 | if (free_str == NULL) | 1469 | if (free_str == NULL) |
1454 | return NULL; | 1470 | return NULL; |
1455 | } | 1471 | } |
1456 | 1472 | ||
1457 | normalized = u8_tolower (str_to_normalize, | 1473 | normalized = u8_tolower(str_to_normalize, |
1458 | strlen ((char *) str_to_normalize), | 1474 | strlen((char *)str_to_normalize), |
1459 | NULL, | 1475 | NULL, |
1460 | UNINORM_NFD, | 1476 | UNINORM_NFD, |
1461 | NULL, | 1477 | NULL, |
1462 | &r_len); | 1478 | &r_len); |
1463 | /* free_str is allocated by libunistring internally, use free() */ | 1479 | /* free_str is allocated by libunistring internally, use free() */ |
1464 | if (free_str != NULL) | 1480 | if (free_str != NULL) |
1465 | free (free_str); | 1481 | free(free_str); |
1466 | if (normalized != NULL) | 1482 | if (normalized != NULL) |
1467 | { | 1483 | { |
1468 | /* u8_tolower allocates a non-NULL-terminated string! */ | 1484 | /* u8_tolower allocates a non-NULL-terminated string! */ |
1469 | free_str = GNUNET_malloc (r_len + 1); | 1485 | free_str = GNUNET_malloc(r_len + 1); |
1470 | GNUNET_memcpy (free_str, normalized, r_len); | 1486 | GNUNET_memcpy(free_str, normalized, r_len); |
1471 | free_str[r_len] = '\0'; | 1487 | free_str[r_len] = '\0'; |
1472 | free (normalized); | 1488 | free(normalized); |
1473 | normalized = free_str; | 1489 | normalized = free_str; |
1474 | } | 1490 | } |
1475 | return (char *) normalized; | 1491 | return (char *)normalized; |
1476 | } | 1492 | } |
1477 | 1493 | ||
1478 | 1494 | ||
@@ -1481,15 +1497,16 @@ normalize_metadata (enum EXTRACTOR_MetaFormat format, | |||
1481 | * returns that count. | 1497 | * returns that count. |
1482 | */ | 1498 | */ |
1483 | static size_t | 1499 | static size_t |
1484 | u8_strcount (const uint8_t *s) | 1500 | u8_strcount(const uint8_t *s) |
1485 | { | 1501 | { |
1486 | size_t count; | 1502 | size_t count; |
1487 | ucs4_t c; | 1503 | ucs4_t c; |
1488 | GNUNET_assert (s != NULL); | 1504 | |
1505 | GNUNET_assert(s != NULL); | ||
1489 | if (s[0] == 0) | 1506 | if (s[0] == 0) |
1490 | return 0; | 1507 | return 0; |
1491 | for (count = 0; s != NULL; count++) | 1508 | for (count = 0; s != NULL; count++) |
1492 | s = u8_next (&c, s); | 1509 | s = u8_next(&c, s); |
1493 | return count - 1; | 1510 | return count - 1; |
1494 | } | 1511 | } |
1495 | 1512 | ||
@@ -1511,7 +1528,7 @@ u8_strcount (const uint8_t *s) | |||
1511 | * were duplicates (when extracting). | 1528 | * were duplicates (when extracting). |
1512 | */ | 1529 | */ |
1513 | static int | 1530 | static int |
1514 | get_keywords_from_parens (const char *s, char **array, int index) | 1531 | get_keywords_from_parens(const char *s, char **array, int index) |
1515 | { | 1532 | { |
1516 | int count = 0; | 1533 | int count = 0; |
1517 | char *open_paren; | 1534 | char *open_paren; |
@@ -1521,77 +1538,80 @@ get_keywords_from_parens (const char *s, char **array, int index) | |||
1521 | 1538 | ||
1522 | if (NULL == s) | 1539 | if (NULL == s) |
1523 | return 0; | 1540 | return 0; |
1524 | ss = GNUNET_strdup (s); | 1541 | ss = GNUNET_strdup(s); |
1525 | open_paren = ss - 1; | 1542 | open_paren = ss - 1; |
1526 | while (NULL != (open_paren = strpbrk (open_paren + 1, "[{("))) | 1543 | while (NULL != (open_paren = strpbrk(open_paren + 1, "[{("))) |
1527 | { | ||
1528 | int match = 0; | ||
1529 | |||
1530 | close_paren = strpbrk (open_paren + 1, "]})"); | ||
1531 | if (NULL == close_paren) | ||
1532 | continue; | ||
1533 | switch (open_paren[0]) | ||
1534 | { | ||
1535 | case '[': | ||
1536 | if (']' == close_paren[0]) | ||
1537 | match = 1; | ||
1538 | break; | ||
1539 | case '{': | ||
1540 | if ('}' == close_paren[0]) | ||
1541 | match = 1; | ||
1542 | break; | ||
1543 | case '(': | ||
1544 | if (')' == close_paren[0]) | ||
1545 | match = 1; | ||
1546 | break; | ||
1547 | default: | ||
1548 | break; | ||
1549 | } | ||
1550 | if (match && (close_paren - open_paren > 1)) | ||
1551 | { | 1544 | { |
1552 | tmp = close_paren[0]; | 1545 | int match = 0; |
1553 | close_paren[0] = '\0'; | 1546 | |
1554 | /* Keywords must be at least 3 characters long */ | 1547 | close_paren = strpbrk(open_paren + 1, "]})"); |
1555 | if (u8_strcount ((const uint8_t *) &open_paren[1]) <= 2) | 1548 | if (NULL == close_paren) |
1556 | { | ||
1557 | close_paren[0] = tmp; | ||
1558 | continue; | 1549 | continue; |
1559 | } | 1550 | switch (open_paren[0]) |
1560 | if (NULL != array) | ||
1561 | { | ||
1562 | char *normalized; | ||
1563 | if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1], | ||
1564 | (const char **) array, | ||
1565 | index + count)) | ||
1566 | { | 1551 | { |
1567 | insert_non_mandatory_keyword ((const char *) &open_paren[1], | 1552 | case '[': |
1568 | array, | 1553 | if (']' == close_paren[0]) |
1569 | index + count); | 1554 | match = 1; |
1570 | count++; | 1555 | break; |
1556 | |||
1557 | case '{': | ||
1558 | if ('}' == close_paren[0]) | ||
1559 | match = 1; | ||
1560 | break; | ||
1561 | |||
1562 | case '(': | ||
1563 | if (')' == close_paren[0]) | ||
1564 | match = 1; | ||
1565 | break; | ||
1566 | |||
1567 | default: | ||
1568 | break; | ||
1571 | } | 1569 | } |
1572 | normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, | 1570 | if (match && (close_paren - open_paren > 1)) |
1573 | &open_paren[1], | ||
1574 | close_paren - &open_paren[1]); | ||
1575 | if (normalized != NULL) | ||
1576 | { | 1571 | { |
1577 | if (GNUNET_NO == find_duplicate ((const char *) normalized, | 1572 | tmp = close_paren[0]; |
1578 | (const char **) array, | 1573 | close_paren[0] = '\0'; |
1579 | index + count)) | 1574 | /* Keywords must be at least 3 characters long */ |
1580 | { | 1575 | if (u8_strcount((const uint8_t *)&open_paren[1]) <= 2) |
1581 | insert_non_mandatory_keyword ((const char *) normalized, | 1576 | { |
1582 | array, | 1577 | close_paren[0] = tmp; |
1583 | index + count); | 1578 | continue; |
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 | ||
1584 | count++; | 1610 | count++; |
1585 | } | 1611 | close_paren[0] = tmp; |
1586 | GNUNET_free (normalized); | ||
1587 | } | 1612 | } |
1588 | } | ||
1589 | else | ||
1590 | count++; | ||
1591 | close_paren[0] = tmp; | ||
1592 | } | 1613 | } |
1593 | } | 1614 | GNUNET_free(ss); |
1594 | GNUNET_free (ss); | ||
1595 | return count; | 1615 | return count; |
1596 | } | 1616 | } |
1597 | 1617 | ||
@@ -1616,46 +1636,46 @@ get_keywords_from_parens (const char *s, char **array, int index) | |||
1616 | * duplicates (when extracting). | 1636 | * duplicates (when extracting). |
1617 | */ | 1637 | */ |
1618 | static int | 1638 | static int |
1619 | get_keywords_from_tokens (const char *s, char **array, int index) | 1639 | get_keywords_from_tokens(const char *s, char **array, int index) |
1620 | { | 1640 | { |
1621 | char *p; | 1641 | char *p; |
1622 | char *ss; | 1642 | char *ss; |
1623 | int seps = 0; | 1643 | int seps = 0; |
1624 | 1644 | ||
1625 | ss = GNUNET_strdup (s); | 1645 | ss = GNUNET_strdup(s); |
1626 | for (p = strtok (ss, TOKENS); p != NULL; p = strtok (NULL, TOKENS)) | 1646 | for (p = strtok(ss, TOKENS); p != NULL; p = strtok(NULL, TOKENS)) |
1627 | { | ||
1628 | /* Keywords must be at least 3 characters long */ | ||
1629 | if (u8_strcount ((const uint8_t *) p) <= 2) | ||
1630 | continue; | ||
1631 | if (NULL != array) | ||
1632 | { | 1647 | { |
1633 | char *normalized; | 1648 | /* Keywords must be at least 3 characters long */ |
1634 | if (GNUNET_NO == find_duplicate (p, (const char **) array, index + seps)) | 1649 | if (u8_strcount((const uint8_t *)p) <= 2) |
1635 | { | 1650 | continue; |
1636 | insert_non_mandatory_keyword (p, array, index + seps); | 1651 | if (NULL != array) |
1637 | seps++; | ||
1638 | } | ||
1639 | normalized = | ||
1640 | normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, p, strlen (p)); | ||
1641 | if (normalized != NULL) | ||
1642 | { | ||
1643 | if (GNUNET_NO == find_duplicate ((const char *) normalized, | ||
1644 | (const char **) array, | ||
1645 | index + seps)) | ||
1646 | { | 1652 | { |
1647 | insert_non_mandatory_keyword ((const char *) normalized, | 1653 | char *normalized; |
1648 | array, | 1654 | if (GNUNET_NO == find_duplicate(p, (const char **)array, index + seps)) |
1649 | index + seps); | 1655 | { |
1650 | seps++; | 1656 | insert_non_mandatory_keyword(p, array, index + 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 | } | ||
1651 | } | 1674 | } |
1652 | GNUNET_free (normalized); | 1675 | else |
1653 | } | 1676 | seps++; |
1654 | } | 1677 | } |
1655 | else | 1678 | GNUNET_free(ss); |
1656 | seps++; | ||
1657 | } | ||
1658 | GNUNET_free (ss); | ||
1659 | return seps; | 1679 | return seps; |
1660 | } | 1680 | } |
1661 | #undef TOKENS | 1681 | #undef TOKENS |
@@ -1679,13 +1699,13 @@ get_keywords_from_tokens (const char *s, char **array, int index) | |||
1679 | * @return 0 (always) | 1699 | * @return 0 (always) |
1680 | */ | 1700 | */ |
1681 | static int | 1701 | static int |
1682 | gather_uri_data (void *cls, | 1702 | gather_uri_data(void *cls, |
1683 | const char *plugin_name, | 1703 | const char *plugin_name, |
1684 | enum EXTRACTOR_MetaType type, | 1704 | enum EXTRACTOR_MetaType type, |
1685 | enum EXTRACTOR_MetaFormat format, | 1705 | enum EXTRACTOR_MetaFormat format, |
1686 | const char *data_mime_type, | 1706 | const char *data_mime_type, |
1687 | const char *data, | 1707 | const char *data, |
1688 | size_t data_len) | 1708 | size_t data_len) |
1689 | { | 1709 | { |
1690 | struct GNUNET_FS_Uri *uri = cls; | 1710 | struct GNUNET_FS_Uri *uri = cls; |
1691 | char *normalized_data; | 1711 | char *normalized_data; |
@@ -1699,49 +1719,49 @@ gather_uri_data (void *cls, | |||
1699 | * and will return the length of its valid part, skipping the keyword. | 1719 | * and will return the length of its valid part, skipping the keyword. |
1700 | * If it does - fix the extractor, not this check! | 1720 | * If it does - fix the extractor, not this check! |
1701 | */ | 1721 | */ |
1702 | if (u8_strcount ((const uint8_t *) data) <= 2) | 1722 | if (u8_strcount((const uint8_t *)data) <= 2) |
1703 | return 0; | 1723 | return 0; |
1704 | if ((EXTRACTOR_METATYPE_MIMETYPE == type) && | 1724 | if ((EXTRACTOR_METATYPE_MIMETYPE == type) && |
1705 | (NULL != (sep = memchr (data, '/', data_len))) && (sep != data)) | 1725 | (NULL != (sep = memchr(data, '/', data_len))) && (sep != data)) |
1706 | { | 1726 | { |
1707 | char *xtra; | 1727 | char *xtra; |
1708 | 1728 | ||
1709 | GNUNET_asprintf (&xtra, "mimetype:%.*s", (int) (sep - data), data); | 1729 | GNUNET_asprintf(&xtra, "mimetype:%.*s", (int)(sep - data), data); |
1710 | if (! find_duplicate (xtra, | 1730 | if (!find_duplicate(xtra, |
1711 | (const char **) uri->data.ksk.keywords, | 1731 | (const char **)uri->data.ksk.keywords, |
1712 | uri->data.ksk.keywordCount)) | 1732 | 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)) | ||
1713 | { | 1746 | { |
1714 | insert_non_mandatory_keyword (xtra, | 1747 | insert_non_mandatory_keyword(data, |
1715 | uri->data.ksk.keywords, | 1748 | uri->data.ksk.keywords, |
1716 | uri->data.ksk.keywordCount); | 1749 | uri->data.ksk.keywordCount); |
1717 | uri->data.ksk.keywordCount++; | 1750 | uri->data.ksk.keywordCount++; |
1718 | } | 1751 | } |
1719 | GNUNET_free (xtra); | ||
1720 | } | ||
1721 | |||
1722 | normalized_data = normalize_metadata (format, data, data_len); | ||
1723 | if (! find_duplicate (data, | ||
1724 | (const char **) uri->data.ksk.keywords, | ||
1725 | uri->data.ksk.keywordCount)) | ||
1726 | { | ||
1727 | insert_non_mandatory_keyword (data, | ||
1728 | uri->data.ksk.keywords, | ||
1729 | uri->data.ksk.keywordCount); | ||
1730 | uri->data.ksk.keywordCount++; | ||
1731 | } | ||
1732 | if (NULL != normalized_data) | 1752 | if (NULL != normalized_data) |
1733 | { | ||
1734 | if (! find_duplicate (normalized_data, | ||
1735 | (const char **) uri->data.ksk.keywords, | ||
1736 | uri->data.ksk.keywordCount)) | ||
1737 | { | 1753 | { |
1738 | insert_non_mandatory_keyword (normalized_data, | 1754 | if (!find_duplicate(normalized_data, |
1739 | uri->data.ksk.keywords, | 1755 | (const char **)uri->data.ksk.keywords, |
1740 | uri->data.ksk.keywordCount); | 1756 | uri->data.ksk.keywordCount)) |
1741 | uri->data.ksk.keywordCount++; | 1757 | { |
1758 | insert_non_mandatory_keyword(normalized_data, | ||
1759 | uri->data.ksk.keywords, | ||
1760 | uri->data.ksk.keywordCount); | ||
1761 | uri->data.ksk.keywordCount++; | ||
1762 | } | ||
1763 | GNUNET_free(normalized_data); | ||
1742 | } | 1764 | } |
1743 | GNUNET_free (normalized_data); | ||
1744 | } | ||
1745 | return 0; | 1765 | return 0; |
1746 | } | 1766 | } |
1747 | 1767 | ||
@@ -1755,7 +1775,7 @@ gather_uri_data (void *cls, | |||
1755 | * @return NULL on error, otherwise a KSK URI | 1775 | * @return NULL on error, otherwise a KSK URI |
1756 | */ | 1776 | */ |
1757 | struct GNUNET_FS_Uri * | 1777 | struct GNUNET_FS_Uri * |
1758 | GNUNET_FS_uri_ksk_create_from_meta_data ( | 1778 | GNUNET_FS_uri_ksk_create_from_meta_data( |
1759 | const struct GNUNET_CONTAINER_MetaData *md) | 1779 | const struct GNUNET_CONTAINER_MetaData *md) |
1760 | { | 1780 | { |
1761 | struct GNUNET_FS_Uri *ret; | 1781 | struct GNUNET_FS_Uri *ret; |
@@ -1768,41 +1788,41 @@ GNUNET_FS_uri_ksk_create_from_meta_data ( | |||
1768 | 1788 | ||
1769 | if (NULL == md) | 1789 | if (NULL == md) |
1770 | return NULL; | 1790 | return NULL; |
1771 | ret = GNUNET_new (struct GNUNET_FS_Uri); | 1791 | ret = GNUNET_new(struct GNUNET_FS_Uri); |
1772 | ret->type = GNUNET_FS_URI_KSK; | 1792 | ret->type = GNUNET_FS_URI_KSK; |
1773 | ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); | 1793 | ent = GNUNET_CONTAINER_meta_data_iterate(md, NULL, NULL); |
1774 | if (ent > 0) | 1794 | if (ent > 0) |
1775 | { | ||
1776 | full_name = GNUNET_CONTAINER_meta_data_get_first_by_types ( | ||
1777 | md, | ||
1778 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
1779 | -1); | ||
1780 | if (NULL != full_name) | ||
1781 | { | 1795 | { |
1782 | filename = full_name; | 1796 | full_name = GNUNET_CONTAINER_meta_data_get_first_by_types( |
1783 | while (NULL != (ss = strstr (filename, DIR_SEPARATOR_STR))) | 1797 | md, |
1784 | filename = ss + 1; | 1798 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, |
1785 | tok_keywords = get_keywords_from_tokens (filename, NULL, 0); | 1799 | -1); |
1786 | paren_keywords = get_keywords_from_parens (filename, NULL, 0); | 1800 | if (NULL != full_name) |
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); | ||
1787 | } | 1813 | } |
1788 | /* x3 because there might be a normalized variant of every keyword, | ||
1789 | plus theoretically one more for mime... */ | ||
1790 | ret->data.ksk.keywords = | ||
1791 | GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, char *); | ||
1792 | GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); | ||
1793 | } | ||
1794 | if (tok_keywords > 0) | 1814 | if (tok_keywords > 0) |
1795 | ret->data.ksk.keywordCount += | 1815 | ret->data.ksk.keywordCount += |
1796 | get_keywords_from_tokens (filename, | 1816 | get_keywords_from_tokens(filename, |
1797 | ret->data.ksk.keywords, | 1817 | ret->data.ksk.keywords, |
1798 | ret->data.ksk.keywordCount); | 1818 | ret->data.ksk.keywordCount); |
1799 | if (paren_keywords > 0) | 1819 | if (paren_keywords > 0) |
1800 | ret->data.ksk.keywordCount += | 1820 | ret->data.ksk.keywordCount += |
1801 | get_keywords_from_parens (filename, | 1821 | get_keywords_from_parens(filename, |
1802 | ret->data.ksk.keywords, | 1822 | ret->data.ksk.keywords, |
1803 | ret->data.ksk.keywordCount); | 1823 | ret->data.ksk.keywordCount); |
1804 | if (ent > 0) | 1824 | if (ent > 0) |
1805 | GNUNET_free_non_null (full_name); | 1825 | GNUNET_free_non_null(full_name); |
1806 | return ret; | 1826 | return ret; |
1807 | } | 1827 | } |
1808 | 1828 | ||
@@ -1812,10 +1832,10 @@ GNUNET_FS_uri_ksk_create_from_meta_data ( | |||
1812 | * need to be encoded using %-encoding? | 1832 | * need to be encoded using %-encoding? |
1813 | */ | 1833 | */ |
1814 | static int | 1834 | static int |
1815 | needs_percent (char c) | 1835 | needs_percent(char c) |
1816 | { | 1836 | { |
1817 | return (! ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') || | 1837 | return(!((isalnum((unsigned char)c)) || (c == '-') || (c == '_') || |
1818 | (c == '.') || (c == '~'))); | 1838 | (c == '.') || (c == '~'))); |
1819 | } | 1839 | } |
1820 | 1840 | ||
1821 | 1841 | ||
@@ -1826,7 +1846,7 @@ needs_percent (char c) | |||
1826 | * @return NULL on error (i.e. keywordCount == 0) | 1846 | * @return NULL on error (i.e. keywordCount == 0) |
1827 | */ | 1847 | */ |
1828 | static char * | 1848 | static char * |
1829 | uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) | 1849 | uri_ksk_to_string(const struct GNUNET_FS_Uri *uri) |
1830 | { | 1850 | { |
1831 | char **keywords; | 1851 | char **keywords; |
1832 | unsigned int keywordCount; | 1852 | unsigned int keywordCount; |
@@ -1842,49 +1862,49 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1842 | return NULL; | 1862 | return NULL; |
1843 | keywords = uri->data.ksk.keywords; | 1863 | keywords = uri->data.ksk.keywords; |
1844 | keywordCount = uri->data.ksk.keywordCount; | 1864 | keywordCount = uri->data.ksk.keywordCount; |
1845 | n = keywordCount + strlen (GNUNET_FS_URI_PREFIX) + | 1865 | n = keywordCount + strlen(GNUNET_FS_URI_PREFIX) + |
1846 | strlen (GNUNET_FS_URI_KSK_INFIX) + 1; | 1866 | strlen(GNUNET_FS_URI_KSK_INFIX) + 1; |
1847 | for (i = 0; i < keywordCount; i++) | 1867 | for (i = 0; i < keywordCount; i++) |
1848 | { | ||
1849 | keyword = keywords[i]; | ||
1850 | slen = strlen (keyword); | ||
1851 | n += slen; | ||
1852 | for (j = 0; j < slen; j++) | ||
1853 | { | 1868 | { |
1854 | if ((j == 0) && (keyword[j] == ' ')) | 1869 | keyword = keywords[i]; |
1855 | { | 1870 | slen = strlen(keyword); |
1856 | n--; | 1871 | n += slen; |
1857 | continue; /* skip leading space */ | 1872 | for (j = 0; j < slen; j++) |
1858 | } | 1873 | { |
1859 | if (needs_percent (keyword[j])) | 1874 | if ((j == 0) && (keyword[j] == ' ')) |
1860 | n += 2; /* will use %-encoding */ | 1875 | { |
1876 | n--; | ||
1877 | continue; /* skip leading space */ | ||
1878 | } | ||
1879 | if (needs_percent(keyword[j])) | ||
1880 | n += 2; /* will use %-encoding */ | ||
1881 | } | ||
1861 | } | 1882 | } |
1862 | } | 1883 | ret = GNUNET_malloc(n); |
1863 | ret = GNUNET_malloc (n); | 1884 | strcpy(ret, GNUNET_FS_URI_PREFIX); |
1864 | strcpy (ret, GNUNET_FS_URI_PREFIX); | 1885 | strcat(ret, GNUNET_FS_URI_KSK_INFIX); |
1865 | strcat (ret, GNUNET_FS_URI_KSK_INFIX); | 1886 | wpos = strlen(ret); |
1866 | wpos = strlen (ret); | ||
1867 | for (i = 0; i < keywordCount; i++) | 1887 | for (i = 0; i < keywordCount; i++) |
1868 | { | ||
1869 | keyword = keywords[i]; | ||
1870 | slen = strlen (keyword); | ||
1871 | for (j = 0; j < slen; j++) | ||
1872 | { | 1888 | { |
1873 | if ((j == 0) && (keyword[j] == ' ')) | 1889 | keyword = keywords[i]; |
1874 | continue; /* skip leading space */ | 1890 | slen = strlen(keyword); |
1875 | if (needs_percent (keyword[j])) | 1891 | for (j = 0; j < slen; j++) |
1876 | { | 1892 | { |
1877 | sprintf (&ret[wpos], "%%%02X", (unsigned char) keyword[j]); | 1893 | if ((j == 0) && (keyword[j] == ' ')) |
1878 | wpos += 3; | 1894 | continue; /* skip leading space */ |
1879 | } | 1895 | if (needs_percent(keyword[j])) |
1880 | else | 1896 | { |
1881 | { | 1897 | sprintf(&ret[wpos], "%%%02X", (unsigned char)keyword[j]); |
1882 | ret[wpos++] = keyword[j]; | 1898 | wpos += 3; |
1883 | } | 1899 | } |
1900 | else | ||
1901 | { | ||
1902 | ret[wpos++] = keyword[j]; | ||
1903 | } | ||
1904 | } | ||
1905 | if (i != keywordCount - 1) | ||
1906 | ret[wpos++] = '+'; | ||
1884 | } | 1907 | } |
1885 | if (i != keywordCount - 1) | ||
1886 | ret[wpos++] = '+'; | ||
1887 | } | ||
1888 | return ret; | 1908 | return ret; |
1889 | } | 1909 | } |
1890 | 1910 | ||
@@ -1896,7 +1916,7 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1896 | * @return NULL on error | 1916 | * @return NULL on error |
1897 | */ | 1917 | */ |
1898 | static char * | 1918 | static char * |
1899 | uri_sks_to_string (const struct GNUNET_FS_Uri *uri) | 1919 | uri_sks_to_string(const struct GNUNET_FS_Uri *uri) |
1900 | { | 1920 | { |
1901 | char *ret; | 1921 | char *ret; |
1902 | char buf[1024]; | 1922 | char buf[1024]; |
@@ -1904,18 +1924,18 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri) | |||
1904 | if (GNUNET_FS_URI_SKS != uri->type) | 1924 | if (GNUNET_FS_URI_SKS != uri->type) |
1905 | return NULL; | 1925 | return NULL; |
1906 | ret = | 1926 | ret = |
1907 | GNUNET_STRINGS_data_to_string (&uri->data.sks.ns, | 1927 | GNUNET_STRINGS_data_to_string(&uri->data.sks.ns, |
1908 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), | 1928 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
1909 | buf, | 1929 | buf, |
1910 | sizeof (buf)); | 1930 | sizeof(buf)); |
1911 | GNUNET_assert (NULL != ret); | 1931 | GNUNET_assert(NULL != ret); |
1912 | ret[0] = '\0'; | 1932 | ret[0] = '\0'; |
1913 | GNUNET_asprintf (&ret, | 1933 | GNUNET_asprintf(&ret, |
1914 | "%s%s%s/%s", | 1934 | "%s%s%s/%s", |
1915 | GNUNET_FS_URI_PREFIX, | 1935 | GNUNET_FS_URI_PREFIX, |
1916 | GNUNET_FS_URI_SKS_INFIX, | 1936 | GNUNET_FS_URI_SKS_INFIX, |
1917 | buf, | 1937 | buf, |
1918 | uri->data.sks.identifier); | 1938 | uri->data.sks.identifier); |
1919 | return ret; | 1939 | return ret; |
1920 | } | 1940 | } |
1921 | 1941 | ||
@@ -1927,7 +1947,7 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri) | |||
1927 | * @return NULL on error | 1947 | * @return NULL on error |
1928 | */ | 1948 | */ |
1929 | static char * | 1949 | static char * |
1930 | uri_chk_to_string (const struct GNUNET_FS_Uri *uri) | 1950 | uri_chk_to_string(const struct GNUNET_FS_Uri *uri) |
1931 | { | 1951 | { |
1932 | const struct FileIdentifier *fi; | 1952 | const struct FileIdentifier *fi; |
1933 | char *ret; | 1953 | char *ret; |
@@ -1937,16 +1957,16 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1937 | if (uri->type != GNUNET_FS_URI_CHK) | 1957 | if (uri->type != GNUNET_FS_URI_CHK) |
1938 | return NULL; | 1958 | return NULL; |
1939 | fi = &uri->data.chk; | 1959 | fi = &uri->data.chk; |
1940 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); | 1960 | GNUNET_CRYPTO_hash_to_enc(&fi->chk.key, &keyhash); |
1941 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); | 1961 | GNUNET_CRYPTO_hash_to_enc(&fi->chk.query, &queryhash); |
1942 | 1962 | ||
1943 | GNUNET_asprintf (&ret, | 1963 | GNUNET_asprintf(&ret, |
1944 | "%s%s%s.%s.%llu", | 1964 | "%s%s%s.%s.%llu", |
1945 | GNUNET_FS_URI_PREFIX, | 1965 | GNUNET_FS_URI_PREFIX, |
1946 | GNUNET_FS_URI_CHK_INFIX, | 1966 | GNUNET_FS_URI_CHK_INFIX, |
1947 | (const char *) &keyhash, | 1967 | (const char *)&keyhash, |
1948 | (const char *) &queryhash, | 1968 | (const char *)&queryhash, |
1949 | GNUNET_ntohll (fi->file_length)); | 1969 | GNUNET_ntohll(fi->file_length)); |
1950 | return ret; | 1970 | return ret; |
1951 | } | 1971 | } |
1952 | 1972 | ||
@@ -1958,7 +1978,7 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1958 | * @return NULL on error | 1978 | * @return NULL on error |
1959 | */ | 1979 | */ |
1960 | static char * | 1980 | static char * |
1961 | uri_loc_to_string (const struct GNUNET_FS_Uri *uri) | 1981 | uri_loc_to_string(const struct GNUNET_FS_Uri *uri) |
1962 | { | 1982 | { |
1963 | char *ret; | 1983 | char *ret; |
1964 | struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; | 1984 | struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; |
@@ -1966,30 +1986,30 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri) | |||
1966 | char *peer_id; | 1986 | char *peer_id; |
1967 | char peer_sig[SIGNATURE_ASCII_LENGTH + 1]; | 1987 | char peer_sig[SIGNATURE_ASCII_LENGTH + 1]; |
1968 | 1988 | ||
1969 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash); | 1989 | GNUNET_CRYPTO_hash_to_enc(&uri->data.loc.fi.chk.key, &keyhash); |
1970 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); | 1990 | GNUNET_CRYPTO_hash_to_enc(&uri->data.loc.fi.chk.query, &queryhash); |
1971 | peer_id = | 1991 | peer_id = |
1972 | GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key); | 1992 | GNUNET_CRYPTO_eddsa_public_key_to_string(&uri->data.loc.peer.public_key); |
1973 | GNUNET_assert ( | 1993 | GNUNET_assert( |
1974 | NULL != | 1994 | NULL != |
1975 | GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature, | 1995 | GNUNET_STRINGS_data_to_string(&uri->data.loc.contentSignature, |
1976 | sizeof (struct GNUNET_CRYPTO_EddsaSignature), | 1996 | sizeof(struct GNUNET_CRYPTO_EddsaSignature), |
1977 | peer_sig, | 1997 | peer_sig, |
1978 | sizeof (peer_sig))); | 1998 | sizeof(peer_sig))); |
1979 | GNUNET_asprintf (&ret, | 1999 | GNUNET_asprintf(&ret, |
1980 | "%s%s%s.%s.%llu.%s.%s.%llu", | 2000 | "%s%s%s.%s.%llu.%s.%s.%llu", |
1981 | GNUNET_FS_URI_PREFIX, | 2001 | GNUNET_FS_URI_PREFIX, |
1982 | GNUNET_FS_URI_LOC_INFIX, | 2002 | GNUNET_FS_URI_LOC_INFIX, |
1983 | (const char *) &keyhash, | 2003 | (const char *)&keyhash, |
1984 | (const char *) &queryhash, | 2004 | (const char *)&queryhash, |
1985 | (unsigned long long) GNUNET_ntohll ( | 2005 | (unsigned long long)GNUNET_ntohll( |
1986 | uri->data.loc.fi.file_length), | 2006 | uri->data.loc.fi.file_length), |
1987 | peer_id, | 2007 | peer_id, |
1988 | peer_sig, | 2008 | peer_sig, |
1989 | (unsigned long long) | 2009 | (unsigned long long) |
1990 | uri->data.loc.expirationTime.abs_value_us / | 2010 | uri->data.loc.expirationTime.abs_value_us / |
1991 | 1000000LL); | 2011 | 1000000LL); |
1992 | GNUNET_free (peer_id); | 2012 | GNUNET_free(peer_id); |
1993 | return ret; | 2013 | return ret; |
1994 | } | 2014 | } |
1995 | 2015 | ||
@@ -2001,27 +2021,31 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri) | |||
2001 | * @return the UTF-8 string | 2021 | * @return the UTF-8 string |
2002 | */ | 2022 | */ |
2003 | char * | 2023 | char * |
2004 | GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri) | 2024 | GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri) |
2005 | { | 2025 | { |
2006 | if (uri == NULL) | 2026 | if (uri == NULL) |
2007 | { | 2027 | { |
2008 | GNUNET_break (0); | 2028 | GNUNET_break(0); |
2009 | return NULL; | 2029 | return NULL; |
2010 | } | 2030 | } |
2011 | switch (uri->type) | 2031 | switch (uri->type) |
2012 | { | 2032 | { |
2013 | case GNUNET_FS_URI_KSK: | 2033 | case GNUNET_FS_URI_KSK: |
2014 | return uri_ksk_to_string (uri); | 2034 | return uri_ksk_to_string(uri); |
2015 | case GNUNET_FS_URI_SKS: | 2035 | |
2016 | return uri_sks_to_string (uri); | 2036 | case GNUNET_FS_URI_SKS: |
2017 | case GNUNET_FS_URI_CHK: | 2037 | return uri_sks_to_string(uri); |
2018 | return uri_chk_to_string (uri); | 2038 | |
2019 | case GNUNET_FS_URI_LOC: | 2039 | case GNUNET_FS_URI_CHK: |
2020 | return uri_loc_to_string (uri); | 2040 | return uri_chk_to_string(uri); |
2021 | default: | 2041 | |
2022 | GNUNET_break (0); | 2042 | case GNUNET_FS_URI_LOC: |
2023 | return NULL; | 2043 | return uri_loc_to_string(uri); |
2024 | } | 2044 | |
2045 | default: | ||
2046 | GNUNET_break(0); | ||
2047 | return NULL; | ||
2048 | } | ||
2025 | } | 2049 | } |
2026 | 2050 | ||
2027 | /* end of fs_uri.c */ | 2051 | /* end of fs_uri.c */ |
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index 8b04e474d..6fc71ebe5 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/gnunet-auto-share.c | 21 | * @file fs/gnunet-auto-share.c |
22 | * @brief automatically publish files on GNUnet | 22 | * @brief automatically publish files on GNUnet |
@@ -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,9 +38,7 @@ | |||
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 | { | ||
43 | |||
44 | /** | 42 | /** |
45 | * PENDING Work is kept in a linked list. | 43 | * PENDING Work is kept in a linked list. |
46 | */ | 44 | */ |
@@ -162,16 +160,16 @@ static struct GNUNET_OS_Process *publish_proc; | |||
162 | * Compute the name of the state database file we will use. | 160 | * Compute the name of the state database file we will use. |
163 | */ | 161 | */ |
164 | static char * | 162 | static char * |
165 | get_state_file () | 163 | get_state_file() |
166 | { | 164 | { |
167 | char *ret; | 165 | char *ret; |
168 | 166 | ||
169 | GNUNET_asprintf (&ret, | 167 | GNUNET_asprintf(&ret, |
170 | "%s%s.auto-share", | 168 | "%s%s.auto-share", |
171 | dir_name, | 169 | dir_name, |
172 | (DIR_SEPARATOR == dir_name[strlen (dir_name) - 1]) | 170 | (DIR_SEPARATOR == dir_name[strlen(dir_name) - 1]) |
173 | ? "" | 171 | ? "" |
174 | : DIR_SEPARATOR_STR); | 172 | : DIR_SEPARATOR_STR); |
175 | return ret; | 173 | return ret; |
176 | } | 174 | } |
177 | 175 | ||
@@ -180,7 +178,7 @@ get_state_file () | |||
180 | * Load the set of #work_finished items from disk. | 178 | * Load the set of #work_finished items from disk. |
181 | */ | 179 | */ |
182 | static void | 180 | static void |
183 | load_state () | 181 | load_state() |
184 | { | 182 | { |
185 | char *fn; | 183 | char *fn; |
186 | struct GNUNET_BIO_ReadHandle *rh; | 184 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -190,47 +188,47 @@ load_state () | |||
190 | char *emsg; | 188 | char *emsg; |
191 | 189 | ||
192 | emsg = NULL; | 190 | emsg = NULL; |
193 | fn = get_state_file (); | 191 | fn = get_state_file(); |
194 | rh = GNUNET_BIO_read_open (fn); | 192 | rh = GNUNET_BIO_read_open(fn); |
195 | GNUNET_free (fn); | 193 | GNUNET_free(fn); |
196 | if (NULL == rh) | 194 | if (NULL == rh) |
197 | return; | 195 | return; |
198 | fn = NULL; | 196 | fn = NULL; |
199 | if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &n)) | 197 | if (GNUNET_OK != GNUNET_BIO_read_int32(rh, &n)) |
200 | goto error; | 198 | goto error; |
201 | while (n-- > 0) | 199 | while (n-- > 0) |
202 | { | 200 | { |
203 | if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "filename", &fn, 1024)) || | 201 | if ((GNUNET_OK != GNUNET_BIO_read_string(rh, "filename", &fn, 1024)) || |
204 | (GNUNET_OK != | 202 | (GNUNET_OK != |
205 | GNUNET_BIO_read (rh, "id", &id, sizeof (struct GNUNET_HashCode)))) | 203 | GNUNET_BIO_read(rh, "id", &id, sizeof(struct GNUNET_HashCode)))) |
206 | goto error; | 204 | goto error; |
207 | wi = GNUNET_new (struct WorkItem); | 205 | wi = GNUNET_new(struct WorkItem); |
208 | wi->id = id; | 206 | wi->id = id; |
209 | wi->filename = fn; | 207 | wi->filename = fn; |
210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 208 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
211 | "Loaded serialization ID for `%s' is `%s'\n", | 209 | "Loaded serialization ID for `%s' is `%s'\n", |
212 | wi->filename, | 210 | wi->filename, |
213 | GNUNET_h2s (&id)); | 211 | GNUNET_h2s(&id)); |
214 | fn = NULL; | 212 | fn = NULL; |
215 | GNUNET_CRYPTO_hash (wi->filename, strlen (wi->filename), &id); | 213 | GNUNET_CRYPTO_hash(wi->filename, strlen(wi->filename), &id); |
216 | GNUNET_break (GNUNET_OK == | 214 | GNUNET_break(GNUNET_OK == |
217 | GNUNET_CONTAINER_multihashmap_put ( | 215 | GNUNET_CONTAINER_multihashmap_put( |
218 | work_finished, | 216 | work_finished, |
219 | &id, | 217 | &id, |
220 | wi, | 218 | wi, |
221 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 219 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
222 | } | 220 | } |
223 | if (GNUNET_OK == GNUNET_BIO_read_close (rh, &emsg)) | 221 | if (GNUNET_OK == GNUNET_BIO_read_close(rh, &emsg)) |
224 | return; | 222 | return; |
225 | rh = NULL; | 223 | rh = NULL; |
226 | error: | 224 | error: |
227 | GNUNET_free_non_null (fn); | 225 | GNUNET_free_non_null(fn); |
228 | if (NULL != rh) | 226 | if (NULL != rh) |
229 | (void) GNUNET_BIO_read_close (rh, &emsg); | 227 | (void)GNUNET_BIO_read_close(rh, &emsg); |
230 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 228 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
231 | _ ("Failed to load state: %s\n"), | 229 | _("Failed to load state: %s\n"), |
232 | emsg); | 230 | emsg); |
233 | GNUNET_free_non_null (emsg); | 231 | GNUNET_free_non_null(emsg); |
234 | } | 232 | } |
235 | 233 | ||
236 | 234 | ||
@@ -243,18 +241,18 @@ error: | |||
243 | * @return #GNUNET_OK to continue to iterate (if write worked) | 241 | * @return #GNUNET_OK to continue to iterate (if write worked) |
244 | */ | 242 | */ |
245 | static int | 243 | static int |
246 | write_item (void *cls, const struct GNUNET_HashCode *key, void *value) | 244 | write_item(void *cls, const struct GNUNET_HashCode *key, void *value) |
247 | { | 245 | { |
248 | struct GNUNET_BIO_WriteHandle *wh = cls; | 246 | struct GNUNET_BIO_WriteHandle *wh = cls; |
249 | struct WorkItem *wi = value; | 247 | struct WorkItem *wi = value; |
250 | 248 | ||
251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 249 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
252 | "Saving serialization ID of file `%s' with value `%s'\n", | 250 | "Saving serialization ID of file `%s' with value `%s'\n", |
253 | wi->filename, | 251 | wi->filename, |
254 | GNUNET_h2s (&wi->id)); | 252 | GNUNET_h2s(&wi->id)); |
255 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, wi->filename)) || | 253 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, wi->filename)) || |
256 | (GNUNET_OK != | 254 | (GNUNET_OK != |
257 | GNUNET_BIO_write (wh, &wi->id, sizeof (struct GNUNET_HashCode)))) | 255 | GNUNET_BIO_write(wh, &wi->id, sizeof(struct GNUNET_HashCode)))) |
258 | return GNUNET_SYSERR; /* write error, abort iteration */ | 256 | return GNUNET_SYSERR; /* write error, abort iteration */ |
259 | return GNUNET_OK; | 257 | return GNUNET_OK; |
260 | } | 258 | } |
@@ -264,38 +262,38 @@ write_item (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
264 | * Save the set of #work_finished items on disk. | 262 | * Save the set of #work_finished items on disk. |
265 | */ | 263 | */ |
266 | static void | 264 | static void |
267 | save_state () | 265 | save_state() |
268 | { | 266 | { |
269 | uint32_t n; | 267 | uint32_t n; |
270 | struct GNUNET_BIO_WriteHandle *wh; | 268 | struct GNUNET_BIO_WriteHandle *wh; |
271 | char *fn; | 269 | char *fn; |
272 | 270 | ||
273 | n = GNUNET_CONTAINER_multihashmap_size (work_finished); | 271 | n = GNUNET_CONTAINER_multihashmap_size(work_finished); |
274 | fn = get_state_file (); | 272 | fn = get_state_file(); |
275 | wh = GNUNET_BIO_write_open (fn); | 273 | wh = GNUNET_BIO_write_open(fn); |
276 | if (NULL == wh) | 274 | if (NULL == wh) |
277 | { | 275 | { |
278 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 276 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
279 | _ ("Failed to save state to file %s\n"), | 277 | _("Failed to save state to file %s\n"), |
280 | fn); | 278 | fn); |
281 | GNUNET_free (fn); | 279 | GNUNET_free(fn); |
282 | return; | 280 | return; |
283 | } | 281 | } |
284 | if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, n)) | 282 | if (GNUNET_OK != GNUNET_BIO_write_int32(wh, n)) |
285 | { | 283 | { |
286 | (void) GNUNET_BIO_write_close (wh); | 284 | (void)GNUNET_BIO_write_close(wh); |
287 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 285 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
288 | _ ("Failed to save state to file %s\n"), | 286 | _("Failed to save state to file %s\n"), |
289 | fn); | 287 | fn); |
290 | GNUNET_free (fn); | 288 | GNUNET_free(fn); |
291 | return; | 289 | return; |
292 | } | 290 | } |
293 | (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, &write_item, wh); | 291 | (void)GNUNET_CONTAINER_multihashmap_iterate(work_finished, &write_item, wh); |
294 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 292 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
295 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 293 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
296 | _ ("Failed to save state to file %s\n"), | 294 | _("Failed to save state to file %s\n"), |
297 | fn); | 295 | fn); |
298 | GNUNET_free (fn); | 296 | GNUNET_free(fn); |
299 | } | 297 | } |
300 | 298 | ||
301 | 299 | ||
@@ -305,19 +303,19 @@ save_state () | |||
305 | * @param cls closure, unused | 303 | * @param cls closure, unused |
306 | */ | 304 | */ |
307 | static void | 305 | static void |
308 | do_stop_task (void *cls) | 306 | do_stop_task(void *cls) |
309 | { | 307 | { |
310 | do_shutdown = GNUNET_YES; | 308 | do_shutdown = GNUNET_YES; |
311 | if (NULL != publish_proc) | 309 | if (NULL != publish_proc) |
312 | { | 310 | { |
313 | GNUNET_OS_process_kill (publish_proc, SIGKILL); | 311 | GNUNET_OS_process_kill(publish_proc, SIGKILL); |
314 | return; | 312 | return; |
315 | } | 313 | } |
316 | if (NULL != run_task) | 314 | if (NULL != run_task) |
317 | { | 315 | { |
318 | GNUNET_SCHEDULER_cancel (run_task); | 316 | GNUNET_SCHEDULER_cancel(run_task); |
319 | run_task = NULL; | 317 | run_task = NULL; |
320 | } | 318 | } |
321 | } | 319 | } |
322 | 320 | ||
323 | 321 | ||
@@ -325,7 +323,7 @@ do_stop_task (void *cls) | |||
325 | * Decide what the next task is (working or scanning) and schedule it. | 323 | * Decide what the next task is (working or scanning) and schedule it. |
326 | */ | 324 | */ |
327 | static void | 325 | static void |
328 | schedule_next_task (void); | 326 | schedule_next_task(void); |
329 | 327 | ||
330 | 328 | ||
331 | /** | 329 | /** |
@@ -335,7 +333,7 @@ schedule_next_task (void); | |||
335 | * @param cls the `struct WorkItem` we were working on | 333 | * @param cls the `struct WorkItem` we were working on |
336 | */ | 334 | */ |
337 | static void | 335 | static void |
338 | maint_child_death (void *cls) | 336 | maint_child_death(void *cls) |
339 | { | 337 | { |
340 | struct WorkItem *wi = cls; | 338 | struct WorkItem *wi = cls; |
341 | struct GNUNET_HashCode key; | 339 | struct GNUNET_HashCode key; |
@@ -347,65 +345,65 @@ maint_child_death (void *cls) | |||
347 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 345 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
348 | 346 | ||
349 | run_task = NULL; | 347 | run_task = NULL; |
350 | pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); | 348 | pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); |
351 | tc = GNUNET_SCHEDULER_get_task_context (); | 349 | tc = GNUNET_SCHEDULER_get_task_context(); |
352 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) | 350 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) |
353 | { | 351 | { |
354 | /* shutdown scheduled us, someone else will kill child, | 352 | /* shutdown scheduled us, someone else will kill child, |
355 | we should just try again */ | 353 | we should just try again */ |
356 | run_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 354 | run_task = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
357 | pr, | 355 | pr, |
358 | &maint_child_death, | 356 | &maint_child_death, |
359 | wi); | 357 | wi); |
360 | return; | 358 | return; |
361 | } | 359 | } |
362 | /* consume the signal */ | 360 | /* consume the signal */ |
363 | GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); | 361 | GNUNET_break(0 < GNUNET_DISK_file_read(pr, &c, sizeof(c))); |
364 | 362 | ||
365 | ret = GNUNET_OS_process_status (publish_proc, &type, &code); | 363 | ret = GNUNET_OS_process_status(publish_proc, &type, &code); |
366 | GNUNET_assert (GNUNET_SYSERR != ret); | 364 | GNUNET_assert(GNUNET_SYSERR != ret); |
367 | if (GNUNET_NO == ret) | 365 | if (GNUNET_NO == ret) |
368 | { | 366 | { |
369 | /* process still running? Then where did the SIGCHLD come from? | 367 | /* process still running? Then where did the SIGCHLD come from? |
370 | Well, let's declare it spurious (kernel bug?) and keep rolling. | 368 | Well, let's declare it spurious (kernel bug?) and keep rolling. |
371 | */ | 369 | */ |
372 | GNUNET_break (0); | 370 | GNUNET_break(0); |
373 | run_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 371 | run_task = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
374 | pr, | 372 | pr, |
375 | &maint_child_death, | 373 | &maint_child_death, |
376 | wi); | 374 | wi); |
377 | return; | 375 | return; |
378 | } | 376 | } |
379 | GNUNET_assert (GNUNET_OK == ret); | 377 | GNUNET_assert(GNUNET_OK == ret); |
380 | 378 | ||
381 | GNUNET_OS_process_destroy (publish_proc); | 379 | GNUNET_OS_process_destroy(publish_proc); |
382 | publish_proc = NULL; | 380 | publish_proc = NULL; |
383 | 381 | ||
384 | if (GNUNET_YES == do_shutdown) | 382 | if (GNUNET_YES == do_shutdown) |
385 | { | 383 | { |
386 | GNUNET_free (wi->filename); | 384 | GNUNET_free(wi->filename); |
387 | GNUNET_free (wi); | 385 | GNUNET_free(wi); |
388 | return; | 386 | return; |
389 | } | 387 | } |
390 | if ((GNUNET_OS_PROCESS_EXITED == type) && (0 == code)) | 388 | if ((GNUNET_OS_PROCESS_EXITED == type) && (0 == code)) |
391 | { | 389 | { |
392 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 390 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
393 | _ ("Publication of `%s' done\n"), | 391 | _("Publication of `%s' done\n"), |
394 | wi->filename); | 392 | wi->filename); |
395 | GNUNET_CRYPTO_hash (wi->filename, strlen (wi->filename), &key); | 393 | GNUNET_CRYPTO_hash(wi->filename, strlen(wi->filename), &key); |
396 | GNUNET_break (GNUNET_OK == | 394 | GNUNET_break(GNUNET_OK == |
397 | GNUNET_CONTAINER_multihashmap_put ( | 395 | GNUNET_CONTAINER_multihashmap_put( |
398 | work_finished, | 396 | work_finished, |
399 | &key, | 397 | &key, |
400 | wi, | 398 | wi, |
401 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 399 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
402 | } | 400 | } |
403 | else | 401 | else |
404 | { | 402 | { |
405 | GNUNET_CONTAINER_DLL_insert_tail (work_head, work_tail, wi); | 403 | GNUNET_CONTAINER_DLL_insert_tail(work_head, work_tail, wi); |
406 | } | 404 | } |
407 | save_state (); | 405 | save_state(); |
408 | schedule_next_task (); | 406 | schedule_next_task(); |
409 | } | 407 | } |
410 | 408 | ||
411 | 409 | ||
@@ -414,17 +412,17 @@ maint_child_death (void *cls) | |||
414 | * respective handler by writing to the trigger pipe. | 412 | * respective handler by writing to the trigger pipe. |
415 | */ | 413 | */ |
416 | static void | 414 | static void |
417 | sighandler_child_death () | 415 | sighandler_child_death() |
418 | { | 416 | { |
419 | static char c; | 417 | static char c; |
420 | int old_errno = errno; /* back-up errno */ | 418 | int old_errno = errno; /* back-up errno */ |
421 | 419 | ||
422 | GNUNET_break ( | 420 | GNUNET_break( |
423 | 1 == | 421 | 1 == |
424 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, | 422 | GNUNET_DISK_file_write(GNUNET_DISK_pipe_handle(sigpipe, |
425 | GNUNET_DISK_PIPE_END_WRITE), | 423 | GNUNET_DISK_PIPE_END_WRITE), |
426 | &c, | 424 | &c, |
427 | sizeof (c))); | 425 | sizeof(c))); |
428 | errno = old_errno; /* restore errno */ | 426 | errno = old_errno; /* restore errno */ |
429 | } | 427 | } |
430 | 428 | ||
@@ -435,7 +433,7 @@ sighandler_child_death () | |||
435 | * @param cls closure, NULL | 433 | * @param cls closure, NULL |
436 | */ | 434 | */ |
437 | static void | 435 | static void |
438 | work (void *cls) | 436 | work(void *cls) |
439 | { | 437 | { |
440 | static char *argv[14]; | 438 | static char *argv[14]; |
441 | static char anon_level[20]; | 439 | static char anon_level[20]; |
@@ -447,7 +445,7 @@ work (void *cls) | |||
447 | 445 | ||
448 | run_task = NULL; | 446 | run_task = NULL; |
449 | wi = work_head; | 447 | wi = work_head; |
450 | GNUNET_CONTAINER_DLL_remove (work_head, work_tail, wi); | 448 | GNUNET_CONTAINER_DLL_remove(work_head, work_tail, wi); |
451 | argc = 0; | 449 | argc = 0; |
452 | argv[argc++] = "gnunet-publish"; | 450 | argv[argc++] = "gnunet-publish"; |
453 | if (verbose) | 451 | if (verbose) |
@@ -458,41 +456,41 @@ work (void *cls) | |||
458 | argv[argc++] = "-d"; | 456 | argv[argc++] = "-d"; |
459 | argv[argc++] = "-c"; | 457 | argv[argc++] = "-c"; |
460 | argv[argc++] = cfg_filename; | 458 | argv[argc++] = cfg_filename; |
461 | GNUNET_snprintf (anon_level, sizeof (anon_level), "%u", anonymity_level); | 459 | GNUNET_snprintf(anon_level, sizeof(anon_level), "%u", anonymity_level); |
462 | argv[argc++] = "-a"; | 460 | argv[argc++] = "-a"; |
463 | argv[argc++] = anon_level; | 461 | argv[argc++] = anon_level; |
464 | GNUNET_snprintf (content_prio, sizeof (content_prio), "%u", content_priority); | 462 | GNUNET_snprintf(content_prio, sizeof(content_prio), "%u", content_priority); |
465 | argv[argc++] = "-p"; | 463 | argv[argc++] = "-p"; |
466 | argv[argc++] = content_prio; | 464 | argv[argc++] = content_prio; |
467 | GNUNET_snprintf (repl_level, sizeof (repl_level), "%u", replication_level); | 465 | GNUNET_snprintf(repl_level, sizeof(repl_level), "%u", replication_level); |
468 | argv[argc++] = "-r"; | 466 | argv[argc++] = "-r"; |
469 | argv[argc++] = repl_level; | 467 | argv[argc++] = repl_level; |
470 | argv[argc++] = wi->filename; | 468 | argv[argc++] = wi->filename; |
471 | argv[argc] = NULL; | 469 | argv[argc] = NULL; |
472 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Publishing `%s'\n"), wi->filename); | 470 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Publishing `%s'\n"), wi->filename); |
473 | GNUNET_assert (NULL == publish_proc); | 471 | GNUNET_assert(NULL == publish_proc); |
474 | publish_proc = GNUNET_OS_start_process_vap (GNUNET_YES, | 472 | publish_proc = GNUNET_OS_start_process_vap(GNUNET_YES, |
475 | 0, | 473 | 0, |
476 | NULL, | 474 | NULL, |
477 | NULL, | 475 | NULL, |
478 | NULL, | 476 | NULL, |
479 | "gnunet-publish", | 477 | "gnunet-publish", |
480 | argv); | 478 | argv); |
481 | if (NULL == publish_proc) | 479 | if (NULL == publish_proc) |
482 | { | 480 | { |
483 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 481 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
484 | _ ("Failed to run `%s'\n"), | 482 | _("Failed to run `%s'\n"), |
485 | "gnunet-publish"); | 483 | "gnunet-publish"); |
486 | GNUNET_CONTAINER_DLL_insert (work_head, work_tail, wi); | 484 | GNUNET_CONTAINER_DLL_insert(work_head, work_tail, wi); |
487 | run_task = | 485 | run_task = |
488 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &work, NULL); | 486 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, &work, NULL); |
489 | return; | 487 | return; |
490 | } | 488 | } |
491 | pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); | 489 | pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); |
492 | run_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 490 | run_task = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
493 | pr, | 491 | pr, |
494 | &maint_child_death, | 492 | &maint_child_death, |
495 | wi); | 493 | wi); |
496 | } | 494 | } |
497 | 495 | ||
498 | 496 | ||
@@ -505,39 +503,39 @@ work (void *cls) | |||
505 | * @return #GNUNET_OK (always) | 503 | * @return #GNUNET_OK (always) |
506 | */ | 504 | */ |
507 | static int | 505 | static int |
508 | determine_id (void *cls, const char *filename) | 506 | determine_id(void *cls, const char *filename) |
509 | { | 507 | { |
510 | struct GNUNET_HashCode *id = cls; | 508 | struct GNUNET_HashCode *id = cls; |
511 | struct stat sbuf; | 509 | struct stat sbuf; |
512 | struct GNUNET_HashCode fx[2]; | 510 | struct GNUNET_HashCode fx[2]; |
513 | struct GNUNET_HashCode ft; | 511 | struct GNUNET_HashCode ft; |
514 | 512 | ||
515 | if (0 != stat (filename, &sbuf)) | 513 | if (0 != stat(filename, &sbuf)) |
516 | { | 514 | { |
517 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | 515 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
518 | return GNUNET_OK; | 516 | return GNUNET_OK; |
519 | } | 517 | } |
520 | GNUNET_CRYPTO_hash (filename, strlen (filename), &fx[0]); | 518 | GNUNET_CRYPTO_hash(filename, strlen(filename), &fx[0]); |
521 | if (! S_ISDIR (sbuf.st_mode)) | 519 | if (!S_ISDIR(sbuf.st_mode)) |
522 | { | 520 | { |
523 | uint64_t fattr[2]; | 521 | uint64_t fattr[2]; |
524 | 522 | ||
525 | fattr[0] = GNUNET_htonll (sbuf.st_size); | 523 | fattr[0] = GNUNET_htonll(sbuf.st_size); |
526 | fattr[0] = GNUNET_htonll (sbuf.st_mtime); | 524 | fattr[0] = GNUNET_htonll(sbuf.st_mtime); |
527 | 525 | ||
528 | GNUNET_CRYPTO_hash (fattr, sizeof (fattr), &fx[1]); | 526 | GNUNET_CRYPTO_hash(fattr, sizeof(fattr), &fx[1]); |
529 | } | 527 | } |
530 | else | 528 | else |
531 | { | 529 | { |
532 | memset (&fx[1], 1, sizeof (struct GNUNET_HashCode)); | 530 | memset(&fx[1], 1, sizeof(struct GNUNET_HashCode)); |
533 | GNUNET_DISK_directory_scan (filename, &determine_id, &fx[1]); | 531 | GNUNET_DISK_directory_scan(filename, &determine_id, &fx[1]); |
534 | } | 532 | } |
535 | /* use hash here to make hierarchical structure distinct from | 533 | /* use hash here to make hierarchical structure distinct from |
536 | all files on the same level */ | 534 | all files on the same level */ |
537 | GNUNET_CRYPTO_hash (fx, sizeof (fx), &ft); | 535 | GNUNET_CRYPTO_hash(fx, sizeof(fx), &ft); |
538 | /* use XOR here so that order of the files in the directory | 536 | /* use XOR here so that order of the files in the directory |
539 | does not matter! */ | 537 | does not matter! */ |
540 | GNUNET_CRYPTO_hash_xor (&ft, id, id); | 538 | GNUNET_CRYPTO_hash_xor(&ft, id, id); |
541 | return GNUNET_OK; | 539 | return GNUNET_OK; |
542 | } | 540 | } |
543 | 541 | ||
@@ -552,7 +550,7 @@ determine_id (void *cls, const char *filename) | |||
552 | * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR during shutdown | 550 | * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR during shutdown |
553 | */ | 551 | */ |
554 | static int | 552 | static int |
555 | add_file (void *cls, const char *filename) | 553 | add_file(void *cls, const char *filename) |
556 | { | 554 | { |
557 | struct WorkItem *wi; | 555 | struct WorkItem *wi; |
558 | struct GNUNET_HashCode key; | 556 | struct GNUNET_HashCode key; |
@@ -560,29 +558,29 @@ add_file (void *cls, const char *filename) | |||
560 | 558 | ||
561 | if (GNUNET_YES == do_shutdown) | 559 | if (GNUNET_YES == do_shutdown) |
562 | return GNUNET_SYSERR; | 560 | return GNUNET_SYSERR; |
563 | if ((NULL != strstr (filename, "/.auto-share")) || | 561 | if ((NULL != strstr(filename, "/.auto-share")) || |
564 | (NULL != strstr (filename, "\\.auto-share"))) | 562 | (NULL != strstr(filename, "\\.auto-share"))) |
565 | return GNUNET_OK; /* skip internal file */ | 563 | return GNUNET_OK; /* skip internal file */ |
566 | GNUNET_CRYPTO_hash (filename, strlen (filename), &key); | 564 | GNUNET_CRYPTO_hash(filename, strlen(filename), &key); |
567 | wi = GNUNET_CONTAINER_multihashmap_get (work_finished, &key); | 565 | wi = GNUNET_CONTAINER_multihashmap_get(work_finished, &key); |
568 | memset (&id, 0, sizeof (struct GNUNET_HashCode)); | 566 | memset(&id, 0, sizeof(struct GNUNET_HashCode)); |
569 | determine_id (&id, filename); | 567 | determine_id(&id, filename); |
570 | if (NULL != wi) | 568 | if (NULL != wi) |
571 | { | 569 | { |
572 | if (0 == memcmp (&id, &wi->id, sizeof (struct GNUNET_HashCode))) | 570 | if (0 == memcmp(&id, &wi->id, sizeof(struct GNUNET_HashCode))) |
573 | return GNUNET_OK; /* skip: we did this one already */ | 571 | return GNUNET_OK; /* skip: we did this one already */ |
574 | /* contents changed, need to re-do the directory... */ | 572 | /* contents changed, need to re-do the directory... */ |
575 | GNUNET_assert ( | 573 | GNUNET_assert( |
576 | GNUNET_YES == | 574 | GNUNET_YES == |
577 | GNUNET_CONTAINER_multihashmap_remove (work_finished, &key, wi)); | 575 | GNUNET_CONTAINER_multihashmap_remove(work_finished, &key, wi)); |
578 | } | 576 | } |
579 | else | 577 | else |
580 | { | 578 | { |
581 | wi = GNUNET_new (struct WorkItem); | 579 | wi = GNUNET_new(struct WorkItem); |
582 | wi->filename = GNUNET_strdup (filename); | 580 | wi->filename = GNUNET_strdup(filename); |
583 | } | 581 | } |
584 | wi->id = id; | 582 | wi->id = id; |
585 | GNUNET_CONTAINER_DLL_insert (work_head, work_tail, wi); | 583 | GNUNET_CONTAINER_DLL_insert(work_head, work_tail, wi); |
586 | if (GNUNET_YES == do_shutdown) | 584 | if (GNUNET_YES == do_shutdown) |
587 | return GNUNET_SYSERR; | 585 | return GNUNET_SYSERR; |
588 | return GNUNET_OK; | 586 | return GNUNET_OK; |
@@ -595,12 +593,12 @@ add_file (void *cls, const char *filename) | |||
595 | * @param cls NULL | 593 | * @param cls NULL |
596 | */ | 594 | */ |
597 | static void | 595 | static void |
598 | scan (void *cls) | 596 | scan(void *cls) |
599 | { | 597 | { |
600 | run_task = NULL; | 598 | run_task = NULL; |
601 | start_time = GNUNET_TIME_absolute_get (); | 599 | start_time = GNUNET_TIME_absolute_get(); |
602 | (void) GNUNET_DISK_directory_scan (dir_name, &add_file, NULL); | 600 | (void)GNUNET_DISK_directory_scan(dir_name, &add_file, NULL); |
603 | schedule_next_task (); | 601 | schedule_next_task(); |
604 | } | 602 | } |
605 | 603 | ||
606 | 604 | ||
@@ -608,27 +606,27 @@ scan (void *cls) | |||
608 | * Decide what the next task is (working or scanning) and schedule it. | 606 | * Decide what the next task is (working or scanning) and schedule it. |
609 | */ | 607 | */ |
610 | static void | 608 | static void |
611 | schedule_next_task () | 609 | schedule_next_task() |
612 | { | 610 | { |
613 | struct GNUNET_TIME_Relative delay; | 611 | struct GNUNET_TIME_Relative delay; |
614 | 612 | ||
615 | if (GNUNET_YES == do_shutdown) | 613 | if (GNUNET_YES == do_shutdown) |
616 | return; | 614 | return; |
617 | GNUNET_assert (NULL == run_task); | 615 | GNUNET_assert(NULL == run_task); |
618 | if (NULL == work_head) | 616 | if (NULL == work_head) |
619 | { | 617 | { |
620 | /* delay by at most 4h, at least 1s, and otherwise in between depending | 618 | /* delay by at most 4h, at least 1s, and otherwise in between depending |
621 | on how long it took to scan */ | 619 | on how long it took to scan */ |
622 | delay = GNUNET_TIME_absolute_get_duration (start_time); | 620 | delay = GNUNET_TIME_absolute_get_duration(start_time); |
623 | delay = GNUNET_TIME_relative_saturating_multiply (delay, 100); | 621 | delay = GNUNET_TIME_relative_saturating_multiply(delay, 100); |
624 | delay = GNUNET_TIME_relative_min (delay, MAX_DELAY); | 622 | delay = GNUNET_TIME_relative_min(delay, MAX_DELAY); |
625 | delay = GNUNET_TIME_relative_max (delay, MIN_DELAY); | 623 | delay = GNUNET_TIME_relative_max(delay, MIN_DELAY); |
626 | run_task = GNUNET_SCHEDULER_add_delayed (delay, &scan, NULL); | 624 | run_task = GNUNET_SCHEDULER_add_delayed(delay, &scan, NULL); |
627 | } | 625 | } |
628 | else | 626 | else |
629 | { | 627 | { |
630 | run_task = GNUNET_SCHEDULER_add_now (&work, NULL); | 628 | run_task = GNUNET_SCHEDULER_add_now(&work, NULL); |
631 | } | 629 | } |
632 | } | 630 | } |
633 | 631 | ||
634 | 632 | ||
@@ -641,29 +639,29 @@ schedule_next_task () | |||
641 | * @param c configuration | 639 | * @param c configuration |
642 | */ | 640 | */ |
643 | static void | 641 | static void |
644 | run (void *cls, | 642 | run(void *cls, |
645 | char *const *args, | 643 | char *const *args, |
646 | const char *cfgfile, | 644 | const char *cfgfile, |
647 | const struct GNUNET_CONFIGURATION_Handle *c) | 645 | const struct GNUNET_CONFIGURATION_Handle *c) |
648 | { | 646 | { |
649 | /* check arguments */ | 647 | /* check arguments */ |
650 | if ((NULL == args[0]) || (NULL != args[1]) || | 648 | if ((NULL == args[0]) || (NULL != args[1]) || |
651 | (GNUNET_YES != GNUNET_DISK_directory_test (args[0], GNUNET_YES))) | 649 | (GNUNET_YES != GNUNET_DISK_directory_test(args[0], GNUNET_YES))) |
652 | { | 650 | { |
653 | printf (_ ( | 651 | printf(_( |
654 | "You must specify one and only one directory name for automatic publication.\n")); | 652 | "You must specify one and only one directory name for automatic publication.\n")); |
655 | ret = -1; | 653 | ret = -1; |
656 | return; | 654 | return; |
657 | } | 655 | } |
658 | cfg_filename = GNUNET_strdup (cfgfile); | 656 | cfg_filename = GNUNET_strdup(cfgfile); |
659 | cfg = c; | 657 | cfg = c; |
660 | dir_name = args[0]; | 658 | dir_name = args[0]; |
661 | work_finished = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); | 659 | work_finished = GNUNET_CONTAINER_multihashmap_create(1024, GNUNET_NO); |
662 | load_state (); | 660 | load_state(); |
663 | run_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 661 | run_task = GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, |
664 | &scan, | 662 | &scan, |
665 | NULL); | 663 | NULL); |
666 | GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL); | 664 | GNUNET_SCHEDULER_add_shutdown(&do_stop_task, NULL); |
667 | } | 665 | } |
668 | 666 | ||
669 | 667 | ||
@@ -676,12 +674,12 @@ run (void *cls, | |||
676 | * @return #GNUNET_OK to continue to iterate | 674 | * @return #GNUNET_OK to continue to iterate |
677 | */ | 675 | */ |
678 | static int | 676 | static int |
679 | free_item (void *cls, const struct GNUNET_HashCode *key, void *value) | 677 | free_item(void *cls, const struct GNUNET_HashCode *key, void *value) |
680 | { | 678 | { |
681 | struct WorkItem *wi = value; | 679 | struct WorkItem *wi = value; |
682 | 680 | ||
683 | GNUNET_free (wi->filename); | 681 | GNUNET_free(wi->filename); |
684 | GNUNET_free (wi); | 682 | GNUNET_free(wi); |
685 | return GNUNET_OK; | 683 | return GNUNET_OK; |
686 | } | 684 | } |
687 | 685 | ||
@@ -694,89 +692,89 @@ free_item (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
694 | * @return 0 ok, 1 on error | 692 | * @return 0 ok, 1 on error |
695 | */ | 693 | */ |
696 | int | 694 | int |
697 | main (int argc, char *const *argv) | 695 | main(int argc, char *const *argv) |
698 | { | 696 | { |
699 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 697 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
700 | 698 | GNUNET_GETOPT_option_uint('a', | |
701 | GNUNET_GETOPT_option_uint ('a', | 699 | "anonymity", |
702 | "anonymity", | 700 | "LEVEL", |
703 | "LEVEL", | 701 | gettext_noop( |
704 | gettext_noop ( | 702 | "set the desired LEVEL of sender-anonymity"), |
705 | "set the desired LEVEL of sender-anonymity"), | 703 | &anonymity_level), |
706 | &anonymity_level), | 704 | |
707 | 705 | GNUNET_GETOPT_option_flag( | |
708 | GNUNET_GETOPT_option_flag ( | ||
709 | 'd', | 706 | 'd', |
710 | "disable-creation-time", | 707 | "disable-creation-time", |
711 | gettext_noop ( | 708 | gettext_noop( |
712 | "disable adding the creation time to the metadata of the uploaded file"), | 709 | "disable adding the creation time to the metadata of the uploaded file"), |
713 | &do_disable_creation_time), | 710 | &do_disable_creation_time), |
714 | 711 | ||
715 | GNUNET_GETOPT_option_flag ( | 712 | GNUNET_GETOPT_option_flag( |
716 | 'D', | 713 | 'D', |
717 | "disable-extractor", | 714 | "disable-extractor", |
718 | gettext_noop ("do not use libextractor to add keywords or metadata"), | 715 | gettext_noop("do not use libextractor to add keywords or metadata"), |
719 | &disable_extractor), | 716 | &disable_extractor), |
720 | 717 | ||
721 | GNUNET_GETOPT_option_uint ('p', | 718 | GNUNET_GETOPT_option_uint('p', |
722 | "priority", | 719 | "priority", |
723 | "PRIORITY", | 720 | "PRIORITY", |
724 | gettext_noop ( | 721 | gettext_noop( |
725 | "specify the priority of the content"), | 722 | "specify the priority of the content"), |
726 | &content_priority), | 723 | &content_priority), |
727 | 724 | ||
728 | GNUNET_GETOPT_option_uint ('r', | 725 | GNUNET_GETOPT_option_uint('r', |
729 | "replication", | 726 | "replication", |
730 | "LEVEL", | 727 | "LEVEL", |
731 | gettext_noop ( | 728 | gettext_noop( |
732 | "set the desired replication LEVEL"), | 729 | "set the desired replication LEVEL"), |
733 | &replication_level), | 730 | &replication_level), |
734 | 731 | ||
735 | GNUNET_GETOPT_option_verbose (&verbose), | 732 | GNUNET_GETOPT_option_verbose(&verbose), |
736 | 733 | ||
737 | GNUNET_GETOPT_OPTION_END}; | 734 | GNUNET_GETOPT_OPTION_END |
735 | }; | ||
738 | struct WorkItem *wi; | 736 | struct WorkItem *wi; |
739 | int ok; | 737 | int ok; |
740 | struct GNUNET_SIGNAL_Context *shc_chld; | 738 | struct GNUNET_SIGNAL_Context *shc_chld; |
741 | 739 | ||
742 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 740 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
743 | return 2; | 741 | return 2; |
744 | sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); | 742 | sigpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); |
745 | GNUNET_assert (NULL != sigpipe); | 743 | GNUNET_assert(NULL != sigpipe); |
746 | shc_chld = | 744 | shc_chld = |
747 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 745 | GNUNET_SIGNAL_handler_install(GNUNET_SIGCHLD, &sighandler_child_death); |
748 | ok = | 746 | ok = |
749 | (GNUNET_OK == | 747 | (GNUNET_OK == |
750 | GNUNET_PROGRAM_run ( | 748 | GNUNET_PROGRAM_run( |
751 | argc, | 749 | argc, |
752 | argv, | 750 | argv, |
753 | "gnunet-auto-share [OPTIONS] FILENAME", | 751 | "gnunet-auto-share [OPTIONS] FILENAME", |
754 | gettext_noop ("Automatically publish files from a directory on GNUnet"), | 752 | gettext_noop("Automatically publish files from a directory on GNUnet"), |
755 | options, | 753 | options, |
756 | &run, | 754 | &run, |
757 | NULL)) | 755 | NULL)) |
758 | ? ret | 756 | ? ret |
759 | : 1; | 757 | : 1; |
760 | if (NULL != work_finished) | 758 | if (NULL != work_finished) |
761 | { | 759 | { |
762 | (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, | 760 | (void)GNUNET_CONTAINER_multihashmap_iterate(work_finished, |
763 | &free_item, | 761 | &free_item, |
764 | NULL); | 762 | NULL); |
765 | GNUNET_CONTAINER_multihashmap_destroy (work_finished); | 763 | GNUNET_CONTAINER_multihashmap_destroy(work_finished); |
766 | } | 764 | } |
767 | while (NULL != (wi = work_head)) | 765 | while (NULL != (wi = work_head)) |
768 | { | 766 | { |
769 | GNUNET_CONTAINER_DLL_remove (work_head, work_tail, wi); | 767 | GNUNET_CONTAINER_DLL_remove(work_head, work_tail, wi); |
770 | GNUNET_free (wi->filename); | 768 | GNUNET_free(wi->filename); |
771 | GNUNET_free (wi); | 769 | GNUNET_free(wi); |
772 | } | 770 | } |
773 | GNUNET_SIGNAL_handler_uninstall (shc_chld); | 771 | GNUNET_SIGNAL_handler_uninstall(shc_chld); |
774 | shc_chld = NULL; | 772 | shc_chld = NULL; |
775 | GNUNET_DISK_pipe_close (sigpipe); | 773 | GNUNET_DISK_pipe_close(sigpipe); |
776 | sigpipe = NULL; | 774 | sigpipe = NULL; |
777 | GNUNET_free_non_null (cfg_filename); | 775 | GNUNET_free_non_null(cfg_filename); |
778 | cfg_filename = NULL; | 776 | cfg_filename = NULL; |
779 | GNUNET_free ((void *) argv); | 777 | GNUNET_free((void *)argv); |
780 | return ok; | 778 | return ok; |
781 | } | 779 | } |
782 | 780 | ||
diff --git a/src/fs/gnunet-daemon-fsprofiler.c b/src/fs/gnunet-daemon-fsprofiler.c index 0202dde9c..524475c40 100644 --- a/src/fs/gnunet-daemon-fsprofiler.c +++ b/src/fs/gnunet-daemon-fsprofiler.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-daemon-fsprofiler.c | 22 | * @file fs/gnunet-daemon-fsprofiler.c |
@@ -34,8 +34,7 @@ | |||
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 | { | ||
39 | /** | 38 | /** |
40 | * Kept in a DLL. | 39 | * Kept in a DLL. |
41 | */ | 40 | */ |
@@ -173,29 +172,29 @@ static struct Pattern *download_tail; | |||
173 | * @return GNUNET_OK on success | 172 | * @return GNUNET_OK on success |
174 | */ | 173 | */ |
175 | static int | 174 | static int |
176 | parse_pattern (struct Pattern **head, | 175 | parse_pattern(struct Pattern **head, |
177 | struct Pattern **tail, | 176 | struct Pattern **tail, |
178 | const char *pattern) | 177 | const char *pattern) |
179 | { | 178 | { |
180 | struct Pattern *p; | 179 | struct Pattern *p; |
181 | unsigned long long x; | 180 | unsigned long long x; |
182 | unsigned long long y; | 181 | unsigned long long y; |
183 | unsigned long long t; | 182 | unsigned long long t; |
184 | 183 | ||
185 | while (3 == sscanf (pattern, | 184 | while (3 == sscanf(pattern, |
186 | "(%llu,%llu,%llu)", | 185 | "(%llu,%llu,%llu)", |
187 | &x, &y, &t)) | 186 | &x, &y, &t)) |
188 | { | 187 | { |
189 | p = GNUNET_new (struct Pattern); | 188 | p = GNUNET_new(struct Pattern); |
190 | p->x = x; | 189 | p->x = x; |
191 | p->y = y; | 190 | p->y = y; |
192 | p->delay.rel_value_us = (uint64_t) t; | 191 | p->delay.rel_value_us = (uint64_t)t; |
193 | GNUNET_CONTAINER_DLL_insert (*head, *tail, p); | 192 | GNUNET_CONTAINER_DLL_insert(*head, *tail, p); |
194 | pattern = strstr (pattern, ")"); | 193 | pattern = strstr(pattern, ")"); |
195 | GNUNET_assert (NULL != pattern); | 194 | GNUNET_assert(NULL != pattern); |
196 | pattern++; | 195 | pattern++; |
197 | } | 196 | } |
198 | return (0 == strlen (pattern)) ? GNUNET_OK : GNUNET_SYSERR; | 197 | return (0 == strlen(pattern)) ? GNUNET_OK : GNUNET_SYSERR; |
199 | } | 198 | } |
200 | 199 | ||
201 | 200 | ||
@@ -206,13 +205,13 @@ parse_pattern (struct Pattern **head, | |||
206 | * @return corresponding KSK URI | 205 | * @return corresponding KSK URI |
207 | */ | 206 | */ |
208 | static struct GNUNET_FS_Uri * | 207 | static struct GNUNET_FS_Uri * |
209 | make_keywords (uint64_t kval) | 208 | make_keywords(uint64_t kval) |
210 | { | 209 | { |
211 | char kw[128]; | 210 | char kw[128]; |
212 | 211 | ||
213 | GNUNET_snprintf (kw, sizeof (kw), | 212 | GNUNET_snprintf(kw, sizeof(kw), |
214 | "%llu", (unsigned long long) kval); | 213 | "%llu", (unsigned long long)kval); |
215 | return GNUNET_FS_uri_ksk_create (kw, NULL); | 214 | return GNUNET_FS_uri_ksk_create(kw, NULL); |
216 | } | 215 | } |
217 | 216 | ||
218 | 217 | ||
@@ -226,9 +225,9 @@ make_keywords (uint64_t kval) | |||
226 | * @return file information handle for the file | 225 | * @return file information handle for the file |
227 | */ | 226 | */ |
228 | static struct GNUNET_FS_FileInformation * | 227 | static struct GNUNET_FS_FileInformation * |
229 | make_file (uint64_t length, | 228 | make_file(uint64_t length, |
230 | uint64_t kval, | 229 | uint64_t kval, |
231 | void *ctx) | 230 | void *ctx) |
232 | { | 231 | { |
233 | struct GNUNET_FS_FileInformation *fi; | 232 | struct GNUNET_FS_FileInformation *fi; |
234 | struct GNUNET_FS_BlockOptions bo; | 233 | struct GNUNET_FS_BlockOptions bo; |
@@ -238,27 +237,27 @@ make_file (uint64_t length, | |||
238 | uint64_t xor; | 237 | uint64_t xor; |
239 | 238 | ||
240 | data = NULL; /* to make compilers happy */ | 239 | data = NULL; /* to make compilers happy */ |
241 | if ( (0 != length) && | 240 | if ((0 != length) && |
242 | (NULL == (data = GNUNET_malloc_large ((size_t) length))) ) | 241 | (NULL == (data = GNUNET_malloc_large((size_t)length)))) |
243 | return NULL; | 242 | return NULL; |
244 | /* initialize data with 'unique' data only depending on 'kval' and 'size', | 243 | /* initialize data with 'unique' data only depending on 'kval' and 'size', |
245 | making sure that blocks do not repeat */ | 244 | making sure that blocks do not repeat */ |
246 | for (i=0;i<length; i+=8) | 245 | for (i = 0; i < length; i += 8) |
247 | { | 246 | { |
248 | xor = length ^ kval ^ (uint64_t) (i / 32 / 1024); | 247 | xor = length ^ kval ^ (uint64_t)(i / 32 / 1024); |
249 | GNUNET_memcpy (&data[i], &xor, GNUNET_MIN (length - i, sizeof (uint64_t))); | 248 | GNUNET_memcpy(&data[i], &xor, GNUNET_MIN(length - i, sizeof(uint64_t))); |
250 | } | 249 | } |
251 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS); | 250 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_DAYS); |
252 | bo.anonymity_level = (uint32_t) anonymity_level; | 251 | bo.anonymity_level = (uint32_t)anonymity_level; |
253 | bo.content_priority = 128; | 252 | bo.content_priority = 128; |
254 | bo.replication_level = (uint32_t) replication_level; | 253 | bo.replication_level = (uint32_t)replication_level; |
255 | keywords = make_keywords (kval); | 254 | keywords = make_keywords(kval); |
256 | fi = GNUNET_FS_file_information_create_from_data (fs_handle, | 255 | fi = GNUNET_FS_file_information_create_from_data(fs_handle, |
257 | ctx, | 256 | ctx, |
258 | length, | 257 | length, |
259 | data, keywords, | 258 | data, keywords, |
260 | NULL, GNUNET_NO, &bo); | 259 | NULL, GNUNET_NO, &bo); |
261 | GNUNET_FS_uri_destroy (keywords); | 260 | GNUNET_FS_uri_destroy(keywords); |
262 | return fi; | 261 | return fi; |
263 | } | 262 | } |
264 | 263 | ||
@@ -269,42 +268,42 @@ make_file (uint64_t length, | |||
269 | * @param cls unused | 268 | * @param cls unused |
270 | */ | 269 | */ |
271 | static void | 270 | static void |
272 | shutdown_task (void *cls) | 271 | shutdown_task(void *cls) |
273 | { | 272 | { |
274 | struct Pattern *p; | 273 | struct Pattern *p; |
275 | 274 | ||
276 | while (NULL != (p = publish_head)) | 275 | while (NULL != (p = publish_head)) |
277 | { | 276 | { |
278 | if (NULL != p->task) | 277 | if (NULL != p->task) |
279 | GNUNET_SCHEDULER_cancel (p->task); | 278 | GNUNET_SCHEDULER_cancel(p->task); |
280 | if (NULL != p->ctx) | 279 | if (NULL != p->ctx) |
281 | GNUNET_FS_publish_stop (p->ctx); | 280 | GNUNET_FS_publish_stop(p->ctx); |
282 | GNUNET_CONTAINER_DLL_remove (publish_head, publish_tail, p); | 281 | GNUNET_CONTAINER_DLL_remove(publish_head, publish_tail, p); |
283 | GNUNET_free (p); | 282 | GNUNET_free(p); |
284 | } | 283 | } |
285 | while (NULL != (p = download_head)) | 284 | while (NULL != (p = download_head)) |
286 | { | 285 | { |
287 | if (NULL != p->task) | 286 | if (NULL != p->task) |
288 | GNUNET_SCHEDULER_cancel (p->task); | 287 | GNUNET_SCHEDULER_cancel(p->task); |
289 | if (NULL != p->stask) | 288 | if (NULL != p->stask) |
290 | GNUNET_SCHEDULER_cancel (p->stask); | 289 | GNUNET_SCHEDULER_cancel(p->stask); |
291 | if (NULL != p->ctx) | 290 | if (NULL != p->ctx) |
292 | GNUNET_FS_download_stop (p->ctx, GNUNET_YES); | 291 | GNUNET_FS_download_stop(p->ctx, GNUNET_YES); |
293 | if (NULL != p->sctx) | 292 | if (NULL != p->sctx) |
294 | GNUNET_FS_search_stop (p->sctx); | 293 | GNUNET_FS_search_stop(p->sctx); |
295 | GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p); | 294 | GNUNET_CONTAINER_DLL_remove(download_head, download_tail, p); |
296 | GNUNET_free (p); | 295 | GNUNET_free(p); |
297 | } | 296 | } |
298 | if (NULL != fs_handle) | 297 | if (NULL != fs_handle) |
299 | { | 298 | { |
300 | GNUNET_FS_stop (fs_handle); | 299 | GNUNET_FS_stop(fs_handle); |
301 | fs_handle = NULL; | 300 | fs_handle = NULL; |
302 | } | 301 | } |
303 | if (NULL != stats_handle) | 302 | if (NULL != stats_handle) |
304 | { | 303 | { |
305 | GNUNET_STATISTICS_destroy (stats_handle, GNUNET_YES); | 304 | GNUNET_STATISTICS_destroy(stats_handle, GNUNET_YES); |
306 | stats_handle = NULL; | 305 | stats_handle = NULL; |
307 | } | 306 | } |
308 | } | 307 | } |
309 | 308 | ||
310 | 309 | ||
@@ -314,12 +313,12 @@ shutdown_task (void *cls) | |||
314 | * @param cls the 'struct Pattern' of the publish operation to stop | 313 | * @param cls the 'struct Pattern' of the publish operation to stop |
315 | */ | 314 | */ |
316 | static void | 315 | static void |
317 | publish_stop_task (void *cls) | 316 | publish_stop_task(void *cls) |
318 | { | 317 | { |
319 | struct Pattern *p = cls; | 318 | struct Pattern *p = cls; |
320 | 319 | ||
321 | p->task = NULL; | 320 | p->task = NULL; |
322 | GNUNET_FS_publish_stop (p->ctx); | 321 | GNUNET_FS_publish_stop(p->ctx); |
323 | } | 322 | } |
324 | 323 | ||
325 | 324 | ||
@@ -329,12 +328,12 @@ publish_stop_task (void *cls) | |||
329 | * @param cls the 'struct Pattern' of the download operation to stop | 328 | * @param cls the 'struct Pattern' of the download operation to stop |
330 | */ | 329 | */ |
331 | static void | 330 | static void |
332 | download_stop_task (void *cls) | 331 | download_stop_task(void *cls) |
333 | { | 332 | { |
334 | struct Pattern *p = cls; | 333 | struct Pattern *p = cls; |
335 | 334 | ||
336 | p->task = NULL; | 335 | p->task = NULL; |
337 | GNUNET_FS_download_stop (p->ctx, GNUNET_YES); | 336 | GNUNET_FS_download_stop(p->ctx, GNUNET_YES); |
338 | } | 337 | } |
339 | 338 | ||
340 | 339 | ||
@@ -344,12 +343,12 @@ download_stop_task (void *cls) | |||
344 | * @param cls the 'struct Pattern' of the download operation to stop | 343 | * @param cls the 'struct Pattern' of the download operation to stop |
345 | */ | 344 | */ |
346 | static void | 345 | static void |
347 | search_stop_task (void *cls) | 346 | search_stop_task(void *cls) |
348 | { | 347 | { |
349 | struct Pattern *p = cls; | 348 | struct Pattern *p = cls; |
350 | 349 | ||
351 | p->stask = NULL; | 350 | p->stask = NULL; |
352 | GNUNET_FS_search_stop (p->sctx); | 351 | GNUNET_FS_search_stop(p->sctx); |
353 | } | 352 | } |
354 | 353 | ||
355 | 354 | ||
@@ -369,124 +368,138 @@ search_stop_task (void *cls) | |||
369 | * field in the GNUNET_FS_ProgressInfo struct. | 368 | * field in the GNUNET_FS_ProgressInfo struct. |
370 | */ | 369 | */ |
371 | static void * | 370 | static void * |
372 | progress_cb (void *cls, | 371 | progress_cb(void *cls, |
373 | const struct GNUNET_FS_ProgressInfo *info) | 372 | const struct GNUNET_FS_ProgressInfo *info) |
374 | { | 373 | { |
375 | struct Pattern *p; | 374 | struct Pattern *p; |
376 | const struct GNUNET_FS_Uri *uri; | 375 | const struct GNUNET_FS_Uri *uri; |
377 | 376 | ||
378 | switch (info->status) | 377 | 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 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
385 | p = info->value.publish.cctx; | ||
386 | return p; | ||
387 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
389 | "Publishing failed\n"); | ||
390 | GNUNET_STATISTICS_update (stats_handle, | ||
391 | "# failed publish operations", 1, GNUNET_NO); | ||
392 | p = info->value.publish.cctx; | ||
393 | p->task = GNUNET_SCHEDULER_add_now (&publish_stop_task, p); | ||
394 | return p; | ||
395 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
396 | p = info->value.publish.cctx; | ||
397 | GNUNET_STATISTICS_update (stats_handle, | ||
398 | "# publishing time (ms)", | ||
399 | (long long) GNUNET_TIME_absolute_get_duration (p->start_time).rel_value_us / 1000LL, | ||
400 | GNUNET_NO); | ||
401 | p->task = GNUNET_SCHEDULER_add_now (&publish_stop_task, p); | ||
402 | return p; | ||
403 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
404 | p = info->value.publish.cctx; | ||
405 | p->ctx = NULL; | ||
406 | GNUNET_CONTAINER_DLL_remove (publish_head, publish_tail, p); | ||
407 | GNUNET_free (p); | ||
408 | return NULL; | ||
409 | case GNUNET_FS_STATUS_DOWNLOAD_START: | ||
410 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
411 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | ||
412 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | ||
413 | p = info->value.download.cctx; | ||
414 | return p; | ||
415 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | ||
416 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
417 | "Download failed\n"); | ||
418 | GNUNET_STATISTICS_update (stats_handle, | ||
419 | "# failed downloads", 1, GNUNET_NO); | ||
420 | p = info->value.download.cctx; | ||
421 | p->task = GNUNET_SCHEDULER_add_now (&download_stop_task, p); | ||
422 | return p; | ||
423 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | ||
424 | p = info->value.download.cctx; | ||
425 | GNUNET_STATISTICS_update (stats_handle, | ||
426 | "# download time (ms)", | ||
427 | (long long) GNUNET_TIME_absolute_get_duration (p->start_time).rel_value_us / 1000LL, | ||
428 | GNUNET_NO); | ||
429 | p->task = GNUNET_SCHEDULER_add_now (&download_stop_task, p); | ||
430 | return p; | ||
431 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
432 | p = info->value.download.cctx; | ||
433 | p->ctx = NULL; | ||
434 | if (NULL == p->sctx) | ||
435 | { | ||
436 | GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p); | ||
437 | GNUNET_free (p); | ||
438 | } | ||
439 | return NULL; | ||
440 | case GNUNET_FS_STATUS_SEARCH_START: | ||
441 | case GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE: | ||
442 | p = info->value.search.cctx; | ||
443 | return p; | ||
444 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
445 | p = info->value.search.cctx; | ||
446 | uri = info->value.search.specifics.result.uri; | ||
447 | if (GNUNET_YES != GNUNET_FS_uri_test_chk (uri)) | ||
448 | return NULL; /* not what we want */ | ||
449 | if (p->y != GNUNET_FS_uri_chk_get_file_size (uri)) | ||
450 | return NULL; /* not what we want */ | ||
451 | GNUNET_STATISTICS_update (stats_handle, | ||
452 | "# search time (ms)", | ||
453 | (long long) GNUNET_TIME_absolute_get_duration (p->start_time).rel_value_us / 1000LL, | ||
454 | GNUNET_NO); | ||
455 | p->start_time = GNUNET_TIME_absolute_get (); | ||
456 | p->ctx = GNUNET_FS_download_start (fs_handle, uri, | ||
457 | NULL, NULL, NULL, | ||
458 | 0, GNUNET_FS_uri_chk_get_file_size (uri), | ||
459 | anonymity_level, | ||
460 | GNUNET_FS_DOWNLOAD_NO_TEMPORARIES, | ||
461 | p, | ||
462 | NULL); | ||
463 | p->stask = GNUNET_SCHEDULER_add_now (&search_stop_task, p); | ||
464 | return NULL; | ||
465 | case GNUNET_FS_STATUS_SEARCH_UPDATE: | ||
466 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
467 | return NULL; /* don't care */ | ||
468 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
469 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
470 | "Search failed\n"); | ||
471 | GNUNET_STATISTICS_update (stats_handle, | ||
472 | "# failed searches", 1, GNUNET_NO); | ||
473 | p = info->value.search.cctx; | ||
474 | p->stask = GNUNET_SCHEDULER_add_now (&search_stop_task, p); | ||
475 | return p; | ||
476 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
477 | p = info->value.search.cctx; | ||
478 | p->sctx = NULL; | ||
479 | if (NULL == p->ctx) | ||
480 | { | 378 | { |
481 | GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p); | 379 | case GNUNET_FS_STATUS_PUBLISH_START: |
482 | GNUNET_free (p); | 380 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
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; | ||
483 | } | 502 | } |
484 | return NULL; | ||
485 | default: | ||
486 | /* unexpected event during profiling */ | ||
487 | GNUNET_break (0); | ||
488 | return NULL; | ||
489 | } | ||
490 | } | 503 | } |
491 | 504 | ||
492 | 505 | ||
@@ -496,18 +509,18 @@ progress_cb (void *cls, | |||
496 | * @param cls the 'struct Pattern' specifying the operation to perform | 509 | * @param cls the 'struct Pattern' specifying the operation to perform |
497 | */ | 510 | */ |
498 | static void | 511 | static void |
499 | start_publish (void *cls) | 512 | start_publish(void *cls) |
500 | { | 513 | { |
501 | struct Pattern *p = cls; | 514 | struct Pattern *p = cls; |
502 | struct GNUNET_FS_FileInformation *fi; | 515 | struct GNUNET_FS_FileInformation *fi; |
503 | 516 | ||
504 | p->task = NULL; | 517 | p->task = NULL; |
505 | fi = make_file (p->x, p->y, p); | 518 | fi = make_file(p->x, p->y, p); |
506 | p->start_time = GNUNET_TIME_absolute_get (); | 519 | p->start_time = GNUNET_TIME_absolute_get(); |
507 | p->ctx = GNUNET_FS_publish_start (fs_handle, | 520 | p->ctx = GNUNET_FS_publish_start(fs_handle, |
508 | fi, | 521 | fi, |
509 | NULL, NULL, NULL, | 522 | NULL, NULL, NULL, |
510 | GNUNET_FS_PUBLISH_OPTION_NONE); | 523 | GNUNET_FS_PUBLISH_OPTION_NONE); |
511 | } | 524 | } |
512 | 525 | ||
513 | 526 | ||
@@ -517,18 +530,18 @@ start_publish (void *cls) | |||
517 | * @param cls the 'struct Pattern' specifying the operation to perform | 530 | * @param cls the 'struct Pattern' specifying the operation to perform |
518 | */ | 531 | */ |
519 | static void | 532 | static void |
520 | start_download (void *cls) | 533 | start_download(void *cls) |
521 | { | 534 | { |
522 | struct Pattern *p = cls; | 535 | struct Pattern *p = cls; |
523 | struct GNUNET_FS_Uri *keywords; | 536 | struct GNUNET_FS_Uri *keywords; |
524 | 537 | ||
525 | p->task = NULL; | 538 | p->task = NULL; |
526 | keywords = make_keywords (p->x); | 539 | keywords = make_keywords(p->x); |
527 | p->start_time = GNUNET_TIME_absolute_get (); | 540 | p->start_time = GNUNET_TIME_absolute_get(); |
528 | p->sctx = GNUNET_FS_search_start (fs_handle, keywords, | 541 | p->sctx = GNUNET_FS_search_start(fs_handle, keywords, |
529 | anonymity_level, | 542 | anonymity_level, |
530 | GNUNET_FS_SEARCH_OPTION_NONE, | 543 | GNUNET_FS_SEARCH_OPTION_NONE, |
531 | p); | 544 | p); |
532 | } | 545 | } |
533 | 546 | ||
534 | 547 | ||
@@ -541,88 +554,88 @@ start_download (void *cls) | |||
541 | * @param cfg_ configuration | 554 | * @param cfg_ configuration |
542 | */ | 555 | */ |
543 | static void | 556 | static void |
544 | run (void *cls, char *const *args GNUNET_UNUSED, | 557 | run(void *cls, char *const *args GNUNET_UNUSED, |
545 | const char *cfgfile GNUNET_UNUSED, | 558 | const char *cfgfile GNUNET_UNUSED, |
546 | const struct GNUNET_CONFIGURATION_Handle *cfg_) | 559 | const struct GNUNET_CONFIGURATION_Handle *cfg_) |
547 | { | 560 | { |
548 | char myoptname[128]; | 561 | char myoptname[128]; |
549 | struct Pattern *p; | 562 | struct Pattern *p; |
550 | 563 | ||
551 | cfg = cfg_; | 564 | cfg = cfg_; |
552 | /* Scheduled the task to clean up when shutdown is called */ | 565 | /* Scheduled the task to clean up when shutdown is called */ |
553 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 566 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, |
554 | NULL); | 567 | NULL); |
555 | 568 | ||
556 | if (GNUNET_OK != | 569 | if (GNUNET_OK != |
557 | GNUNET_CONFIGURATION_get_value_number (cfg, | 570 | GNUNET_CONFIGURATION_get_value_number(cfg, |
558 | "TESTBED", "PEERID", | 571 | "TESTBED", "PEERID", |
559 | &my_peerid)) | 572 | &my_peerid)) |
560 | { | 573 | { |
561 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 574 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
562 | "TESTBED", "PEERID"); | 575 | "TESTBED", "PEERID"); |
563 | global_ret = GNUNET_SYSERR; | 576 | global_ret = GNUNET_SYSERR; |
564 | GNUNET_SCHEDULER_shutdown (); | 577 | GNUNET_SCHEDULER_shutdown(); |
565 | return; | 578 | return; |
566 | } | 579 | } |
567 | if (GNUNET_OK != | 580 | if (GNUNET_OK != |
568 | GNUNET_CONFIGURATION_get_value_number (cfg, | 581 | GNUNET_CONFIGURATION_get_value_number(cfg, |
569 | "FSPROFILER", "ANONYMITY_LEVEL", | 582 | "FSPROFILER", "ANONYMITY_LEVEL", |
570 | &anonymity_level)) | 583 | &anonymity_level)) |
571 | anonymity_level = 1; | 584 | anonymity_level = 1; |
572 | if (GNUNET_OK != | 585 | if (GNUNET_OK != |
573 | GNUNET_CONFIGURATION_get_value_number (cfg, | 586 | GNUNET_CONFIGURATION_get_value_number(cfg, |
574 | "FSPROFILER", "REPLICATION_LEVEL", | 587 | "FSPROFILER", "REPLICATION_LEVEL", |
575 | &replication_level)) | 588 | &replication_level)) |
576 | replication_level = 1; | 589 | replication_level = 1; |
577 | GNUNET_snprintf (myoptname, sizeof (myoptname), | 590 | GNUNET_snprintf(myoptname, sizeof(myoptname), |
578 | "DOWNLOAD-PATTERN-%u", my_peerid); | 591 | "DOWNLOAD-PATTERN-%u", my_peerid); |
579 | if (GNUNET_OK != | 592 | if (GNUNET_OK != |
580 | GNUNET_CONFIGURATION_get_value_string (cfg, | 593 | GNUNET_CONFIGURATION_get_value_string(cfg, |
581 | "FSPROFILER", myoptname, | 594 | "FSPROFILER", myoptname, |
582 | &download_pattern)) | 595 | &download_pattern)) |
583 | download_pattern = GNUNET_strdup (""); | 596 | download_pattern = GNUNET_strdup(""); |
584 | GNUNET_snprintf (myoptname, sizeof (myoptname), | 597 | GNUNET_snprintf(myoptname, sizeof(myoptname), |
585 | "PUBLISH-PATTERN-%u", my_peerid); | 598 | "PUBLISH-PATTERN-%u", my_peerid); |
586 | if (GNUNET_OK != | 599 | if (GNUNET_OK != |
587 | GNUNET_CONFIGURATION_get_value_string (cfg, | 600 | GNUNET_CONFIGURATION_get_value_string(cfg, |
588 | "FSPROFILER", myoptname, | 601 | "FSPROFILER", myoptname, |
589 | &publish_pattern)) | 602 | &publish_pattern)) |
590 | publish_pattern = GNUNET_strdup (""); | 603 | publish_pattern = GNUNET_strdup(""); |
591 | if ( (GNUNET_OK != | 604 | if ((GNUNET_OK != |
592 | parse_pattern (&download_head, | 605 | parse_pattern(&download_head, |
593 | &download_tail, | 606 | &download_tail, |
594 | download_pattern)) || | 607 | download_pattern)) || |
595 | (GNUNET_OK != | 608 | (GNUNET_OK != |
596 | parse_pattern (&publish_head, | 609 | parse_pattern(&publish_head, |
597 | &publish_tail, | 610 | &publish_tail, |
598 | publish_pattern)) ) | 611 | publish_pattern))) |
599 | { | 612 | { |
600 | GNUNET_SCHEDULER_shutdown (); | 613 | GNUNET_SCHEDULER_shutdown(); |
601 | return; | 614 | return; |
602 | } | 615 | } |
603 | 616 | ||
604 | stats_handle = GNUNET_STATISTICS_create ("fsprofiler", cfg); | 617 | stats_handle = GNUNET_STATISTICS_create("fsprofiler", cfg); |
605 | fs_handle = | 618 | fs_handle = |
606 | GNUNET_FS_start (cfg, | 619 | GNUNET_FS_start(cfg, |
607 | "fsprofiler", | 620 | "fsprofiler", |
608 | &progress_cb, NULL, | 621 | &progress_cb, NULL, |
609 | GNUNET_FS_FLAGS_NONE, | 622 | GNUNET_FS_FLAGS_NONE, |
610 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 1, | 623 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 1, |
611 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 1, | 624 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 1, |
612 | GNUNET_FS_OPTIONS_END); | 625 | GNUNET_FS_OPTIONS_END); |
613 | if (NULL == fs_handle) | 626 | if (NULL == fs_handle) |
614 | { | 627 | { |
615 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not acquire FS handle. Exiting.\n"); | 628 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not acquire FS handle. Exiting.\n"); |
616 | global_ret = GNUNET_SYSERR; | 629 | global_ret = GNUNET_SYSERR; |
617 | GNUNET_SCHEDULER_shutdown (); | 630 | GNUNET_SCHEDULER_shutdown(); |
618 | return; | 631 | return; |
619 | } | 632 | } |
620 | for (p = publish_head; NULL != p; p = p->next) | 633 | for (p = publish_head; NULL != p; p = p->next) |
621 | p->task = GNUNET_SCHEDULER_add_delayed (p->delay, | 634 | p->task = GNUNET_SCHEDULER_add_delayed(p->delay, |
622 | &start_publish, p); | 635 | &start_publish, p); |
623 | for (p = download_head; NULL != p; p = p->next) | 636 | for (p = download_head; NULL != p; p = p->next) |
624 | p->task = GNUNET_SCHEDULER_add_delayed (p->delay, | 637 | p->task = GNUNET_SCHEDULER_add_delayed(p->delay, |
625 | &start_download, p); | 638 | &start_download, p); |
626 | } | 639 | } |
627 | 640 | ||
628 | 641 | ||
@@ -634,19 +647,19 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
634 | * @return 0 ok, 1 on error | 647 | * @return 0 ok, 1 on error |
635 | */ | 648 | */ |
636 | int | 649 | int |
637 | main (int argc, char *const *argv) | 650 | main(int argc, char *const *argv) |
638 | { | 651 | { |
639 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 652 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
640 | GNUNET_GETOPT_OPTION_END | 653 | GNUNET_GETOPT_OPTION_END |
641 | }; | 654 | }; |
642 | 655 | ||
643 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 656 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
644 | return 2; | 657 | return 2; |
645 | return (GNUNET_OK == | 658 | return (GNUNET_OK == |
646 | GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-fsprofiler", | 659 | GNUNET_PROGRAM_run(argc, argv, "gnunet-daemon-fsprofiler", |
647 | gettext_noop | 660 | gettext_noop |
648 | ("Daemon to use file-sharing to measure its performance."), | 661 | ("Daemon to use file-sharing to measure its performance."), |
649 | options, &run, NULL)) ? global_ret : 1; | 662 | options, &run, NULL)) ? global_ret : 1; |
650 | } | 663 | } |
651 | 664 | ||
652 | /* end of gnunet-daemon-fsprofiler.c */ | 665 | /* end of gnunet-daemon-fsprofiler.c */ |
diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c index 4cce69d72..f33db109f 100644 --- a/src/fs/gnunet-directory.c +++ b/src/fs/gnunet-directory.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/gnunet-directory.c | 21 | * @file fs/gnunet-directory.c |
22 | * @brief display content of GNUnet directories | 22 | * @brief display content of GNUnet directories |
@@ -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)))) | ||
157 | { | 151 | { |
158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 152 | if ((GNUNET_OK != |
159 | _ ("Failed to read directory `%s'\n"), | 153 | GNUNET_DISK_file_size(filename, &size, GNUNET_YES, GNUNET_YES)) || |
160 | filename); | 154 | (NULL == (h = GNUNET_DISK_file_open(filename, |
161 | ret = 1; | 155 | GNUNET_DISK_OPEN_READ, |
162 | continue; | 156 | GNUNET_DISK_PERM_NONE)))) |
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); | ||
163 | } | 174 | } |
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,26 +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 | 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)) |
191 | return 2; | 192 | return 2; |
192 | 193 | ||
193 | ret = (GNUNET_OK == | 194 | ret = (GNUNET_OK == |
194 | GNUNET_PROGRAM_run (argc, | 195 | GNUNET_PROGRAM_run(argc, |
195 | argv, | 196 | argv, |
196 | "gnunet-directory [OPTIONS] FILENAME", | 197 | "gnunet-directory [OPTIONS] FILENAME", |
197 | gettext_noop ( | 198 | gettext_noop( |
198 | "Display contents of a GNUnet directory"), | 199 | "Display contents of a GNUnet directory"), |
199 | options, | 200 | options, |
200 | &run, | 201 | &run, |
201 | NULL)) | 202 | NULL)) |
202 | ? ret | 203 | ? ret |
203 | : 1; | 204 | : 1; |
204 | GNUNET_free ((void *) argv); | 205 | GNUNET_free((void *)argv); |
205 | return ret; | 206 | return ret; |
206 | } | 207 | } |
207 | 208 | ||
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index 00e8336a2..eda6765ab 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/gnunet-download.c | 21 | * @file fs/gnunet-download.c |
22 | * @brief downloading for files on GNUnet | 22 | * @brief downloading for files on GNUnet |
@@ -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,30 +80,30 @@ 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 ! WINDOWS | 90 | #if !WINDOWS |
91 | if (0 == isatty (1)) | 91 | if (0 == isatty(1)) |
92 | return; | 92 | return; |
93 | #else | 93 | #else |
94 | if (FILE_TYPE_CHAR != GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) | 94 | if (FILE_TYPE_CHAR != GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))) |
95 | return; | 95 | return; |
96 | #endif | 96 | #endif |
97 | ratio_complete = x / (float) n; | 97 | ratio_complete = x / (float)n; |
98 | endeq = ratio_complete * w; | 98 | endeq = ratio_complete * w; |
99 | GNUNET_snprintf (buf, sizeof (buf), "%3d%% [", (int) (ratio_complete * 100)); | 99 | GNUNET_snprintf(buf, sizeof(buf), "%3d%% [", (int)(ratio_complete * 100)); |
100 | for (p = 0; p < endeq; p++) | 100 | for (p = 0; p < endeq; p++) |
101 | strcat (buf, "="); | 101 | strcat(buf, "="); |
102 | for (p = endeq; p < w; p++) | 102 | for (p = endeq; p < w; p++) |
103 | strcat (buf, " "); | 103 | strcat(buf, " "); |
104 | strcat (buf, "]\r"); | 104 | strcat(buf, "]\r"); |
105 | printf ("%s", buf); | 105 | printf("%s", buf); |
106 | fflush (stdout); | 106 | fflush(stdout); |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
@@ -121,100 +121,106 @@ display_bar (unsigned long long x, unsigned long long n, unsigned int w) | |||
121 | * field in the `struct GNUNET_FS_ProgressInfo` | 121 | * field in the `struct GNUNET_FS_ProgressInfo` |
122 | */ | 122 | */ |
123 | static void * | 123 | static void * |
124 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | 124 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) |
125 | { | 125 | { |
126 | char *s; | 126 | char *s; |
127 | const char *s2; | 127 | const char *s2; |
128 | char *t; | 128 | char *t; |
129 | 129 | ||
130 | switch (info->status) | 130 | switch (info->status) |
131 | { | ||
132 | case GNUNET_FS_STATUS_DOWNLOAD_START: | ||
133 | if (verbose > 1) | ||
134 | fprintf (stderr, | ||
135 | _ ("Starting download `%s'.\n"), | ||
136 | info->value.download.filename); | ||
137 | break; | ||
138 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
139 | if (verbose) | ||
140 | { | 131 | { |
141 | s = GNUNET_strdup ( | 132 | case GNUNET_FS_STATUS_DOWNLOAD_START: |
142 | GNUNET_STRINGS_relative_time_to_string (info->value.download.eta, | 133 | if (verbose > 1) |
143 | GNUNET_YES)); | 134 | fprintf(stderr, |
144 | if (info->value.download.specifics.progress.block_download_duration | 135 | _("Starting download `%s'.\n"), |
145 | .rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) | 136 | info->value.download.filename); |
146 | s2 = _ ("<unknown time>"); | 137 | break; |
138 | |||
139 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
140 | if (verbose) | ||
141 | { | ||
142 | s = GNUNET_strdup( | ||
143 | GNUNET_STRINGS_relative_time_to_string(info->value.download.eta, | ||
144 | GNUNET_YES)); | ||
145 | if (info->value.download.specifics.progress.block_download_duration | ||
146 | .rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) | ||
147 | s2 = _("<unknown time>"); | ||
148 | else | ||
149 | s2 = GNUNET_STRINGS_relative_time_to_string(info->value.download | ||
150 | .specifics.progress | ||
151 | .block_download_duration, | ||
152 | GNUNET_YES); | ||
153 | t = GNUNET_STRINGS_byte_size_fancy( | ||
154 | info->value.download.completed * 1000LL / | ||
155 | (info->value.download.duration.rel_value_us + 1)); | ||
156 | fprintf( | ||
157 | stdout, | ||
158 | _( | ||
159 | "Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), | ||
160 | info->value.download.filename, | ||
161 | (unsigned long long)info->value.download.completed, | ||
162 | (unsigned long long)info->value.download.size, | ||
163 | s, | ||
164 | t, | ||
165 | s2); | ||
166 | GNUNET_free(s); | ||
167 | GNUNET_free(t); | ||
168 | } | ||
147 | else | 169 | else |
148 | s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download | 170 | { |
149 | .specifics.progress | 171 | display_bar(info->value.download.completed, |
150 | .block_download_duration, | 172 | info->value.download.size, |
151 | GNUNET_YES); | 173 | 60); |
152 | t = GNUNET_STRINGS_byte_size_fancy ( | 174 | } |
153 | info->value.download.completed * 1000LL / | 175 | break; |
154 | (info->value.download.duration.rel_value_us + 1)); | 176 | |
155 | fprintf ( | 177 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: |
156 | stdout, | 178 | #if !WINDOWS |
157 | _ ( | 179 | if (0 != isatty(1)) |
158 | "Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), | 180 | fprintf(stdout, "\n"); |
159 | info->value.download.filename, | ||
160 | (unsigned long long) info->value.download.completed, | ||
161 | (unsigned long long) info->value.download.size, | ||
162 | s, | ||
163 | t, | ||
164 | s2); | ||
165 | GNUNET_free (s); | ||
166 | GNUNET_free (t); | ||
167 | } | ||
168 | else | ||
169 | { | ||
170 | display_bar (info->value.download.completed, | ||
171 | info->value.download.size, | ||
172 | 60); | ||
173 | } | ||
174 | break; | ||
175 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | ||
176 | #if ! WINDOWS | ||
177 | if (0 != isatty (1)) | ||
178 | fprintf (stdout, "\n"); | ||
179 | #else | 181 | #else |
180 | if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) | 182 | if (FILE_TYPE_CHAR == GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))) |
181 | fprintf (stdout, "\n"); | 183 | fprintf(stdout, "\n"); |
182 | #endif | 184 | #endif |
183 | fprintf (stderr, | 185 | fprintf(stderr, |
184 | _ ("Error downloading: %s.\n"), | 186 | _("Error downloading: %s.\n"), |
185 | info->value.download.specifics.error.message); | 187 | info->value.download.specifics.error.message); |
186 | GNUNET_SCHEDULER_shutdown (); | 188 | GNUNET_SCHEDULER_shutdown(); |
187 | break; | 189 | break; |
188 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 190 | |
189 | s = GNUNET_STRINGS_byte_size_fancy ( | 191 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
190 | info->value.download.completed * 1000 / | 192 | s = GNUNET_STRINGS_byte_size_fancy( |
191 | (info->value.download.duration.rel_value_us + 1)); | 193 | info->value.download.completed * 1000 / |
192 | #if ! WINDOWS | 194 | (info->value.download.duration.rel_value_us + 1)); |
193 | if (0 != isatty (1)) | 195 | #if !WINDOWS |
194 | fprintf (stdout, "\n"); | 196 | if (0 != isatty(1)) |
197 | fprintf(stdout, "\n"); | ||
195 | #else | 198 | #else |
196 | if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) | 199 | if (FILE_TYPE_CHAR == GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))) |
197 | fprintf (stdout, "\n"); | 200 | fprintf(stdout, "\n"); |
198 | #endif | 201 | #endif |
199 | fprintf (stdout, | 202 | fprintf(stdout, |
200 | _ ("Downloading `%s' done (%s/s).\n"), | 203 | _("Downloading `%s' done (%s/s).\n"), |
201 | info->value.download.filename, | 204 | info->value.download.filename, |
202 | s); | 205 | s); |
203 | GNUNET_free (s); | 206 | GNUNET_free(s); |
204 | if (info->value.download.dc == dc) | 207 | if (info->value.download.dc == dc) |
205 | GNUNET_SCHEDULER_shutdown (); | 208 | GNUNET_SCHEDULER_shutdown(); |
206 | break; | 209 | break; |
207 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | 210 | |
208 | if (info->value.download.dc == dc) | 211 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: |
209 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | 212 | if (info->value.download.dc == dc) |
210 | break; | 213 | GNUNET_SCHEDULER_add_now(&cleanup_task, NULL); |
211 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | 214 | break; |
212 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | 215 | |
213 | break; | 216 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: |
214 | default: | 217 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: |
215 | fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); | 218 | break; |
216 | break; | 219 | |
217 | } | 220 | default: |
221 | fprintf(stderr, _("Unexpected status: %d\n"), info->status); | ||
222 | break; | ||
223 | } | ||
218 | return NULL; | 224 | return NULL; |
219 | } | 225 | } |
220 | 226 | ||
@@ -228,84 +234,84 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
228 | * @param c configuration | 234 | * @param c configuration |
229 | */ | 235 | */ |
230 | static void | 236 | static void |
231 | run (void *cls, | 237 | run(void *cls, |
232 | char *const *args, | 238 | char *const *args, |
233 | const char *cfgfile, | 239 | const char *cfgfile, |
234 | const struct GNUNET_CONFIGURATION_Handle *c) | 240 | const struct GNUNET_CONFIGURATION_Handle *c) |
235 | { | 241 | { |
236 | struct GNUNET_FS_Uri *uri; | 242 | struct GNUNET_FS_Uri *uri; |
237 | char *emsg; | 243 | char *emsg; |
238 | enum GNUNET_FS_DownloadOptions options; | 244 | enum GNUNET_FS_DownloadOptions options; |
239 | 245 | ||
240 | if (NULL == args[0]) | 246 | if (NULL == args[0]) |
241 | { | 247 | { |
242 | fprintf (stderr, "%s", _ ("You need to specify a URI argument.\n")); | 248 | fprintf(stderr, "%s", _("You need to specify a URI argument.\n")); |
243 | return; | 249 | return; |
244 | } | 250 | } |
245 | uri = GNUNET_FS_uri_parse (args[0], &emsg); | 251 | uri = GNUNET_FS_uri_parse(args[0], &emsg); |
246 | if (NULL == uri) | 252 | if (NULL == uri) |
247 | { | 253 | { |
248 | fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg); | 254 | fprintf(stderr, _("Failed to parse URI: %s\n"), emsg); |
249 | GNUNET_free (emsg); | 255 | GNUNET_free(emsg); |
250 | ret = 1; | 256 | ret = 1; |
251 | return; | 257 | return; |
252 | } | 258 | } |
253 | if ((! GNUNET_FS_uri_test_chk (uri)) && (! GNUNET_FS_uri_test_loc (uri))) | 259 | if ((!GNUNET_FS_uri_test_chk(uri)) && (!GNUNET_FS_uri_test_loc(uri))) |
254 | { | 260 | { |
255 | fprintf (stderr, "%s", _ ("Only CHK or LOC URIs supported.\n")); | 261 | fprintf(stderr, "%s", _("Only CHK or LOC URIs supported.\n")); |
256 | ret = 1; | 262 | ret = 1; |
257 | GNUNET_FS_uri_destroy (uri); | 263 | GNUNET_FS_uri_destroy(uri); |
258 | return; | 264 | return; |
259 | } | 265 | } |
260 | if (NULL == filename) | 266 | if (NULL == filename) |
261 | { | 267 | { |
262 | fprintf (stderr, "%s", _ ("Target filename must be specified.\n")); | 268 | fprintf(stderr, "%s", _("Target filename must be specified.\n")); |
263 | ret = 1; | 269 | ret = 1; |
264 | GNUNET_FS_uri_destroy (uri); | 270 | GNUNET_FS_uri_destroy(uri); |
265 | return; | 271 | return; |
266 | } | 272 | } |
267 | cfg = c; | 273 | cfg = c; |
268 | ctx = GNUNET_FS_start (cfg, | 274 | ctx = GNUNET_FS_start(cfg, |
269 | "gnunet-download", | 275 | "gnunet-download", |
270 | &progress_cb, | 276 | &progress_cb, |
271 | NULL, | 277 | NULL, |
272 | GNUNET_FS_FLAGS_NONE, | 278 | GNUNET_FS_FLAGS_NONE, |
273 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, | 279 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, |
274 | parallelism, | 280 | parallelism, |
275 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, | 281 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, |
276 | request_parallelism, | 282 | request_parallelism, |
277 | GNUNET_FS_OPTIONS_END); | 283 | GNUNET_FS_OPTIONS_END); |
278 | if (NULL == ctx) | 284 | if (NULL == ctx) |
279 | { | 285 | { |
280 | fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); | 286 | fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); |
281 | GNUNET_FS_uri_destroy (uri); | 287 | GNUNET_FS_uri_destroy(uri); |
282 | ret = 1; | 288 | ret = 1; |
283 | return; | 289 | return; |
284 | } | 290 | } |
285 | options = GNUNET_FS_DOWNLOAD_OPTION_NONE; | 291 | options = GNUNET_FS_DOWNLOAD_OPTION_NONE; |
286 | if (do_recursive) | 292 | if (do_recursive) |
287 | options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; | 293 | options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; |
288 | if (local_only) | 294 | if (local_only) |
289 | options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; | 295 | options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; |
290 | dc = GNUNET_FS_download_start (ctx, | 296 | dc = GNUNET_FS_download_start(ctx, |
291 | uri, | 297 | uri, |
292 | NULL, | 298 | NULL, |
293 | filename, | 299 | filename, |
294 | NULL, | 300 | NULL, |
295 | 0, | 301 | 0, |
296 | GNUNET_FS_uri_chk_get_file_size (uri), | 302 | GNUNET_FS_uri_chk_get_file_size(uri), |
297 | anonymity, | 303 | anonymity, |
298 | options, | 304 | options, |
299 | NULL, | 305 | NULL, |
300 | NULL); | 306 | NULL); |
301 | GNUNET_FS_uri_destroy (uri); | 307 | GNUNET_FS_uri_destroy(uri); |
302 | if (dc == NULL) | 308 | if (dc == NULL) |
303 | { | 309 | { |
304 | GNUNET_FS_stop (ctx); | 310 | GNUNET_FS_stop(ctx); |
305 | ctx = NULL; | 311 | ctx = NULL; |
306 | return; | 312 | return; |
307 | } | 313 | } |
308 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 314 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
309 | } | 315 | } |
310 | 316 | ||
311 | 317 | ||
@@ -317,75 +323,75 @@ run (void *cls, | |||
317 | * @return 0 ok, 1 on error | 323 | * @return 0 ok, 1 on error |
318 | */ | 324 | */ |
319 | int | 325 | int |
320 | main (int argc, char *const *argv) | 326 | main(int argc, char *const *argv) |
321 | { | 327 | { |
322 | struct GNUNET_GETOPT_CommandLineOption options[] = | 328 | struct GNUNET_GETOPT_CommandLineOption options[] = |
323 | {GNUNET_GETOPT_option_uint ('a', | 329 | { GNUNET_GETOPT_option_uint('a', |
324 | "anonymity", | 330 | "anonymity", |
325 | "LEVEL", | 331 | "LEVEL", |
326 | gettext_noop ( | 332 | gettext_noop( |
327 | "set the desired LEVEL of receiver-anonymity"), | 333 | "set the desired LEVEL of receiver-anonymity"), |
328 | &anonymity), | 334 | &anonymity), |
329 | 335 | ||
330 | GNUNET_GETOPT_option_flag ( | 336 | GNUNET_GETOPT_option_flag( |
331 | 'D', | 337 | 'D', |
332 | "delete-incomplete", | 338 | "delete-incomplete", |
333 | gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), | 339 | gettext_noop("delete incomplete downloads (when aborted with CTRL-C)"), |
334 | &delete_incomplete), | 340 | &delete_incomplete), |
335 | 341 | ||
336 | GNUNET_GETOPT_option_flag ( | 342 | GNUNET_GETOPT_option_flag( |
337 | 'n', | 343 | 'n', |
338 | "no-network", | 344 | "no-network", |
339 | gettext_noop ("only search the local peer (no P2P network search)"), | 345 | gettext_noop("only search the local peer (no P2P network search)"), |
340 | &local_only), | 346 | &local_only), |
341 | GNUNET_GETOPT_option_string ('o', | 347 | GNUNET_GETOPT_option_string('o', |
342 | "output", | 348 | "output", |
343 | "FILENAME", | 349 | "FILENAME", |
344 | gettext_noop ("write the file to FILENAME"), | 350 | gettext_noop("write the file to FILENAME"), |
345 | &filename), | 351 | &filename), |
346 | GNUNET_GETOPT_option_uint ( | 352 | GNUNET_GETOPT_option_uint( |
347 | 'p', | 353 | 'p', |
348 | "parallelism", | 354 | "parallelism", |
349 | "DOWNLOADS", | 355 | "DOWNLOADS", |
350 | gettext_noop ( | 356 | gettext_noop( |
351 | "set the maximum number of parallel downloads that is allowed"), | 357 | "set the maximum number of parallel downloads that is allowed"), |
352 | ¶llelism), | 358 | ¶llelism), |
353 | GNUNET_GETOPT_option_uint ( | 359 | GNUNET_GETOPT_option_uint( |
354 | 'r', | 360 | 'r', |
355 | "request-parallelism", | 361 | "request-parallelism", |
356 | "REQUESTS", | 362 | "REQUESTS", |
357 | gettext_noop ( | 363 | gettext_noop( |
358 | "set the maximum number of parallel requests for blocks that is allowed"), | 364 | "set the maximum number of parallel requests for blocks that is allowed"), |
359 | &request_parallelism), | 365 | &request_parallelism), |
360 | GNUNET_GETOPT_option_flag ('R', | 366 | GNUNET_GETOPT_option_flag('R', |
361 | "recursive", | 367 | "recursive", |
362 | gettext_noop ( | 368 | gettext_noop( |
363 | "download a GNUnet directory recursively"), | 369 | "download a GNUnet directory recursively"), |
364 | &do_recursive), | 370 | &do_recursive), |
365 | GNUNET_GETOPT_option_increment_uint ( | 371 | GNUNET_GETOPT_option_increment_uint( |
366 | 'V', | 372 | 'V', |
367 | "verbose", | 373 | "verbose", |
368 | gettext_noop ("be verbose (print progress information)"), | 374 | gettext_noop("be verbose (print progress information)"), |
369 | &verbose), | 375 | &verbose), |
370 | GNUNET_GETOPT_OPTION_END}; | 376 | GNUNET_GETOPT_OPTION_END }; |
371 | 377 | ||
372 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 378 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
373 | return 2; | 379 | return 2; |
374 | 380 | ||
375 | ret = | 381 | ret = |
376 | (GNUNET_OK == | 382 | (GNUNET_OK == |
377 | GNUNET_PROGRAM_run ( | 383 | GNUNET_PROGRAM_run( |
378 | argc, | 384 | argc, |
379 | argv, | 385 | argv, |
380 | "gnunet-download [OPTIONS] URI", | 386 | "gnunet-download [OPTIONS] URI", |
381 | gettext_noop ( | 387 | gettext_noop( |
382 | "Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), | 388 | "Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), |
383 | options, | 389 | options, |
384 | &run, | 390 | &run, |
385 | NULL)) | 391 | NULL)) |
386 | ? ret | 392 | ? ret |
387 | : 1; | 393 | : 1; |
388 | GNUNET_free ((void *) argv); | 394 | GNUNET_free((void *)argv); |
389 | return ret; | 395 | return ret; |
390 | } | 396 | } |
391 | 397 | ||
diff --git a/src/fs/gnunet-fs-profiler.c b/src/fs/gnunet-fs-profiler.c index 8a71c5a59..d47ca8b29 100644 --- a/src/fs/gnunet-fs-profiler.c +++ b/src/fs/gnunet-fs-profiler.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-fs-profiler.c | 22 | * @file fs/gnunet-fs-profiler.c |
@@ -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,38 @@ 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 | 207 | GNUNET_GETOPT_option_uint('n', | |
208 | GNUNET_GETOPT_option_uint ('n', | 208 | "num-peers", |
209 | "num-peers", | 209 | "COUNT", |
210 | "COUNT", | 210 | gettext_noop("run the experiment with COUNT peers"), |
211 | gettext_noop ("run the experiment with COUNT peers"), | 211 | &num_peers), |
212 | &num_peers), | 212 | |
213 | 213 | GNUNET_GETOPT_option_string('H', | |
214 | GNUNET_GETOPT_option_string ('H', | 214 | "hosts", |
215 | "hosts", | 215 | "HOSTFILE", |
216 | "HOSTFILE", | 216 | gettext_noop("specifies name of a file with the HOSTS the testbed should use"), |
217 | gettext_noop ("specifies name of a file with the HOSTS the testbed should use"), | 217 | &host_filename), |
218 | &host_filename), | 218 | |
219 | 219 | GNUNET_GETOPT_option_relative_time('t', | |
220 | GNUNET_GETOPT_option_relative_time ('t', | 220 | "timeout", |
221 | "timeout", | 221 | "DELAY", |
222 | "DELAY", | 222 | gettext_noop("automatically terminate experiment after DELAY"), |
223 | gettext_noop ("automatically terminate experiment after DELAY"), | 223 | &timeout), |
224 | &timeout), | ||
225 | 224 | ||
226 | GNUNET_GETOPT_OPTION_END | 225 | GNUNET_GETOPT_OPTION_END |
227 | }; | 226 | }; |
228 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 227 | |
228 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | ||
229 | return 2; | 229 | return 2; |
230 | 230 | ||
231 | ret = (GNUNET_OK == | 231 | ret = (GNUNET_OK == |
232 | GNUNET_PROGRAM_run (argc, argv, "gnunet-fs-profiler", | 232 | GNUNET_PROGRAM_run(argc, argv, "gnunet-fs-profiler", |
233 | gettext_noop ("run a testbed to measure file-sharing performance"), options, &run, | 233 | gettext_noop("run a testbed to measure file-sharing performance"), options, &run, |
234 | NULL)) ? ret : 1; | 234 | NULL)) ? ret : 1; |
235 | GNUNET_free ((void*) argv); | 235 | GNUNET_free((void*)argv); |
236 | return ret; | 236 | return ret; |
237 | } | 237 | } |
238 | 238 | ||
diff --git a/src/fs/gnunet-fs.c b/src/fs/gnunet-fs.c index ad2a8d6c5..3fa65d6cb 100644 --- a/src/fs/gnunet-fs.c +++ b/src/fs/gnunet-fs.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/gnunet-fs.c | 21 | * @file fs/gnunet-fs.c |
22 | * @brief special file-sharing functions | 22 | * @brief special file-sharing functions |
@@ -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) | ||
99 | { | 91 | { |
100 | ret = 1; | 92 | fs = GNUNET_FS_start(cfg, |
101 | return; | 93 | "gnunet-fs", |
94 | NULL, | ||
95 | NULL, | ||
96 | GNUNET_FS_FLAGS_NONE, | ||
97 | GNUNET_FS_OPTIONS_END); | ||
98 | if (NULL == fs) | ||
99 | { | ||
100 | ret = 1; | ||
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 | } | ||
102 | } | 110 | } |
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 | } | ||
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', | ||
125 | "list-indexed", | ||
126 | gettext_noop( | ||
127 | "print a list of all indexed files"), | ||
128 | &list_indexed_files), | ||
124 | 129 | ||
125 | GNUNET_GETOPT_option_flag ('i', | 130 | GNUNET_GETOPT_option_verbose(&verbose), |
126 | "list-indexed", | 131 | GNUNET_GETOPT_OPTION_END |
127 | gettext_noop ( | 132 | }; |
128 | "print a list of all indexed files"), | ||
129 | &list_indexed_files), | ||
130 | |||
131 | GNUNET_GETOPT_option_verbose (&verbose), | ||
132 | GNUNET_GETOPT_OPTION_END}; | ||
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 dcb4b47cd..db74e65aa 100644 --- a/src/fs/gnunet-helper-fs-publish.c +++ b/src/fs/gnunet-helper-fs-publish.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file src/fs/gnunet-helper-fs-publish.c | 22 | * @file src/fs/gnunet-helper-fs-publish.c |
@@ -33,9 +33,7 @@ | |||
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 | { | ||
38 | |||
39 | /** | 37 | /** |
40 | * This is a doubly-linked list | 38 | * This is a doubly-linked list |
41 | */ | 39 | */ |
@@ -113,41 +111,41 @@ static int output_stream; | |||
113 | * @return always 0 to continue extracting | 111 | * @return always 0 to continue extracting |
114 | */ | 112 | */ |
115 | static int | 113 | static int |
116 | add_to_md (void *cls, | 114 | add_to_md(void *cls, |
117 | const char *plugin_name, | 115 | const char *plugin_name, |
118 | enum EXTRACTOR_MetaType type, | 116 | enum EXTRACTOR_MetaType type, |
119 | enum EXTRACTOR_MetaFormat format, | 117 | enum EXTRACTOR_MetaFormat format, |
120 | const char *data_mime_type, | 118 | const char *data_mime_type, |
121 | const char *data, | 119 | const char *data, |
122 | size_t data_len) | 120 | size_t data_len) |
123 | { | 121 | { |
124 | struct GNUNET_CONTAINER_MetaData *md = cls; | 122 | struct GNUNET_CONTAINER_MetaData *md = cls; |
125 | 123 | ||
126 | if (((EXTRACTOR_METAFORMAT_UTF8 == format) || | 124 | if (((EXTRACTOR_METAFORMAT_UTF8 == format) || |
127 | (EXTRACTOR_METAFORMAT_C_STRING == format)) && | 125 | (EXTRACTOR_METAFORMAT_C_STRING == format)) && |
128 | ('\0' != data[data_len - 1])) | 126 | ('\0' != data[data_len - 1])) |
129 | { | 127 | { |
130 | char zdata[data_len + 1]; | 128 | char zdata[data_len + 1]; |
131 | GNUNET_memcpy (zdata, data, data_len); | 129 | GNUNET_memcpy(zdata, data, data_len); |
132 | zdata[data_len] = '\0'; | 130 | zdata[data_len] = '\0'; |
133 | (void) GNUNET_CONTAINER_meta_data_insert (md, | 131 | (void)GNUNET_CONTAINER_meta_data_insert(md, |
134 | plugin_name, | 132 | plugin_name, |
135 | type, | 133 | type, |
136 | format, | 134 | format, |
137 | data_mime_type, | 135 | data_mime_type, |
138 | zdata, | 136 | zdata, |
139 | data_len + 1); | 137 | data_len + 1); |
140 | } | 138 | } |
141 | else | 139 | else |
142 | { | 140 | { |
143 | (void) GNUNET_CONTAINER_meta_data_insert (md, | 141 | (void)GNUNET_CONTAINER_meta_data_insert(md, |
144 | plugin_name, | 142 | plugin_name, |
145 | type, | 143 | type, |
146 | format, | 144 | format, |
147 | data_mime_type, | 145 | data_mime_type, |
148 | data, | 146 | data, |
149 | data_len); | 147 | data_len); |
150 | } | 148 | } |
151 | return 0; | 149 | return 0; |
152 | } | 150 | } |
153 | #endif | 151 | #endif |
@@ -159,18 +157,18 @@ add_to_md (void *cls, | |||
159 | * @param tree tree to free | 157 | * @param tree tree to free |
160 | */ | 158 | */ |
161 | static void | 159 | static void |
162 | free_tree (struct ScanTreeNode *tree) | 160 | free_tree(struct ScanTreeNode *tree) |
163 | { | 161 | { |
164 | struct ScanTreeNode *pos; | 162 | struct ScanTreeNode *pos; |
165 | 163 | ||
166 | while (NULL != (pos = tree->children_head)) | 164 | while (NULL != (pos = tree->children_head)) |
167 | free_tree (pos); | 165 | free_tree(pos); |
168 | if (NULL != tree->parent) | 166 | if (NULL != tree->parent) |
169 | GNUNET_CONTAINER_DLL_remove (tree->parent->children_head, | 167 | GNUNET_CONTAINER_DLL_remove(tree->parent->children_head, |
170 | tree->parent->children_tail, | 168 | tree->parent->children_tail, |
171 | tree); | 169 | tree); |
172 | GNUNET_free (tree->filename); | 170 | GNUNET_free(tree->filename); |
173 | GNUNET_free (tree); | 171 | GNUNET_free(tree); |
174 | } | 172 | } |
175 | 173 | ||
176 | 174 | ||
@@ -182,7 +180,7 @@ free_tree (struct ScanTreeNode *tree) | |||
182 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 180 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
183 | */ | 181 | */ |
184 | static int | 182 | static int |
185 | write_all (const void *buf, size_t size) | 183 | write_all(const void *buf, size_t size) |
186 | { | 184 | { |
187 | const char *cbuf = buf; | 185 | const char *cbuf = buf; |
188 | size_t total; | 186 | size_t total; |
@@ -190,15 +188,16 @@ write_all (const void *buf, size_t size) | |||
190 | 188 | ||
191 | total = 0; | 189 | total = 0; |
192 | do | 190 | do |
193 | { | 191 | { |
194 | wr = write (output_stream, &cbuf[total], size - total); | 192 | wr = write(output_stream, &cbuf[total], size - total); |
195 | if (wr > 0) | 193 | if (wr > 0) |
196 | total += wr; | 194 | total += wr; |
197 | } while ((wr > 0) && (total < size)); | 195 | } |
196 | while ((wr > 0) && (total < size)); | ||
198 | if (wr <= 0) | 197 | if (wr <= 0) |
199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 198 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
200 | "Failed to write to stdout: %s\n", | 199 | "Failed to write to stdout: %s\n", |
201 | strerror (errno)); | 200 | strerror(errno)); |
202 | return (total == size) ? GNUNET_OK : GNUNET_SYSERR; | 201 | return (total == size) ? GNUNET_OK : GNUNET_SYSERR; |
203 | } | 202 | } |
204 | 203 | ||
@@ -212,20 +211,20 @@ write_all (const void *buf, size_t size) | |||
212 | * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) | 211 | * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) |
213 | */ | 212 | */ |
214 | static int | 213 | static int |
215 | write_message (uint16_t message_type, const char *data, size_t data_length) | 214 | write_message(uint16_t message_type, const char *data, size_t data_length) |
216 | { | 215 | { |
217 | struct GNUNET_MessageHeader hdr; | 216 | struct GNUNET_MessageHeader hdr; |
218 | 217 | ||
219 | #if 0 | 218 | #if 0 |
220 | fprintf (stderr, | 219 | fprintf(stderr, |
221 | "Helper sends %u-byte message of type %u\n", | 220 | "Helper sends %u-byte message of type %u\n", |
222 | (unsigned int) (sizeof (struct GNUNET_MessageHeader) + data_length), | 221 | (unsigned int)(sizeof(struct GNUNET_MessageHeader) + data_length), |
223 | (unsigned int) message_type); | 222 | (unsigned int)message_type); |
224 | #endif | 223 | #endif |
225 | hdr.type = htons (message_type); | 224 | hdr.type = htons(message_type); |
226 | hdr.size = htons (sizeof (struct GNUNET_MessageHeader) + data_length); | 225 | hdr.size = htons(sizeof(struct GNUNET_MessageHeader) + data_length); |
227 | if ((GNUNET_OK != write_all (&hdr, sizeof (hdr))) || | 226 | if ((GNUNET_OK != write_all(&hdr, sizeof(hdr))) || |
228 | (GNUNET_OK != write_all (data, data_length))) | 227 | (GNUNET_OK != write_all(data, data_length))) |
229 | return GNUNET_SYSERR; | 228 | return GNUNET_SYSERR; |
230 | return GNUNET_OK; | 229 | return GNUNET_OK; |
231 | } | 230 | } |
@@ -242,14 +241,13 @@ write_message (uint16_t message_type, const char *data, size_t data_length) | |||
242 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 241 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
243 | */ | 242 | */ |
244 | static int | 243 | static int |
245 | preprocess_file (const char *filename, struct ScanTreeNode **dst); | 244 | preprocess_file(const char *filename, struct ScanTreeNode **dst); |
246 | 245 | ||
247 | 246 | ||
248 | /** | 247 | /** |
249 | * Closure for the 'scan_callback' | 248 | * Closure for the 'scan_callback' |
250 | */ | 249 | */ |
251 | struct RecursionContext | 250 | struct RecursionContext { |
252 | { | ||
253 | /** | 251 | /** |
254 | * Parent to add the files to. | 252 | * Parent to add the files to. |
255 | */ | 253 | */ |
@@ -272,22 +270,22 @@ struct RecursionContext | |||
272 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 270 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
273 | */ | 271 | */ |
274 | static int | 272 | static int |
275 | scan_callback (void *cls, const char *filename) | 273 | scan_callback(void *cls, const char *filename) |
276 | { | 274 | { |
277 | struct RecursionContext *rc = cls; | 275 | struct RecursionContext *rc = cls; |
278 | struct ScanTreeNode *chld; | 276 | struct ScanTreeNode *chld; |
279 | 277 | ||
280 | if (GNUNET_OK != preprocess_file (filename, &chld)) | 278 | if (GNUNET_OK != preprocess_file(filename, &chld)) |
281 | { | 279 | { |
282 | rc->stop = GNUNET_YES; | 280 | rc->stop = GNUNET_YES; |
283 | return GNUNET_SYSERR; | 281 | return GNUNET_SYSERR; |
284 | } | 282 | } |
285 | if (NULL == chld) | 283 | if (NULL == chld) |
286 | return GNUNET_OK; | 284 | return GNUNET_OK; |
287 | chld->parent = rc->parent; | 285 | chld->parent = rc->parent; |
288 | GNUNET_CONTAINER_DLL_insert (rc->parent->children_head, | 286 | GNUNET_CONTAINER_DLL_insert(rc->parent->children_head, |
289 | rc->parent->children_tail, | 287 | rc->parent->children_tail, |
290 | chld); | 288 | chld); |
291 | return GNUNET_OK; | 289 | return GNUNET_OK; |
292 | } | 290 | } |
293 | 291 | ||
@@ -303,60 +301,60 @@ scan_callback (void *cls, const char *filename) | |||
303 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 301 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
304 | */ | 302 | */ |
305 | static int | 303 | static int |
306 | preprocess_file (const char *filename, struct ScanTreeNode **dst) | 304 | preprocess_file(const char *filename, struct ScanTreeNode **dst) |
307 | { | 305 | { |
308 | struct ScanTreeNode *item; | 306 | struct ScanTreeNode *item; |
309 | struct stat sbuf; | 307 | struct stat sbuf; |
310 | uint64_t fsize = 0; | 308 | uint64_t fsize = 0; |
311 | 309 | ||
312 | if ((0 != stat (filename, &sbuf)) || | 310 | if ((0 != stat(filename, &sbuf)) || |
313 | ((! S_ISDIR (sbuf.st_mode)) && | 311 | ((!S_ISDIR(sbuf.st_mode)) && |
314 | (GNUNET_OK != | 312 | (GNUNET_OK != |
315 | GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)))) | 313 | GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES)))) |
316 | { | 314 | { |
317 | /* If the file doesn't exist (or is not stat-able for any other reason) | 315 | /* If the file doesn't exist (or is not stat-able for any other reason) |
318 | skip it (but report it), but do continue. */ | 316 | skip it (but report it), but do continue. */ |
319 | if (GNUNET_OK != | 317 | if (GNUNET_OK != |
320 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, | 318 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, |
321 | filename, | 319 | filename, |
322 | strlen (filename) + 1)) | 320 | strlen(filename) + 1)) |
323 | return GNUNET_SYSERR; | 321 | return GNUNET_SYSERR; |
324 | /* recoverable error, store 'NULL' in *dst */ | 322 | /* recoverable error, store 'NULL' in *dst */ |
325 | *dst = NULL; | 323 | *dst = NULL; |
326 | return GNUNET_OK; | 324 | return GNUNET_OK; |
327 | } | 325 | } |
328 | 326 | ||
329 | /* Report the progress */ | 327 | /* Report the progress */ |
330 | if ( | 328 | if ( |
331 | GNUNET_OK != | 329 | GNUNET_OK != |
332 | write_message (S_ISDIR (sbuf.st_mode) | 330 | write_message(S_ISDIR(sbuf.st_mode) |
333 | ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY | 331 | ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY |
334 | : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, | 332 | : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, |
335 | filename, | 333 | filename, |
336 | strlen (filename) + 1)) | 334 | strlen(filename) + 1)) |
337 | return GNUNET_SYSERR; | 335 | return GNUNET_SYSERR; |
338 | item = GNUNET_new (struct ScanTreeNode); | 336 | item = GNUNET_new(struct ScanTreeNode); |
339 | item->filename = GNUNET_strdup (filename); | 337 | item->filename = GNUNET_strdup(filename); |
340 | item->is_directory = (S_ISDIR (sbuf.st_mode)) ? GNUNET_YES : GNUNET_NO; | 338 | item->is_directory = (S_ISDIR(sbuf.st_mode)) ? GNUNET_YES : GNUNET_NO; |
341 | item->file_size = fsize; | 339 | item->file_size = fsize; |
342 | if (GNUNET_YES == item->is_directory) | 340 | 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))) | ||
355 | { | 341 | { |
356 | free_tree (item); | 342 | struct RecursionContext rc; |
357 | return GNUNET_SYSERR; | 343 | |
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 | } | ||
358 | } | 357 | } |
359 | } | ||
360 | *dst = item; | 358 | *dst = item; |
361 | return GNUNET_OK; | 359 | return GNUNET_OK; |
362 | } | 360 | } |
@@ -369,67 +367,67 @@ preprocess_file (const char *filename, struct ScanTreeNode **dst) | |||
369 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on fatal errors | 367 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on fatal errors |
370 | */ | 368 | */ |
371 | static int | 369 | static int |
372 | extract_files (struct ScanTreeNode *item) | 370 | extract_files(struct ScanTreeNode *item) |
373 | { | 371 | { |
374 | struct GNUNET_CONTAINER_MetaData *meta; | 372 | struct GNUNET_CONTAINER_MetaData *meta; |
375 | ssize_t size; | 373 | ssize_t size; |
376 | size_t slen; | 374 | size_t slen; |
377 | 375 | ||
378 | if (GNUNET_YES == item->is_directory) | 376 | if (GNUNET_YES == item->is_directory) |
379 | { | 377 | { |
380 | /* for directories, we simply only descent, no extraction, no | 378 | /* for directories, we simply only descent, no extraction, no |
381 | progress reporting */ | 379 | progress reporting */ |
382 | struct ScanTreeNode *pos; | 380 | struct ScanTreeNode *pos; |
383 | 381 | ||
384 | for (pos = item->children_head; NULL != pos; pos = pos->next) | 382 | for (pos = item->children_head; NULL != pos; pos = pos->next) |
385 | if (GNUNET_OK != extract_files (pos)) | 383 | if (GNUNET_OK != extract_files(pos)) |
386 | return GNUNET_SYSERR; | 384 | return GNUNET_SYSERR; |
387 | return GNUNET_OK; | 385 | return GNUNET_OK; |
388 | } | 386 | } |
389 | 387 | ||
390 | /* this is the expensive operation, *afterwards* we'll check for aborts */ | 388 | /* this is the expensive operation, *afterwards* we'll check for aborts */ |
391 | meta = GNUNET_CONTAINER_meta_data_create (); | 389 | meta = GNUNET_CONTAINER_meta_data_create(); |
392 | #if HAVE_LIBEXTRACTOR | 390 | #if HAVE_LIBEXTRACTOR |
393 | EXTRACTOR_extract (plugins, item->filename, NULL, 0, &add_to_md, meta); | 391 | EXTRACTOR_extract(plugins, item->filename, NULL, 0, &add_to_md, meta); |
394 | #endif | 392 | #endif |
395 | slen = strlen (item->filename) + 1; | 393 | slen = strlen(item->filename) + 1; |
396 | size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); | 394 | size = GNUNET_CONTAINER_meta_data_get_serialized_size(meta); |
397 | if (-1 == size) | 395 | if (-1 == size) |
398 | { | 396 | { |
399 | /* no meta data */ | 397 | /* no meta data */ |
400 | GNUNET_CONTAINER_meta_data_destroy (meta); | 398 | GNUNET_CONTAINER_meta_data_destroy(meta); |
401 | if (GNUNET_OK != | 399 | if (GNUNET_OK != |
402 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, | 400 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, |
403 | item->filename, | 401 | item->filename, |
404 | slen)) | 402 | slen)) |
405 | return GNUNET_SYSERR; | 403 | return GNUNET_SYSERR; |
406 | return GNUNET_OK; | 404 | return GNUNET_OK; |
407 | } | 405 | } |
408 | else if (size > (UINT16_MAX - sizeof (struct GNUNET_MessageHeader) - slen)) | 406 | else if (size > (UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen)) |
409 | { | 407 | { |
410 | /* We can't transfer more than 64k bytes in one message. */ | 408 | /* We can't transfer more than 64k bytes in one message. */ |
411 | size = UINT16_MAX - sizeof (struct GNUNET_MessageHeader) - slen; | 409 | size = UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen; |
412 | } | 410 | } |
413 | { | 411 | { |
414 | char buf[size + slen]; | 412 | char buf[size + slen]; |
415 | char *dst = &buf[slen]; | 413 | char *dst = &buf[slen]; |
416 | 414 | ||
417 | GNUNET_memcpy (buf, item->filename, slen); | 415 | GNUNET_memcpy(buf, item->filename, slen); |
418 | size = GNUNET_CONTAINER_meta_data_serialize ( | 416 | size = GNUNET_CONTAINER_meta_data_serialize( |
419 | meta, | 417 | meta, |
420 | &dst, | 418 | &dst, |
421 | size, | 419 | size, |
422 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | 420 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); |
423 | if (size < 0) | 421 | if (size < 0) |
424 | { | 422 | { |
425 | GNUNET_break (0); | 423 | GNUNET_break(0); |
426 | size = 0; | 424 | size = 0; |
427 | } | 425 | } |
428 | GNUNET_CONTAINER_meta_data_destroy (meta); | 426 | GNUNET_CONTAINER_meta_data_destroy(meta); |
429 | if (GNUNET_OK != | 427 | if (GNUNET_OK != |
430 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, | 428 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, |
431 | buf, | 429 | buf, |
432 | slen + size)) | 430 | slen + size)) |
433 | return GNUNET_SYSERR; | 431 | return GNUNET_SYSERR; |
434 | } | 432 | } |
435 | return GNUNET_OK; | 433 | return GNUNET_OK; |
@@ -441,23 +439,23 @@ extract_files (struct ScanTreeNode *item) | |||
441 | * Install a signal handler to ignore SIGPIPE. | 439 | * Install a signal handler to ignore SIGPIPE. |
442 | */ | 440 | */ |
443 | static void | 441 | static void |
444 | ignore_sigpipe () | 442 | ignore_sigpipe() |
445 | { | 443 | { |
446 | struct sigaction oldsig; | 444 | struct sigaction oldsig; |
447 | struct sigaction sig; | 445 | struct sigaction sig; |
448 | 446 | ||
449 | memset (&sig, 0, sizeof (struct sigaction)); | 447 | memset(&sig, 0, sizeof(struct sigaction)); |
450 | sig.sa_handler = SIG_IGN; | 448 | sig.sa_handler = SIG_IGN; |
451 | sigemptyset (&sig.sa_mask); | 449 | sigemptyset(&sig.sa_mask); |
452 | #ifdef SA_INTERRUPT | 450 | #ifdef SA_INTERRUPT |
453 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ | 451 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ |
454 | #else | 452 | #else |
455 | sig.sa_flags = SA_RESTART; | 453 | sig.sa_flags = SA_RESTART; |
456 | #endif | 454 | #endif |
457 | if (0 != sigaction (SIGPIPE, &sig, &oldsig)) | 455 | if (0 != sigaction(SIGPIPE, &sig, &oldsig)) |
458 | fprintf (stderr, | 456 | fprintf(stderr, |
459 | "Failed to install SIGPIPE handler: %s\n", | 457 | "Failed to install SIGPIPE handler: %s\n", |
460 | strerror (errno)); | 458 | strerror(errno)); |
461 | } | 459 | } |
462 | 460 | ||
463 | 461 | ||
@@ -468,17 +466,17 @@ ignore_sigpipe () | |||
468 | * @param flags flags to use (O_RDONLY or O_WRONLY) | 466 | * @param flags flags to use (O_RDONLY or O_WRONLY) |
469 | */ | 467 | */ |
470 | static void | 468 | static void |
471 | make_dev_zero (int fd, int flags) | 469 | make_dev_zero(int fd, int flags) |
472 | { | 470 | { |
473 | int z; | 471 | int z; |
474 | 472 | ||
475 | GNUNET_assert (0 == close (fd)); | 473 | GNUNET_assert(0 == close(fd)); |
476 | z = open ("/dev/null", flags); | 474 | z = open("/dev/null", flags); |
477 | GNUNET_assert (-1 != z); | 475 | GNUNET_assert(-1 != z); |
478 | if (z == fd) | 476 | if (z == fd) |
479 | return; | 477 | return; |
480 | GNUNET_break (fd == dup2 (z, fd)); | 478 | GNUNET_break(fd == dup2(z, fd)); |
481 | GNUNET_assert (0 == close (z)); | 479 | GNUNET_assert(0 == close(z)); |
482 | } | 480 | } |
483 | 481 | ||
484 | #endif | 482 | #endif |
@@ -495,7 +493,7 @@ make_dev_zero (int fd, int flags) | |||
495 | * @return 0 on success | 493 | * @return 0 on success |
496 | */ | 494 | */ |
497 | int | 495 | int |
498 | main (int argc, char *const *argv) | 496 | main(int argc, char *const *argv) |
499 | { | 497 | { |
500 | const char *filename_expanded; | 498 | const char *filename_expanded; |
501 | const char *ex; | 499 | const char *ex; |
@@ -505,98 +503,98 @@ main (int argc, char *const *argv) | |||
505 | /* We're using stdout to communicate binary data back to the parent; use | 503 | /* We're using stdout to communicate binary data back to the parent; use |
506 | * binary mode. | 504 | * binary mode. |
507 | */ | 505 | */ |
508 | _setmode (1, _O_BINARY); | 506 | _setmode(1, _O_BINARY); |
509 | /* Get utf-8-encoded arguments */ | 507 | /* Get utf-8-encoded arguments */ |
510 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 508 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
511 | return 5; | 509 | return 5; |
512 | output_stream = 1; /* stdout */ | 510 | output_stream = 1; /* stdout */ |
513 | #else | 511 | #else |
514 | ignore_sigpipe (); | 512 | ignore_sigpipe(); |
515 | /* move stdout to some other FD for IPC, bind | 513 | /* move stdout to some other FD for IPC, bind |
516 | stdout/stderr to /dev/null */ | 514 | stdout/stderr to /dev/null */ |
517 | output_stream = dup (1); | 515 | output_stream = dup(1); |
518 | make_dev_zero (1, O_WRONLY); | 516 | make_dev_zero(1, O_WRONLY); |
519 | make_dev_zero (2, O_WRONLY); | 517 | make_dev_zero(2, O_WRONLY); |
520 | #endif | 518 | #endif |
521 | 519 | ||
522 | /* parse command line */ | 520 | /* parse command line */ |
523 | if ((3 != argc) && (2 != argc)) | 521 | if ((3 != argc) && (2 != argc)) |
524 | { | 522 | { |
525 | fprintf (stderr, | 523 | fprintf(stderr, |
526 | "%s", | 524 | "%s", |
527 | "gnunet-helper-fs-publish needs exactly one or two arguments\n"); | 525 | "gnunet-helper-fs-publish needs exactly one or two arguments\n"); |
528 | #if WINDOWS | 526 | #if WINDOWS |
529 | GNUNET_free ((void *) argv); | 527 | GNUNET_free((void *)argv); |
530 | #endif | 528 | #endif |
531 | return 1; | 529 | return 1; |
532 | } | 530 | } |
533 | filename_expanded = argv[1]; | 531 | filename_expanded = argv[1]; |
534 | ex = argv[2]; | 532 | ex = argv[2]; |
535 | if ((NULL == ex) || (0 != strcmp (ex, "-"))) | 533 | if ((NULL == ex) || (0 != strcmp(ex, "-"))) |
536 | { | 534 | { |
537 | #if HAVE_LIBEXTRACTOR | 535 | #if HAVE_LIBEXTRACTOR |
538 | plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); | 536 | plugins = EXTRACTOR_plugin_add_defaults(EXTRACTOR_OPTION_DEFAULT_POLICY); |
539 | if (NULL != ex) | 537 | if (NULL != ex) |
540 | plugins = EXTRACTOR_plugin_add_config (plugins, | 538 | plugins = EXTRACTOR_plugin_add_config(plugins, |
541 | ex, | 539 | ex, |
542 | EXTRACTOR_OPTION_DEFAULT_POLICY); | 540 | EXTRACTOR_OPTION_DEFAULT_POLICY); |
543 | #endif | 541 | #endif |
544 | } | 542 | } |
545 | 543 | ||
546 | /* scan tree to find out how much work there is to be done */ | 544 | /* scan tree to find out how much work there is to be done */ |
547 | if (GNUNET_OK != preprocess_file (filename_expanded, &root)) | 545 | if (GNUNET_OK != preprocess_file(filename_expanded, &root)) |
548 | { | 546 | { |
549 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); | 547 | (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); |
550 | #if HAVE_LIBEXTRACTOR | 548 | #if HAVE_LIBEXTRACTOR |
551 | EXTRACTOR_plugin_remove_all (plugins); | 549 | EXTRACTOR_plugin_remove_all(plugins); |
552 | #endif | 550 | #endif |
553 | #if WINDOWS | 551 | #if WINDOWS |
554 | GNUNET_free ((void *) argv); | 552 | GNUNET_free((void *)argv); |
555 | #endif | 553 | #endif |
556 | return 2; | 554 | return 2; |
557 | } | 555 | } |
558 | /* signal that we're done counting files, so that a percentage of | 556 | /* signal that we're done counting files, so that a percentage of |
559 | progress can now be calculated */ | 557 | progress can now be calculated */ |
560 | if (GNUNET_OK != | 558 | if (GNUNET_OK != |
561 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, | 559 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, |
562 | NULL, | 560 | NULL, |
563 | 0)) | 561 | 0)) |
564 | { | 562 | { |
565 | #if HAVE_LIBEXTRACTOR | 563 | #if HAVE_LIBEXTRACTOR |
566 | EXTRACTOR_plugin_remove_all (plugins); | 564 | EXTRACTOR_plugin_remove_all(plugins); |
567 | #endif | 565 | #endif |
568 | #if WINDOWS | 566 | #if WINDOWS |
569 | GNUNET_free ((void *) argv); | 567 | GNUNET_free((void *)argv); |
570 | #endif | 568 | #endif |
571 | return 3; | 569 | return 3; |
572 | } | 570 | } |
573 | if (NULL != root) | 571 | if (NULL != root) |
574 | { | ||
575 | if (GNUNET_OK != extract_files (root)) | ||
576 | { | 572 | { |
577 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, | 573 | if (GNUNET_OK != extract_files(root)) |
578 | NULL, | 574 | { |
579 | 0); | 575 | (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, |
580 | free_tree (root); | 576 | NULL, |
577 | 0); | ||
578 | free_tree(root); | ||
581 | #if HAVE_LIBEXTRACTOR | 579 | #if HAVE_LIBEXTRACTOR |
582 | EXTRACTOR_plugin_remove_all (plugins); | 580 | EXTRACTOR_plugin_remove_all(plugins); |
583 | #endif | 581 | #endif |
584 | #if WINDOWS | 582 | #if WINDOWS |
585 | GNUNET_free ((void *) argv); | 583 | GNUNET_free((void *)argv); |
586 | #endif | 584 | #endif |
587 | return 4; | 585 | return 4; |
586 | } | ||
587 | free_tree(root); | ||
588 | } | 588 | } |
589 | free_tree (root); | ||
590 | } | ||
591 | /* enable "clean" shutdown by telling parent that we are done */ | 589 | /* enable "clean" shutdown by telling parent that we are done */ |
592 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, | 590 | (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, |
593 | NULL, | 591 | NULL, |
594 | 0); | 592 | 0); |
595 | #if HAVE_LIBEXTRACTOR | 593 | #if HAVE_LIBEXTRACTOR |
596 | EXTRACTOR_plugin_remove_all (plugins); | 594 | EXTRACTOR_plugin_remove_all(plugins); |
597 | #endif | 595 | #endif |
598 | #if WINDOWS | 596 | #if WINDOWS |
599 | GNUNET_free ((void *) argv); | 597 | GNUNET_free((void *)argv); |
600 | #endif | 598 | #endif |
601 | return 0; | 599 | return 0; |
602 | } | 600 | } |
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index 84cbf0aac..24baa4d38 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/gnunet-publish.c | 21 | * @file fs/gnunet-publish.c |
22 | * @brief publishing files on GNUnet | 22 | * @brief publishing files on GNUnet |
@@ -67,7 +67,7 @@ static struct GNUNET_FS_Uri *topKeywords; | |||
67 | /** | 67 | /** |
68 | * Options we set for published blocks. | 68 | * Options we set for published blocks. |
69 | */ | 69 | */ |
70 | static struct GNUNET_FS_BlockOptions bo = {{0LL}, 1, 365, 1}; | 70 | static struct GNUNET_FS_BlockOptions bo = { { 0LL }, 1, 365, 1 }; |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * Value of URI provided on command-line (when not publishing | 73 | * Value of URI provided on command-line (when not publishing |
@@ -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,94 +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 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
213 | if (verbose) | ||
214 | { | 209 | { |
215 | s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta, | 210 | case GNUNET_FS_STATUS_PUBLISH_START: |
216 | GNUNET_YES); | 211 | break; |
217 | fprintf (stdout, | 212 | |
218 | _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"), | 213 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
219 | info->value.publish.filename, | 214 | if (verbose) |
220 | (unsigned long long) info->value.publish.completed, | 215 | { |
221 | (unsigned long long) info->value.publish.size, | 216 | s = GNUNET_STRINGS_relative_time_to_string(info->value.publish.eta, |
222 | s); | 217 | GNUNET_YES); |
223 | } | 218 | fprintf(stdout, |
224 | break; | 219 | _("Publishing `%s' at %llu/%llu (%s remaining)\n"), |
225 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 220 | info->value.publish.filename, |
226 | if (verbose) | 221 | (unsigned long long)info->value.publish.completed, |
227 | { | 222 | (unsigned long long)info->value.publish.size, |
228 | s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.specifics | 223 | s); |
229 | .progress_directory.eta, | 224 | } |
230 | GNUNET_YES); | 225 | break; |
231 | fprintf (stdout, | 226 | |
232 | _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"), | 227 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
233 | info->value.publish.filename, | 228 | if (verbose) |
234 | (unsigned long long) | 229 | { |
235 | info->value.publish.specifics.progress_directory.completed, | 230 | s = GNUNET_STRINGS_relative_time_to_string(info->value.publish.specifics |
236 | (unsigned long long) | 231 | .progress_directory.eta, |
237 | info->value.publish.specifics.progress_directory.total, | 232 | GNUNET_YES); |
238 | s); | 233 | fprintf(stdout, |
239 | } | 234 | _("Publishing `%s' at %llu/%llu (%s remaining)\n"), |
240 | break; | 235 | info->value.publish.filename, |
241 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 236 | (unsigned long long) |
242 | fprintf (stderr, | 237 | info->value.publish.specifics.progress_directory.completed, |
243 | _ ("Error publishing: %s.\n"), | 238 | (unsigned long long) |
244 | info->value.publish.specifics.error.message); | 239 | info->value.publish.specifics.progress_directory.total, |
245 | ret = 1; | 240 | s); |
246 | GNUNET_SCHEDULER_shutdown (); | 241 | } |
247 | break; | 242 | break; |
248 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 243 | |
249 | fprintf (stdout, | 244 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
250 | _ ("Publishing `%s' done.\n"), | 245 | fprintf(stderr, |
251 | info->value.publish.filename); | 246 | _("Error publishing: %s.\n"), |
252 | suri = | 247 | info->value.publish.specifics.error.message); |
253 | GNUNET_FS_uri_to_string (info->value.publish.specifics.completed.chk_uri); | 248 | ret = 1; |
254 | fprintf (stdout, _ ("URI is `%s'.\n"), suri); | 249 | GNUNET_SCHEDULER_shutdown(); |
255 | GNUNET_free (suri); | 250 | break; |
256 | if (NULL != info->value.publish.specifics.completed.sks_uri) | 251 | |
257 | { | 252 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
258 | suri = GNUNET_FS_uri_to_string ( | 253 | fprintf(stdout, |
259 | info->value.publish.specifics.completed.sks_uri); | 254 | _("Publishing `%s' done.\n"), |
260 | fprintf (stdout, _ ("Namespace URI is `%s'.\n"), suri); | 255 | info->value.publish.filename); |
261 | GNUNET_free (suri); | 256 | suri = |
262 | } | 257 | GNUNET_FS_uri_to_string(info->value.publish.specifics.completed.chk_uri); |
263 | if (NULL == info->value.publish.pctx) | 258 | fprintf(stdout, _("URI is `%s'.\n"), suri); |
264 | { | 259 | GNUNET_free(suri); |
265 | ret = 0; | 260 | if (NULL != info->value.publish.specifics.completed.sks_uri) |
266 | GNUNET_SCHEDULER_shutdown (); | 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; | ||
267 | } | 301 | } |
268 | break; | ||
269 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
270 | GNUNET_break (NULL == pc); | ||
271 | return NULL; | ||
272 | case GNUNET_FS_STATUS_UNINDEX_START: | ||
273 | fprintf (stderr, "%s", _ ("Starting cleanup after abort\n")); | ||
274 | return NULL; | ||
275 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | ||
276 | return NULL; | ||
277 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | ||
278 | fprintf (stderr, "%s", _ ("Cleanup after abort completed.\n")); | ||
279 | GNUNET_FS_unindex_stop (info->value.unindex.uc); | ||
280 | return NULL; | ||
281 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | ||
282 | fprintf (stderr, "%s", _ ("Cleanup after abort failed.\n")); | ||
283 | GNUNET_FS_unindex_stop (info->value.unindex.uc); | ||
284 | return NULL; | ||
285 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | ||
286 | return NULL; | ||
287 | default: | ||
288 | fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); | ||
289 | return NULL; | ||
290 | } | ||
291 | return ""; /* non-null */ | 302 | return ""; /* non-null */ |
292 | } | 303 | } |
293 | 304 | ||
@@ -306,13 +317,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
306 | * @return always 0 | 317 | * @return always 0 |
307 | */ | 318 | */ |
308 | static int | 319 | static int |
309 | meta_printer (void *cls, | 320 | meta_printer(void *cls, |
310 | const char *plugin_name, | 321 | const char *plugin_name, |
311 | enum EXTRACTOR_MetaType type, | 322 | enum EXTRACTOR_MetaType type, |
312 | enum EXTRACTOR_MetaFormat format, | 323 | enum EXTRACTOR_MetaFormat format, |
313 | const char *data_mime_type, | 324 | const char *data_mime_type, |
314 | const char *data, | 325 | const char *data, |
315 | size_t data_size) | 326 | size_t data_size) |
316 | { | 327 | { |
317 | if ((EXTRACTOR_METAFORMAT_UTF8 != format) && | 328 | if ((EXTRACTOR_METAFORMAT_UTF8 != format) && |
318 | (EXTRACTOR_METAFORMAT_C_STRING != format)) | 329 | (EXTRACTOR_METAFORMAT_C_STRING != format)) |
@@ -320,9 +331,9 @@ meta_printer (void *cls, | |||
320 | if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type) | 331 | if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type) |
321 | return 0; | 332 | return 0; |
322 | #if HAVE_LIBEXTRACTOR | 333 | #if HAVE_LIBEXTRACTOR |
323 | 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); |
324 | #else | 335 | #else |
325 | fprintf (stdout, "\t%d - %s\n", type, data); | 336 | fprintf(stdout, "\t%d - %s\n", type, data); |
326 | #endif | 337 | #endif |
327 | return 0; | 338 | return 0; |
328 | } | 339 | } |
@@ -337,9 +348,9 @@ meta_printer (void *cls, | |||
337 | * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort | 348 | * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort |
338 | */ | 349 | */ |
339 | static int | 350 | static int |
340 | keyword_printer (void *cls, const char *keyword, int is_mandatory) | 351 | keyword_printer(void *cls, const char *keyword, int is_mandatory) |
341 | { | 352 | { |
342 | fprintf (stdout, "\t%s\n", keyword); | 353 | fprintf(stdout, "\t%s\n", keyword); |
343 | return GNUNET_OK; | 354 | return GNUNET_OK; |
344 | } | 355 | } |
345 | 356 | ||
@@ -362,14 +373,14 @@ keyword_printer (void *cls, const char *keyword, int is_mandatory) | |||
362 | * to abort the iteration | 373 | * to abort the iteration |
363 | */ | 374 | */ |
364 | static int | 375 | static int |
365 | publish_inspector (void *cls, | 376 | publish_inspector(void *cls, |
366 | struct GNUNET_FS_FileInformation *fi, | 377 | struct GNUNET_FS_FileInformation *fi, |
367 | uint64_t length, | 378 | uint64_t length, |
368 | struct GNUNET_CONTAINER_MetaData *m, | 379 | struct GNUNET_CONTAINER_MetaData *m, |
369 | struct GNUNET_FS_Uri **uri, | 380 | struct GNUNET_FS_Uri **uri, |
370 | struct GNUNET_FS_BlockOptions *bo, | 381 | struct GNUNET_FS_BlockOptions *bo, |
371 | int *do_index, | 382 | int *do_index, |
372 | void **client_info) | 383 | void **client_info) |
373 | { | 384 | { |
374 | char *fn; | 385 | char *fn; |
375 | char *fs; | 386 | char *fs; |
@@ -378,50 +389,50 @@ publish_inspector (void *cls, | |||
378 | if (cls == fi) | 389 | if (cls == fi) |
379 | return GNUNET_OK; | 390 | return GNUNET_OK; |
380 | if ((disable_extractor) && (NULL != *uri)) | 391 | if ((disable_extractor) && (NULL != *uri)) |
381 | { | ||
382 | GNUNET_FS_uri_destroy (*uri); | ||
383 | *uri = NULL; | ||
384 | } | ||
385 | if (NULL != topKeywords) | ||
386 | { | ||
387 | if (NULL != *uri) | ||
388 | { | 392 | { |
389 | new_uri = GNUNET_FS_uri_ksk_merge (topKeywords, *uri); | 393 | GNUNET_FS_uri_destroy(*uri); |
390 | GNUNET_FS_uri_destroy (*uri); | 394 | *uri = NULL; |
391 | *uri = new_uri; | ||
392 | GNUNET_FS_uri_destroy (topKeywords); | ||
393 | } | 395 | } |
394 | else | 396 | if (NULL != topKeywords) |
395 | { | 397 | { |
396 | *uri = topKeywords; | 398 | if (NULL != *uri) |
399 | { | ||
400 | new_uri = GNUNET_FS_uri_ksk_merge(topKeywords, *uri); | ||
401 | GNUNET_FS_uri_destroy(*uri); | ||
402 | *uri = new_uri; | ||
403 | GNUNET_FS_uri_destroy(topKeywords); | ||
404 | } | ||
405 | else | ||
406 | { | ||
407 | *uri = topKeywords; | ||
408 | } | ||
409 | topKeywords = NULL; | ||
397 | } | 410 | } |
398 | topKeywords = NULL; | ||
399 | } | ||
400 | if (NULL != meta) | 411 | if (NULL != meta) |
401 | { | 412 | { |
402 | GNUNET_CONTAINER_meta_data_merge (m, meta); | 413 | GNUNET_CONTAINER_meta_data_merge(m, meta); |
403 | GNUNET_CONTAINER_meta_data_destroy (meta); | 414 | GNUNET_CONTAINER_meta_data_destroy(meta); |
404 | meta = NULL; | 415 | meta = NULL; |
405 | } | 416 | } |
406 | if (enable_creation_time) | 417 | if (enable_creation_time) |
407 | GNUNET_CONTAINER_meta_data_add_publication_date (m); | 418 | GNUNET_CONTAINER_meta_data_add_publication_date(m); |
408 | if (extract_only) | 419 | if (extract_only) |
409 | { | 420 | { |
410 | fn = GNUNET_CONTAINER_meta_data_get_by_type ( | 421 | fn = GNUNET_CONTAINER_meta_data_get_by_type( |
411 | m, | 422 | m, |
412 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 423 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); |
413 | fs = GNUNET_STRINGS_byte_size_fancy (length); | 424 | fs = GNUNET_STRINGS_byte_size_fancy(length); |
414 | fprintf (stdout, _ ("Meta data for file `%s' (%s)\n"), fn, fs); | 425 | fprintf(stdout, _("Meta data for file `%s' (%s)\n"), fn, fs); |
415 | GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL); | 426 | GNUNET_CONTAINER_meta_data_iterate(m, &meta_printer, NULL); |
416 | fprintf (stdout, _ ("Keywords for file `%s' (%s)\n"), fn, fs); | 427 | fprintf(stdout, _("Keywords for file `%s' (%s)\n"), fn, fs); |
417 | GNUNET_free (fn); | 428 | GNUNET_free(fn); |
418 | GNUNET_free (fs); | 429 | GNUNET_free(fs); |
419 | if (NULL != *uri) | 430 | if (NULL != *uri) |
420 | GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL); | 431 | GNUNET_FS_uri_ksk_get_keywords(*uri, &keyword_printer, NULL); |
421 | fprintf (stdout, "%s", "\n"); | 432 | fprintf(stdout, "%s", "\n"); |
422 | } | 433 | } |
423 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) | 434 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(m)) |
424 | GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi); | 435 | GNUNET_FS_file_information_inspect(fi, &publish_inspector, fi); |
425 | return GNUNET_OK; | 436 | return GNUNET_OK; |
426 | } | 437 | } |
427 | 438 | ||
@@ -436,16 +447,16 @@ publish_inspector (void *cls, | |||
436 | * @param emsg error message, NULL on success | 447 | * @param emsg error message, NULL on success |
437 | */ | 448 | */ |
438 | static void | 449 | static void |
439 | uri_sks_continuation (void *cls, | 450 | uri_sks_continuation(void *cls, |
440 | const struct GNUNET_FS_Uri *sks_uri, | 451 | const struct GNUNET_FS_Uri *sks_uri, |
441 | const char *emsg) | 452 | const char *emsg) |
442 | { | 453 | { |
443 | if (NULL != emsg) | 454 | if (NULL != emsg) |
444 | { | 455 | { |
445 | fprintf (stderr, "%s\n", emsg); | 456 | fprintf(stderr, "%s\n", emsg); |
446 | ret = 1; | 457 | ret = 1; |
447 | } | 458 | } |
448 | GNUNET_SCHEDULER_shutdown (); | 459 | GNUNET_SCHEDULER_shutdown(); |
449 | } | 460 | } |
450 | 461 | ||
451 | 462 | ||
@@ -459,33 +470,33 @@ uri_sks_continuation (void *cls, | |||
459 | * @param emsg error message, NULL on success | 470 | * @param emsg error message, NULL on success |
460 | */ | 471 | */ |
461 | static void | 472 | static void |
462 | uri_ksk_continuation (void *cls, | 473 | uri_ksk_continuation(void *cls, |
463 | const struct GNUNET_FS_Uri *ksk_uri, | 474 | const struct GNUNET_FS_Uri *ksk_uri, |
464 | const char *emsg) | 475 | const char *emsg) |
465 | { | 476 | { |
466 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; | 477 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; |
467 | 478 | ||
468 | if (NULL != emsg) | 479 | if (NULL != emsg) |
469 | { | 480 | { |
470 | fprintf (stderr, "%s\n", emsg); | 481 | fprintf(stderr, "%s\n", emsg); |
471 | ret = 1; | 482 | ret = 1; |
472 | } | 483 | } |
473 | if (NULL == namespace) | 484 | if (NULL == namespace) |
474 | { | 485 | { |
475 | GNUNET_SCHEDULER_shutdown (); | 486 | GNUNET_SCHEDULER_shutdown(); |
476 | return; | 487 | return; |
477 | } | 488 | } |
478 | priv = GNUNET_IDENTITY_ego_get_private_key (namespace); | 489 | priv = GNUNET_IDENTITY_ego_get_private_key(namespace); |
479 | GNUNET_FS_publish_sks (ctx, | 490 | GNUNET_FS_publish_sks(ctx, |
480 | priv, | 491 | priv, |
481 | this_id, | 492 | this_id, |
482 | next_id, | 493 | next_id, |
483 | meta, | 494 | meta, |
484 | uri, | 495 | uri, |
485 | &bo, | 496 | &bo, |
486 | GNUNET_FS_PUBLISH_OPTION_NONE, | 497 | GNUNET_FS_PUBLISH_OPTION_NONE, |
487 | &uri_sks_continuation, | 498 | &uri_sks_continuation, |
488 | NULL); | 499 | NULL); |
489 | } | 500 | } |
490 | 501 | ||
491 | 502 | ||
@@ -497,52 +508,52 @@ uri_ksk_continuation (void *cls, | |||
497 | * @return handle with the information for the publishing operation | 508 | * @return handle with the information for the publishing operation |
498 | */ | 509 | */ |
499 | static struct GNUNET_FS_FileInformation * | 510 | static struct GNUNET_FS_FileInformation * |
500 | get_file_information (struct GNUNET_FS_ShareTreeItem *item) | 511 | get_file_information(struct GNUNET_FS_ShareTreeItem *item) |
501 | { | 512 | { |
502 | struct GNUNET_FS_FileInformation *fi; | 513 | struct GNUNET_FS_FileInformation *fi; |
503 | struct GNUNET_FS_FileInformation *fic; | 514 | struct GNUNET_FS_FileInformation *fic; |
504 | struct GNUNET_FS_ShareTreeItem *child; | 515 | struct GNUNET_FS_ShareTreeItem *child; |
505 | 516 | ||
506 | if (GNUNET_YES == item->is_directory) | 517 | if (GNUNET_YES == item->is_directory) |
507 | { | ||
508 | if (NULL == item->meta) | ||
509 | item->meta = GNUNET_CONTAINER_meta_data_create (); | ||
510 | GNUNET_CONTAINER_meta_data_delete (item->meta, | ||
511 | EXTRACTOR_METATYPE_MIMETYPE, | ||
512 | NULL, | ||
513 | 0); | ||
514 | GNUNET_FS_meta_data_make_directory (item->meta); | ||
515 | if (NULL == item->ksk_uri) | ||
516 | { | 518 | { |
517 | const char *mime = GNUNET_FS_DIRECTORY_MIME; | 519 | if (NULL == item->meta) |
518 | item->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &mime); | 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) | ||
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 | } | ||
519 | } | 546 | } |
520 | else | 547 | else |
521 | GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri, | ||
522 | GNUNET_FS_DIRECTORY_MIME, | ||
523 | GNUNET_NO); | ||
524 | fi = GNUNET_FS_file_information_create_empty_directory (ctx, | ||
525 | NULL, | ||
526 | item->ksk_uri, | ||
527 | item->meta, | ||
528 | &bo, | ||
529 | item->filename); | ||
530 | for (child = item->children_head; child; child = child->next) | ||
531 | { | 548 | { |
532 | fic = get_file_information (child); | 549 | fi = GNUNET_FS_file_information_create_from_file(ctx, |
533 | GNUNET_break (GNUNET_OK == GNUNET_FS_file_information_add (fi, fic)); | 550 | NULL, |
551 | item->filename, | ||
552 | item->ksk_uri, | ||
553 | item->meta, | ||
554 | !do_insert, | ||
555 | &bo); | ||
534 | } | 556 | } |
535 | } | ||
536 | else | ||
537 | { | ||
538 | fi = GNUNET_FS_file_information_create_from_file (ctx, | ||
539 | NULL, | ||
540 | item->filename, | ||
541 | item->ksk_uri, | ||
542 | item->meta, | ||
543 | ! do_insert, | ||
544 | &bo); | ||
545 | } | ||
546 | return fi; | 557 | return fi; |
547 | } | 558 | } |
548 | 559 | ||
@@ -554,46 +565,46 @@ get_file_information (struct GNUNET_FS_ShareTreeItem *item) | |||
554 | * @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 |
555 | */ | 566 | */ |
556 | static void | 567 | static void |
557 | directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) | 568 | directory_trim_complete(struct GNUNET_FS_ShareTreeItem *directory_scan_result) |
558 | { | 569 | { |
559 | struct GNUNET_FS_FileInformation *fi; | 570 | struct GNUNET_FS_FileInformation *fi; |
560 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; | 571 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; |
561 | 572 | ||
562 | fi = get_file_information (directory_scan_result); | 573 | fi = get_file_information(directory_scan_result); |
563 | GNUNET_FS_share_tree_free (directory_scan_result); | 574 | GNUNET_FS_share_tree_free(directory_scan_result); |
564 | if (NULL == fi) | 575 | if (NULL == fi) |
565 | { | 576 | { |
566 | fprintf (stderr, "%s", _ ("Could not publish\n")); | 577 | fprintf(stderr, "%s", _("Could not publish\n")); |
567 | ret = 1; | 578 | ret = 1; |
568 | GNUNET_SCHEDULER_shutdown (); | 579 | GNUNET_SCHEDULER_shutdown(); |
569 | return; | 580 | return; |
570 | } | 581 | } |
571 | GNUNET_FS_file_information_inspect (fi, &publish_inspector, NULL); | 582 | GNUNET_FS_file_information_inspect(fi, &publish_inspector, NULL); |
572 | if (extract_only) | 583 | if (extract_only) |
573 | { | 584 | { |
574 | GNUNET_FS_file_information_destroy (fi, NULL, NULL); | 585 | GNUNET_FS_file_information_destroy(fi, NULL, NULL); |
575 | GNUNET_SCHEDULER_shutdown (); | 586 | GNUNET_SCHEDULER_shutdown(); |
576 | return; | 587 | return; |
577 | } | 588 | } |
578 | if (NULL == namespace) | 589 | if (NULL == namespace) |
579 | priv = NULL; | 590 | priv = NULL; |
580 | else | 591 | else |
581 | priv = GNUNET_IDENTITY_ego_get_private_key (namespace); | 592 | priv = GNUNET_IDENTITY_ego_get_private_key(namespace); |
582 | pc = GNUNET_FS_publish_start (ctx, | 593 | pc = GNUNET_FS_publish_start(ctx, |
583 | fi, | 594 | fi, |
584 | priv, | 595 | priv, |
585 | this_id, | 596 | this_id, |
586 | next_id, | 597 | next_id, |
587 | (do_simulate) | 598 | (do_simulate) |
588 | ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY | 599 | ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY |
589 | : GNUNET_FS_PUBLISH_OPTION_NONE); | 600 | : GNUNET_FS_PUBLISH_OPTION_NONE); |
590 | if (NULL == pc) | 601 | if (NULL == pc) |
591 | { | 602 | { |
592 | fprintf (stderr, "%s", _ ("Could not start publishing.\n")); | 603 | fprintf(stderr, "%s", _("Could not start publishing.\n")); |
593 | ret = 1; | 604 | ret = 1; |
594 | GNUNET_SCHEDULER_shutdown (); | 605 | GNUNET_SCHEDULER_shutdown(); |
595 | return; | 606 | return; |
596 | } | 607 | } |
597 | } | 608 | } |
598 | 609 | ||
599 | 610 | ||
@@ -609,57 +620,63 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) | |||
609 | * @param reason kind of progress we are making | 620 | * @param reason kind of progress we are making |
610 | */ | 621 | */ |
611 | static void | 622 | static void |
612 | directory_scan_cb (void *cls, | 623 | directory_scan_cb(void *cls, |
613 | const char *filename, | 624 | const char *filename, |
614 | int is_directory, | 625 | int is_directory, |
615 | enum GNUNET_FS_DirScannerProgressUpdateReason reason) | 626 | enum GNUNET_FS_DirScannerProgressUpdateReason reason) |
616 | { | 627 | { |
617 | struct GNUNET_FS_ShareTreeItem *directory_scan_result; | 628 | struct GNUNET_FS_ShareTreeItem *directory_scan_result; |
618 | 629 | ||
619 | switch (reason) | 630 | switch (reason) |
620 | { | ||
621 | case GNUNET_FS_DIRSCANNER_FILE_START: | ||
622 | if (verbose > 1) | ||
623 | { | 631 | { |
624 | if (is_directory == GNUNET_YES) | 632 | case GNUNET_FS_DIRSCANNER_FILE_START: |
625 | fprintf (stdout, _ ("Scanning directory `%s'.\n"), filename); | 633 | if (verbose > 1) |
626 | else | 634 | { |
627 | fprintf (stdout, _ ("Scanning file `%s'.\n"), filename); | 635 | if (is_directory == GNUNET_YES) |
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; | ||
628 | } | 678 | } |
629 | break; | 679 | fflush(stdout); |
630 | case GNUNET_FS_DIRSCANNER_FILE_IGNORED: | ||
631 | fprintf (stderr, | ||
632 | _ ("There was trouble processing file `%s', skipping it.\n"), | ||
633 | filename); | ||
634 | break; | ||
635 | case GNUNET_FS_DIRSCANNER_ALL_COUNTED: | ||
636 | if (verbose) | ||
637 | fprintf (stdout, "%s", _ ("Preprocessing complete.\n")); | ||
638 | break; | ||
639 | case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED: | ||
640 | if (verbose > 2) | ||
641 | fprintf (stdout, | ||
642 | _ ("Extracting meta data from file `%s' complete.\n"), | ||
643 | filename); | ||
644 | break; | ||
645 | case GNUNET_FS_DIRSCANNER_FINISHED: | ||
646 | if (verbose > 1) | ||
647 | fprintf (stdout, "%s", _ ("Meta data extraction has finished.\n")); | ||
648 | directory_scan_result = GNUNET_FS_directory_scan_get_result (ds); | ||
649 | ds = NULL; | ||
650 | GNUNET_FS_share_tree_trim (directory_scan_result); | ||
651 | directory_trim_complete (directory_scan_result); | ||
652 | break; | ||
653 | case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: | ||
654 | fprintf (stdout, "%s", _ ("Error scanning directory.\n")); | ||
655 | ret = 1; | ||
656 | GNUNET_SCHEDULER_shutdown (); | ||
657 | break; | ||
658 | default: | ||
659 | GNUNET_assert (0); | ||
660 | break; | ||
661 | } | ||
662 | fflush (stdout); | ||
663 | } | 680 | } |
664 | 681 | ||
665 | 682 | ||
@@ -670,67 +687,67 @@ directory_scan_cb (void *cls, | |||
670 | * @param args0 filename to publish | 687 | * @param args0 filename to publish |
671 | */ | 688 | */ |
672 | static void | 689 | static void |
673 | identity_continuation (const char *args0) | 690 | identity_continuation(const char *args0) |
674 | { | 691 | { |
675 | char *ex; | 692 | char *ex; |
676 | char *emsg; | 693 | char *emsg; |
677 | 694 | ||
678 | if ((NULL != pseudonym) && (NULL == namespace)) | 695 | if ((NULL != pseudonym) && (NULL == namespace)) |
679 | { | ||
680 | fprintf (stderr, _ ("Selected pseudonym `%s' unknown\n"), pseudonym); | ||
681 | ret = 1; | ||
682 | GNUNET_SCHEDULER_shutdown (); | ||
683 | return; | ||
684 | } | ||
685 | if (NULL != uri_string) | ||
686 | { | ||
687 | emsg = NULL; | ||
688 | if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg))) | ||
689 | { | 696 | { |
690 | fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg); | 697 | fprintf(stderr, _("Selected pseudonym `%s' unknown\n"), pseudonym); |
691 | GNUNET_free (emsg); | ||
692 | ret = 1; | 698 | ret = 1; |
693 | GNUNET_SCHEDULER_shutdown (); | 699 | GNUNET_SCHEDULER_shutdown(); |
700 | return; | ||
701 | } | ||
702 | if (NULL != uri_string) | ||
703 | { | ||
704 | emsg = NULL; | ||
705 | if (NULL == (uri = GNUNET_FS_uri_parse(uri_string, &emsg))) | ||
706 | { | ||
707 | fprintf(stderr, _("Failed to parse URI: %s\n"), emsg); | ||
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); | ||
694 | return; | 721 | return; |
695 | } | 722 | } |
696 | GNUNET_FS_publish_ksk (ctx, | ||
697 | topKeywords, | ||
698 | meta, | ||
699 | uri, | ||
700 | &bo, | ||
701 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
702 | &uri_ksk_continuation, | ||
703 | NULL); | ||
704 | return; | ||
705 | } | ||
706 | if (GNUNET_OK != | 723 | if (GNUNET_OK != |
707 | GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex)) | 724 | GNUNET_CONFIGURATION_get_value_string(cfg, "FS", "EXTRACTORS", &ex)) |
708 | ex = NULL; | 725 | ex = NULL; |
709 | if (0 != access (args0, R_OK)) | 726 | if (0 != access(args0, R_OK)) |
710 | { | 727 | { |
711 | fprintf (stderr, | 728 | fprintf(stderr, |
712 | _ ("Failed to access `%s': %s\n"), | 729 | _("Failed to access `%s': %s\n"), |
713 | args0, | 730 | args0, |
714 | strerror (errno)); | 731 | strerror(errno)); |
715 | GNUNET_free_non_null (ex); | 732 | GNUNET_free_non_null(ex); |
716 | return; | 733 | return; |
717 | } | 734 | } |
718 | ds = GNUNET_FS_directory_scan_start (args0, | 735 | ds = GNUNET_FS_directory_scan_start(args0, |
719 | disable_extractor, | 736 | disable_extractor, |
720 | ex, | 737 | ex, |
721 | &directory_scan_cb, | 738 | &directory_scan_cb, |
722 | NULL); | 739 | NULL); |
723 | if (NULL == ds) | 740 | if (NULL == ds) |
724 | { | 741 | { |
725 | fprintf ( | 742 | fprintf( |
726 | stderr, | 743 | stderr, |
727 | "%s", | 744 | "%s", |
728 | _ ( | 745 | _( |
729 | "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")); |
730 | GNUNET_free_non_null (ex); | 747 | GNUNET_free_non_null(ex); |
731 | return; | 748 | return; |
732 | } | 749 | } |
733 | GNUNET_free_non_null (ex); | 750 | GNUNET_free_non_null(ex); |
734 | } | 751 | } |
735 | 752 | ||
736 | 753 | ||
@@ -746,22 +763,22 @@ identity_continuation (const char *args0) | |||
746 | * must thus no longer be used | 763 | * must thus no longer be used |
747 | */ | 764 | */ |
748 | static void | 765 | static void |
749 | identity_cb (void *cls, | 766 | identity_cb(void *cls, |
750 | struct GNUNET_IDENTITY_Ego *ego, | 767 | struct GNUNET_IDENTITY_Ego *ego, |
751 | void **ctx, | 768 | void **ctx, |
752 | const char *name) | 769 | const char *name) |
753 | { | 770 | { |
754 | const char *args0 = cls; | 771 | const char *args0 = cls; |
755 | 772 | ||
756 | if (NULL == ego) | 773 | if (NULL == ego) |
757 | { | 774 | { |
758 | identity_continuation (args0); | 775 | identity_continuation(args0); |
759 | return; | 776 | return; |
760 | } | 777 | } |
761 | if (NULL == name) | 778 | if (NULL == name) |
762 | return; | 779 | return; |
763 | if (0 == strcmp (name, pseudonym)) | 780 | if (0 == strcmp(name, pseudonym)) |
764 | namespace = ego; | 781 | namespace = ego; |
765 | } | 782 | } |
766 | 783 | ||
767 | 784 | ||
@@ -774,82 +791,82 @@ identity_cb (void *cls, | |||
774 | * @param c configuration | 791 | * @param c configuration |
775 | */ | 792 | */ |
776 | static void | 793 | static void |
777 | run (void *cls, | 794 | run(void *cls, |
778 | char *const *args, | 795 | char *const *args, |
779 | const char *cfgfile, | 796 | const char *cfgfile, |
780 | const struct GNUNET_CONFIGURATION_Handle *c) | 797 | const struct GNUNET_CONFIGURATION_Handle *c) |
781 | { | 798 | { |
782 | /* check arguments */ | 799 | /* check arguments */ |
783 | if ((NULL != uri_string) && (extract_only)) | 800 | if ((NULL != uri_string) && (extract_only)) |
784 | { | ||
785 | printf (_ ("Cannot extract metadata from a URI!\n")); | ||
786 | ret = -1; | ||
787 | return; | ||
788 | } | ||
789 | if (((NULL == uri_string) || (extract_only)) && | ||
790 | ((NULL == args[0]) || (NULL != args[1]))) | ||
791 | { | ||
792 | printf (_ ("You must specify one and only one filename for insertion.\n")); | ||
793 | ret = -1; | ||
794 | return; | ||
795 | } | ||
796 | if ((NULL != uri_string) && (NULL != args[0])) | ||
797 | { | ||
798 | printf (_ ("You must NOT specify an URI and a filename.\n")); | ||
799 | ret = -1; | ||
800 | return; | ||
801 | } | ||
802 | if (NULL != pseudonym) | ||
803 | { | ||
804 | if (NULL == this_id) | ||
805 | { | 801 | { |
806 | fprintf (stderr, | 802 | printf(_("Cannot extract metadata from a URI!\n")); |
807 | _ ("Option `%s' is required when using option `%s'.\n"), | ||
808 | "-t", | ||
809 | "-P"); | ||
810 | ret = -1; | 803 | ret = -1; |
811 | return; | 804 | return; |
812 | } | 805 | } |
813 | } | 806 | if (((NULL == uri_string) || (extract_only)) && |
814 | else | 807 | ((NULL == args[0]) || (NULL != args[1]))) |
815 | { /* ordinary insertion checks */ | ||
816 | if (NULL != next_id) | ||
817 | { | 808 | { |
818 | fprintf (stderr, | 809 | printf(_("You must specify one and only one filename for insertion.\n")); |
819 | _ ("Option `%s' makes no sense without option `%s'.\n"), | ||
820 | "-N", | ||
821 | "-P"); | ||
822 | ret = -1; | 810 | ret = -1; |
823 | return; | 811 | return; |
824 | } | 812 | } |
825 | if (NULL != this_id) | 813 | if ((NULL != uri_string) && (NULL != args[0])) |
826 | { | 814 | { |
827 | fprintf (stderr, | 815 | printf(_("You must NOT specify an URI and a filename.\n")); |
828 | _ ("Option `%s' makes no sense without option `%s'.\n"), | ||
829 | "-t", | ||
830 | "-P"); | ||
831 | ret = -1; | 816 | ret = -1; |
832 | return; | 817 | return; |
833 | } | 818 | } |
834 | } | 819 | if (NULL != pseudonym) |
820 | { | ||
821 | if (NULL == this_id) | ||
822 | { | ||
823 | fprintf(stderr, | ||
824 | _("Option `%s' is required when using option `%s'.\n"), | ||
825 | "-t", | ||
826 | "-P"); | ||
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 | } | ||
835 | cfg = c; | 852 | cfg = c; |
836 | ctx = GNUNET_FS_start (cfg, | 853 | ctx = GNUNET_FS_start(cfg, |
837 | "gnunet-publish", | 854 | "gnunet-publish", |
838 | &progress_cb, | 855 | &progress_cb, |
839 | NULL, | 856 | NULL, |
840 | GNUNET_FS_FLAGS_NONE, | 857 | GNUNET_FS_FLAGS_NONE, |
841 | GNUNET_FS_OPTIONS_END); | 858 | GNUNET_FS_OPTIONS_END); |
842 | if (NULL == ctx) | 859 | if (NULL == ctx) |
843 | { | 860 | { |
844 | fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); | 861 | fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); |
845 | ret = 1; | 862 | ret = 1; |
846 | return; | 863 | return; |
847 | } | 864 | } |
848 | GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL); | 865 | GNUNET_SCHEDULER_add_shutdown(&do_stop_task, NULL); |
849 | if (NULL != pseudonym) | 866 | if (NULL != pseudonym) |
850 | identity = GNUNET_IDENTITY_connect (cfg, &identity_cb, args[0]); | 867 | identity = GNUNET_IDENTITY_connect(cfg, &identity_cb, args[0]); |
851 | else | 868 | else |
852 | identity_continuation (args[0]); | 869 | identity_continuation(args[0]); |
853 | } | 870 | } |
854 | 871 | ||
855 | 872 | ||
@@ -861,120 +878,121 @@ run (void *cls, | |||
861 | * @return 0 ok, 1 on error | 878 | * @return 0 ok, 1 on error |
862 | */ | 879 | */ |
863 | int | 880 | int |
864 | main (int argc, char *const *argv) | 881 | main(int argc, char *const *argv) |
865 | { | 882 | { |
866 | struct GNUNET_GETOPT_CommandLineOption options[] = | 883 | struct GNUNET_GETOPT_CommandLineOption options[] = |
867 | {GNUNET_GETOPT_option_uint ('a', | 884 | { GNUNET_GETOPT_option_uint('a', |
868 | "anonymity", | 885 | "anonymity", |
869 | "LEVEL", | 886 | "LEVEL", |
870 | gettext_noop ( | 887 | gettext_noop( |
871 | "set the desired LEVEL of sender-anonymity"), | 888 | "set the desired LEVEL of sender-anonymity"), |
872 | &bo.anonymity_level), | 889 | &bo.anonymity_level), |
873 | GNUNET_GETOPT_option_flag ( | 890 | GNUNET_GETOPT_option_flag( |
874 | 'D', | 891 | 'D', |
875 | "disable-extractor", | 892 | "disable-extractor", |
876 | gettext_noop ("do not use libextractor to add keywords or metadata"), | 893 | gettext_noop("do not use libextractor to add keywords or metadata"), |
877 | &disable_extractor), | 894 | &disable_extractor), |
878 | GNUNET_GETOPT_option_flag ('E', | 895 | GNUNET_GETOPT_option_flag('E', |
879 | "enable-creation-time", | 896 | "enable-creation-time", |
880 | gettext_noop ( | 897 | gettext_noop( |
881 | "enable adding the creation time to the " | 898 | "enable adding the creation time to the " |
882 | "metadata of the uploaded file"), | 899 | "metadata of the uploaded file"), |
883 | &enable_creation_time), | 900 | &enable_creation_time), |
884 | GNUNET_GETOPT_option_flag ('e', | 901 | GNUNET_GETOPT_option_flag('e', |
885 | "extract", | 902 | "extract", |
886 | gettext_noop ( | 903 | gettext_noop( |
887 | "print list of extracted keywords that would " | 904 | "print list of extracted keywords that would " |
888 | "be used, but do not perform upload"), | 905 | "be used, but do not perform upload"), |
889 | &extract_only), | 906 | &extract_only), |
890 | GNUNET_FS_GETOPT_KEYWORDS ( | 907 | GNUNET_FS_GETOPT_KEYWORDS( |
891 | 'k', | 908 | 'k', |
892 | "key", | 909 | "key", |
893 | "KEYWORD", | 910 | "KEYWORD", |
894 | gettext_noop ( | 911 | gettext_noop( |
895 | "add an additional keyword for the top-level " | 912 | "add an additional keyword for the top-level " |
896 | "file or directory (this option can be specified multiple times)"), | 913 | "file or directory (this option can be specified multiple times)"), |
897 | &topKeywords), | 914 | &topKeywords), |
898 | GNUNET_FS_GETOPT_METADATA ( | 915 | GNUNET_FS_GETOPT_METADATA( |
899 | 'm', | 916 | 'm', |
900 | "meta", | 917 | "meta", |
901 | "TYPE:VALUE", | 918 | "TYPE:VALUE", |
902 | 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"), |
903 | &meta), | 920 | &meta), |
904 | GNUNET_GETOPT_option_flag ( | 921 | GNUNET_GETOPT_option_flag( |
905 | 'n', | 922 | 'n', |
906 | "noindex", | 923 | "noindex", |
907 | gettext_noop ("do not index, perform full insertion (stores " | 924 | gettext_noop("do not index, perform full insertion (stores " |
908 | "entire file in encrypted form in GNUnet database)"), | 925 | "entire file in encrypted form in GNUnet database)"), |
909 | &do_insert), | 926 | &do_insert), |
910 | GNUNET_GETOPT_option_string ( | 927 | GNUNET_GETOPT_option_string( |
911 | 'N', | 928 | 'N', |
912 | "next", | 929 | "next", |
913 | "ID", | 930 | "ID", |
914 | gettext_noop ("specify ID of an updated version to be " | 931 | gettext_noop("specify ID of an updated version to be " |
915 | "published in the future (for namespace insertions only)"), | 932 | "published in the future (for namespace insertions only)"), |
916 | &next_id), | 933 | &next_id), |
917 | GNUNET_GETOPT_option_uint ('p', | 934 | GNUNET_GETOPT_option_uint('p', |
918 | "priority", | 935 | "priority", |
919 | "PRIORITY", | 936 | "PRIORITY", |
920 | gettext_noop ( | 937 | gettext_noop( |
921 | "specify the priority of the content"), | 938 | "specify the priority of the content"), |
922 | &bo.content_priority), | 939 | &bo.content_priority), |
923 | GNUNET_GETOPT_option_string ('P', | 940 | GNUNET_GETOPT_option_string('P', |
924 | "pseudonym", | 941 | "pseudonym", |
925 | "NAME", | 942 | "NAME", |
926 | gettext_noop ( | 943 | gettext_noop( |
927 | "publish the files under the pseudonym " | 944 | "publish the files under the pseudonym " |
928 | "NAME (place file into namespace)"), | 945 | "NAME (place file into namespace)"), |
929 | &pseudonym), | 946 | &pseudonym), |
930 | GNUNET_GETOPT_option_uint ('r', | 947 | GNUNET_GETOPT_option_uint('r', |
931 | "replication", | 948 | "replication", |
932 | "LEVEL", | 949 | "LEVEL", |
933 | gettext_noop ( | 950 | gettext_noop( |
934 | "set the desired replication LEVEL"), | 951 | "set the desired replication LEVEL"), |
935 | &bo.replication_level), | 952 | &bo.replication_level), |
936 | GNUNET_GETOPT_option_flag ('s', | 953 | GNUNET_GETOPT_option_flag('s', |
937 | "simulate-only", | 954 | "simulate-only", |
938 | gettext_noop ( | 955 | gettext_noop( |
939 | "only simulate the process but do not do " | 956 | "only simulate the process but do not do " |
940 | "any actual publishing (useful to compute URIs)"), | 957 | "any actual publishing (useful to compute URIs)"), |
941 | &do_simulate), | 958 | &do_simulate), |
942 | GNUNET_GETOPT_option_string ('t', | 959 | GNUNET_GETOPT_option_string('t', |
943 | "this", | 960 | "this", |
944 | "ID", | 961 | "ID", |
945 | gettext_noop ( | 962 | gettext_noop( |
946 | "set the ID of this version of the publication " | 963 | "set the ID of this version of the publication " |
947 | "(for namespace insertions only)"), | 964 | "(for namespace insertions only)"), |
948 | &this_id), | 965 | &this_id), |
949 | GNUNET_GETOPT_option_string ( | 966 | GNUNET_GETOPT_option_string( |
950 | 'u', | 967 | 'u', |
951 | "uri", | 968 | "uri", |
952 | "URI", | 969 | "URI", |
953 | gettext_noop ( | 970 | gettext_noop( |
954 | "URI to be published (can be used instead of passing a " | 971 | "URI to be published (can be used instead of passing a " |
955 | "file to add keywords to the file with the respective URI)"), | 972 | "file to add keywords to the file with the respective URI)"), |
956 | &uri_string), | 973 | &uri_string), |
957 | 974 | ||
958 | GNUNET_GETOPT_option_verbose (&verbose), | 975 | GNUNET_GETOPT_option_verbose(&verbose), |
959 | 976 | ||
960 | GNUNET_GETOPT_OPTION_END}; | 977 | GNUNET_GETOPT_OPTION_END }; |
978 | |||
961 | bo.expiration_time = | 979 | bo.expiration_time = |
962 | GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2); | 980 | GNUNET_TIME_year_to_time(GNUNET_TIME_get_current_year() + 2); |
963 | 981 | ||
964 | 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)) |
965 | return 2; | 983 | return 2; |
966 | ret = | 984 | ret = |
967 | (GNUNET_OK == | 985 | (GNUNET_OK == |
968 | GNUNET_PROGRAM_run (argc, | 986 | GNUNET_PROGRAM_run(argc, |
969 | argv, | 987 | argv, |
970 | "gnunet-publish [OPTIONS] FILENAME", | 988 | "gnunet-publish [OPTIONS] FILENAME", |
971 | gettext_noop ("Publish a file or directory on GNUnet"), | 989 | gettext_noop("Publish a file or directory on GNUnet"), |
972 | options, | 990 | options, |
973 | &run, | 991 | &run, |
974 | NULL)) | 992 | NULL)) |
975 | ? ret | 993 | ? ret |
976 | : 1; | 994 | : 1; |
977 | GNUNET_free ((void *) argv); | 995 | GNUNET_free((void *)argv); |
978 | return ret; | 996 | return ret; |
979 | } | 997 | } |
980 | 998 | ||
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index 7d6ff4c6b..ac31387e2 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/gnunet-search.c | 21 | * @file fs/gnunet-search.c |
22 | * @brief searching for files on GNUnet | 22 | * @brief searching for files on GNUnet |
@@ -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,92 +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 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
161 | if (db != NULL) | ||
162 | GNUNET_FS_directory_builder_add (db, | ||
163 | info->value.search.specifics.result.uri, | ||
164 | info->value.search.specifics.result.meta, | ||
165 | NULL); | ||
166 | uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); | ||
167 | printf ("#%u:\n", ++cnt); | ||
168 | filename = GNUNET_CONTAINER_meta_data_get_by_type ( | ||
169 | info->value.search.specifics.result.meta, | ||
170 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | ||
171 | is_directory = GNUNET_FS_meta_data_test_for_directory ( | ||
172 | info->value.search.specifics.result.meta); | ||
173 | if (NULL != filename) | ||
174 | { | 157 | { |
175 | while ((filename[0] != '\0') && ('/' == filename[strlen (filename) - 1])) | 158 | case GNUNET_FS_STATUS_SEARCH_START: |
176 | filename[strlen (filename) - 1] = '\0'; | 159 | break; |
177 | GNUNET_DISK_filename_canonicalize (filename); | 160 | |
178 | if (GNUNET_YES == is_directory) | 161 | case GNUNET_FS_STATUS_SEARCH_RESULT: |
179 | printf ("gnunet-download -o \"%s%s\" -R %s\n", | 162 | if (db != NULL) |
180 | filename, | 163 | GNUNET_FS_directory_builder_add(db, |
181 | GNUNET_FS_DIRECTORY_EXT, | 164 | info->value.search.specifics.result.uri, |
182 | 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) | ||
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); | ||
183 | else | 191 | else |
184 | printf ("gnunet-download -o \"%s\" %s\n", filename, uri); | 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; | ||
185 | } | 228 | } |
186 | else if (GNUNET_YES == is_directory) | ||
187 | printf ("gnunet-download -o \"collection%s\" -R %s\n", | ||
188 | GNUNET_FS_DIRECTORY_EXT, | ||
189 | uri); | ||
190 | else | ||
191 | printf ("gnunet-download %s\n", uri); | ||
192 | if (verbose) | ||
193 | GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.result | ||
194 | .meta, | ||
195 | &item_printer, | ||
196 | NULL); | ||
197 | printf ("\n"); | ||
198 | fflush (stdout); | ||
199 | GNUNET_free_non_null (filename); | ||
200 | GNUNET_free (uri); | ||
201 | results++; | ||
202 | if ((results_limit > 0) && (results >= results_limit)) | ||
203 | GNUNET_SCHEDULER_shutdown (); | ||
204 | break; | ||
205 | case GNUNET_FS_STATUS_SEARCH_UPDATE: | ||
206 | break; | ||
207 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
208 | /* ignore */ | ||
209 | break; | ||
210 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
211 | fprintf (stderr, | ||
212 | _ ("Error searching: %s.\n"), | ||
213 | info->value.search.specifics.error.message); | ||
214 | GNUNET_SCHEDULER_shutdown (); | ||
215 | break; | ||
216 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
217 | GNUNET_SCHEDULER_add_now (&clean_task, NULL); | ||
218 | break; | ||
219 | default: | ||
220 | fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); | ||
221 | break; | ||
222 | } | ||
223 | return NULL; | 229 | return NULL; |
224 | } | 230 | } |
225 | 231 | ||
226 | 232 | ||
227 | static void | 233 | static void |
228 | shutdown_task (void *cls) | 234 | shutdown_task(void *cls) |
229 | { | 235 | { |
230 | if (sc != NULL) | 236 | if (sc != NULL) |
231 | { | 237 | { |
232 | GNUNET_FS_search_stop (sc); | 238 | GNUNET_FS_search_stop(sc); |
233 | sc = NULL; | 239 | sc = NULL; |
234 | } | 240 | } |
235 | } | 241 | } |
236 | 242 | ||
237 | 243 | ||
238 | static void | 244 | static void |
239 | timeout_task (void *cls) | 245 | timeout_task(void *cls) |
240 | { | 246 | { |
241 | tt = NULL; | 247 | tt = NULL; |
242 | GNUNET_SCHEDULER_shutdown (); | 248 | GNUNET_SCHEDULER_shutdown(); |
243 | } | 249 | } |
244 | 250 | ||
245 | 251 | ||
@@ -252,10 +258,10 @@ timeout_task (void *cls) | |||
252 | * @param c configuration | 258 | * @param c configuration |
253 | */ | 259 | */ |
254 | static void | 260 | static void |
255 | run (void *cls, | 261 | run(void *cls, |
256 | char *const *args, | 262 | char *const *args, |
257 | const char *cfgfile, | 263 | const char *cfgfile, |
258 | const struct GNUNET_CONFIGURATION_Handle *c) | 264 | const struct GNUNET_CONFIGURATION_Handle *c) |
259 | { | 265 | { |
260 | struct GNUNET_FS_Uri *uri; | 266 | struct GNUNET_FS_Uri *uri; |
261 | unsigned int argc; | 267 | unsigned int argc; |
@@ -264,46 +270,46 @@ run (void *cls, | |||
264 | argc = 0; | 270 | argc = 0; |
265 | while (NULL != args[argc]) | 271 | while (NULL != args[argc]) |
266 | argc++; | 272 | argc++; |
267 | 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); |
268 | if (NULL == uri) | 274 | if (NULL == uri) |
269 | { | 275 | { |
270 | fprintf (stderr, | 276 | fprintf(stderr, |
271 | "%s", | 277 | "%s", |
272 | _ ("Could not create keyword URI from arguments.\n")); | 278 | _("Could not create keyword URI from arguments.\n")); |
273 | ret = 1; | 279 | ret = 1; |
274 | return; | 280 | return; |
275 | } | 281 | } |
276 | cfg = c; | 282 | cfg = c; |
277 | ctx = GNUNET_FS_start (cfg, | 283 | ctx = GNUNET_FS_start(cfg, |
278 | "gnunet-search", | 284 | "gnunet-search", |
279 | &progress_cb, | 285 | &progress_cb, |
280 | NULL, | 286 | NULL, |
281 | GNUNET_FS_FLAGS_NONE, | 287 | GNUNET_FS_FLAGS_NONE, |
282 | GNUNET_FS_OPTIONS_END); | 288 | GNUNET_FS_OPTIONS_END); |
283 | if (NULL == ctx) | 289 | if (NULL == ctx) |
284 | { | 290 | { |
285 | fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); | 291 | fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); |
286 | GNUNET_FS_uri_destroy (uri); | 292 | GNUNET_FS_uri_destroy(uri); |
287 | ret = 1; | 293 | ret = 1; |
288 | return; | 294 | return; |
289 | } | 295 | } |
290 | if (output_filename != NULL) | 296 | if (output_filename != NULL) |
291 | db = GNUNET_FS_directory_builder_create (NULL); | 297 | db = GNUNET_FS_directory_builder_create(NULL); |
292 | options = GNUNET_FS_SEARCH_OPTION_NONE; | 298 | options = GNUNET_FS_SEARCH_OPTION_NONE; |
293 | if (local_only) | 299 | if (local_only) |
294 | options |= GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY; | 300 | options |= GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY; |
295 | sc = GNUNET_FS_search_start (ctx, uri, anonymity, options, NULL); | 301 | sc = GNUNET_FS_search_start(ctx, uri, anonymity, options, NULL); |
296 | GNUNET_FS_uri_destroy (uri); | 302 | GNUNET_FS_uri_destroy(uri); |
297 | if (NULL == sc) | 303 | if (NULL == sc) |
298 | { | 304 | { |
299 | fprintf (stderr, "%s", _ ("Could not start searching.\n")); | 305 | fprintf(stderr, "%s", _("Could not start searching.\n")); |
300 | GNUNET_FS_stop (ctx); | 306 | GNUNET_FS_stop(ctx); |
301 | ret = 1; | 307 | ret = 1; |
302 | return; | 308 | return; |
303 | } | 309 | } |
304 | if (0 != timeout.rel_value_us) | 310 | if (0 != timeout.rel_value_us) |
305 | tt = GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, NULL); | 311 | tt = GNUNET_SCHEDULER_add_delayed(timeout, &timeout_task, NULL); |
306 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 312 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
307 | } | 313 | } |
308 | 314 | ||
309 | 315 | ||
@@ -315,57 +321,57 @@ run (void *cls, | |||
315 | * @return 0 ok, 1 on error | 321 | * @return 0 ok, 1 on error |
316 | */ | 322 | */ |
317 | int | 323 | int |
318 | main (int argc, char *const *argv) | 324 | main(int argc, char *const *argv) |
319 | { | 325 | { |
320 | struct GNUNET_GETOPT_CommandLineOption options[] = | 326 | struct GNUNET_GETOPT_CommandLineOption options[] = |
321 | {GNUNET_GETOPT_option_uint ('a', | 327 | { GNUNET_GETOPT_option_uint('a', |
322 | "anonymity", | 328 | "anonymity", |
323 | "LEVEL", | 329 | "LEVEL", |
324 | gettext_noop ( | 330 | gettext_noop( |
325 | "set the desired LEVEL of receiver-anonymity"), | 331 | "set the desired LEVEL of receiver-anonymity"), |
326 | &anonymity), | 332 | &anonymity), |
327 | GNUNET_GETOPT_option_flag ( | 333 | GNUNET_GETOPT_option_flag( |
328 | 'n', | 334 | 'n', |
329 | "no-network", | 335 | "no-network", |
330 | gettext_noop ("only search the local peer (no P2P network search)"), | 336 | gettext_noop("only search the local peer (no P2P network search)"), |
331 | &local_only), | 337 | &local_only), |
332 | GNUNET_GETOPT_option_string ( | 338 | GNUNET_GETOPT_option_string( |
333 | 'o', | 339 | 'o', |
334 | "output", | 340 | "output", |
335 | "PREFIX", | 341 | "PREFIX", |
336 | gettext_noop ("write search results to file starting with PREFIX"), | 342 | gettext_noop("write search results to file starting with PREFIX"), |
337 | &output_filename), | 343 | &output_filename), |
338 | GNUNET_GETOPT_option_relative_time ( | 344 | GNUNET_GETOPT_option_relative_time( |
339 | 't', | 345 | 't', |
340 | "timeout", | 346 | "timeout", |
341 | "DELAY", | 347 | "DELAY", |
342 | gettext_noop ("automatically terminate search after DELAY"), | 348 | gettext_noop("automatically terminate search after DELAY"), |
343 | &timeout), | 349 | &timeout), |
344 | GNUNET_GETOPT_option_verbose (&verbose), | 350 | GNUNET_GETOPT_option_verbose(&verbose), |
345 | GNUNET_GETOPT_option_uint ('N', | 351 | GNUNET_GETOPT_option_uint('N', |
346 | "results", | 352 | "results", |
347 | "VALUE", | 353 | "VALUE", |
348 | gettext_noop ("automatically terminate search " | 354 | gettext_noop("automatically terminate search " |
349 | "after VALUE results are found"), | 355 | "after VALUE results are found"), |
350 | &results_limit), | 356 | &results_limit), |
351 | GNUNET_GETOPT_OPTION_END}; | 357 | GNUNET_GETOPT_OPTION_END }; |
352 | 358 | ||
353 | 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)) |
354 | return 2; | 360 | return 2; |
355 | 361 | ||
356 | ret = | 362 | ret = |
357 | (GNUNET_OK == | 363 | (GNUNET_OK == |
358 | GNUNET_PROGRAM_run (argc, | 364 | GNUNET_PROGRAM_run(argc, |
359 | argv, | 365 | argv, |
360 | "gnunet-search [OPTIONS] KEYWORD", | 366 | "gnunet-search [OPTIONS] KEYWORD", |
361 | gettext_noop ( | 367 | gettext_noop( |
362 | "Search GNUnet for files that were published on GNUnet"), | 368 | "Search GNUnet for files that were published on GNUnet"), |
363 | options, | 369 | options, |
364 | &run, | 370 | &run, |
365 | NULL)) | 371 | NULL)) |
366 | ? ret | 372 | ? ret |
367 | : 1; | 373 | : 1; |
368 | GNUNET_free ((void *) argv); | 374 | GNUNET_free((void *)argv); |
369 | return ret; | 375 | return ret; |
370 | } | 376 | } |
371 | 377 | ||
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 691242ce3..70aff8a75 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs.c | 22 | * @file fs/gnunet-service-fs.c |
@@ -59,7 +59,7 @@ | |||
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(GNUNET_TIME_UNIT_SECONDS, 5) |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Collect an instane number of statistics? May cause excessive IPC. | 65 | * Collect an instane number of statistics? May cause excessive IPC. |
@@ -72,9 +72,7 @@ | |||
72 | * Doubly-linked list of requests we are performing | 72 | * Doubly-linked list of requests we are performing |
73 | * on behalf of the same client. | 73 | * on behalf of the same client. |
74 | */ | 74 | */ |
75 | struct ClientRequest | 75 | struct ClientRequest { |
76 | { | ||
77 | |||
78 | /** | 76 | /** |
79 | * This is a doubly-linked list. | 77 | * This is a doubly-linked list. |
80 | */ | 78 | */ |
@@ -99,7 +97,6 @@ struct ClientRequest | |||
99 | * Task scheduled to destroy the request. | 97 | * Task scheduled to destroy the request. |
100 | */ | 98 | */ |
101 | struct GNUNET_SCHEDULER_Task * kill_task; | 99 | struct GNUNET_SCHEDULER_Task * kill_task; |
102 | |||
103 | }; | 100 | }; |
104 | 101 | ||
105 | 102 | ||
@@ -107,8 +104,7 @@ struct ClientRequest | |||
107 | * Replies to be transmitted to the client. The actual | 104 | * Replies to be transmitted to the client. The actual |
108 | * response message is allocated after this struct. | 105 | * response message is allocated after this struct. |
109 | */ | 106 | */ |
110 | struct ClientResponse | 107 | struct ClientResponse { |
111 | { | ||
112 | /** | 108 | /** |
113 | * This is a doubly-linked list. | 109 | * This is a doubly-linked list. |
114 | */ | 110 | */ |
@@ -135,9 +131,7 @@ struct ClientResponse | |||
135 | * Information we track while handling an index | 131 | * Information we track while handling an index |
136 | * start request from a client. | 132 | * start request from a client. |
137 | */ | 133 | */ |
138 | struct IndexStartContext | 134 | struct IndexStartContext { |
139 | { | ||
140 | |||
141 | /** | 135 | /** |
142 | * This is a doubly linked list. | 136 | * This is a doubly linked list. |
143 | */ | 137 | */ |
@@ -167,16 +161,13 @@ struct IndexStartContext | |||
167 | * Hash of the contents of the file. | 161 | * Hash of the contents of the file. |
168 | */ | 162 | */ |
169 | struct GNUNET_HashCode file_id; | 163 | struct GNUNET_HashCode file_id; |
170 | |||
171 | }; | 164 | }; |
172 | 165 | ||
173 | 166 | ||
174 | /** | 167 | /** |
175 | * A local client. | 168 | * A local client. |
176 | */ | 169 | */ |
177 | struct GSF_LocalClient | 170 | struct GSF_LocalClient { |
178 | { | ||
179 | |||
180 | /** | 171 | /** |
181 | * ID of the client. | 172 | * ID of the client. |
182 | */ | 173 | */ |
@@ -218,7 +209,6 @@ struct GSF_LocalClient | |||
218 | * Tail of linked list of responses. | 209 | * Tail of linked list of responses. |
219 | */ | 210 | */ |
220 | struct ClientResponse *res_tail; | 211 | struct ClientResponse *res_tail; |
221 | |||
222 | }; | 212 | }; |
223 | 213 | ||
224 | 214 | ||
@@ -343,13 +333,13 @@ static struct GNUNET_LOAD_Value *datastore_get_load; | |||
343 | * @return handle to local client entry | 333 | * @return handle to local client entry |
344 | */ | 334 | */ |
345 | static void * | 335 | static void * |
346 | client_connect_cb (void *cls, | 336 | client_connect_cb(void *cls, |
347 | struct GNUNET_SERVICE_Client *client, | 337 | struct GNUNET_SERVICE_Client *client, |
348 | struct GNUNET_MQ_Handle *mq) | 338 | struct GNUNET_MQ_Handle *mq) |
349 | { | 339 | { |
350 | struct GSF_LocalClient *pos; | 340 | struct GSF_LocalClient *pos; |
351 | 341 | ||
352 | pos = GNUNET_new (struct GSF_LocalClient); | 342 | pos = GNUNET_new(struct GSF_LocalClient); |
353 | pos->client = client; | 343 | pos->client = client; |
354 | pos->mq = mq; | 344 | pos->mq = mq; |
355 | return pos; | 345 | return pos; |
@@ -362,22 +352,22 @@ client_connect_cb (void *cls, | |||
362 | * @param cls the client request to free | 352 | * @param cls the client request to free |
363 | */ | 353 | */ |
364 | static void | 354 | static void |
365 | client_request_destroy (void *cls) | 355 | client_request_destroy(void *cls) |
366 | { | 356 | { |
367 | struct ClientRequest *cr = cls; | 357 | struct ClientRequest *cr = cls; |
368 | struct GSF_LocalClient *lc = cr->lc; | 358 | struct GSF_LocalClient *lc = cr->lc; |
369 | 359 | ||
370 | cr->kill_task = NULL; | 360 | cr->kill_task = NULL; |
371 | GNUNET_CONTAINER_DLL_remove (lc->cr_head, | 361 | GNUNET_CONTAINER_DLL_remove(lc->cr_head, |
372 | lc->cr_tail, | 362 | lc->cr_tail, |
373 | cr); | 363 | cr); |
374 | GSF_pending_request_cancel_ (cr->pr, | 364 | GSF_pending_request_cancel_(cr->pr, |
375 | GNUNET_YES); | 365 | GNUNET_YES); |
376 | GNUNET_STATISTICS_update (GSF_stats, | 366 | GNUNET_STATISTICS_update(GSF_stats, |
377 | gettext_noop ("# client searches active"), | 367 | gettext_noop("# client searches active"), |
378 | -1, | 368 | -1, |
379 | GNUNET_NO); | 369 | GNUNET_NO); |
380 | GNUNET_free (cr); | 370 | GNUNET_free(cr); |
381 | } | 371 | } |
382 | 372 | ||
383 | 373 | ||
@@ -400,15 +390,15 @@ client_request_destroy (void *cls) | |||
400 | * @param data_len number of bytes in @a data | 390 | * @param data_len number of bytes in @a data |
401 | */ | 391 | */ |
402 | static void | 392 | static void |
403 | client_response_handler (void *cls, | 393 | client_response_handler(void *cls, |
404 | enum GNUNET_BLOCK_EvaluationResult eval, | 394 | enum GNUNET_BLOCK_EvaluationResult eval, |
405 | struct GSF_PendingRequest *pr, | 395 | struct GSF_PendingRequest *pr, |
406 | uint32_t reply_anonymity_level, | 396 | uint32_t reply_anonymity_level, |
407 | struct GNUNET_TIME_Absolute expiration, | 397 | struct GNUNET_TIME_Absolute expiration, |
408 | struct GNUNET_TIME_Absolute last_transmission, | 398 | struct GNUNET_TIME_Absolute last_transmission, |
409 | enum GNUNET_BLOCK_Type type, | 399 | enum GNUNET_BLOCK_Type type, |
410 | const void *data, | 400 | const void *data, |
411 | size_t data_len) | 401 | size_t data_len) |
412 | { | 402 | { |
413 | struct ClientRequest *cr = cls; | 403 | struct ClientRequest *cr = cls; |
414 | struct GSF_LocalClient *lc; | 404 | struct GSF_LocalClient *lc; |
@@ -417,52 +407,52 @@ client_response_handler (void *cls, | |||
417 | const struct GSF_PendingRequestData *prd; | 407 | const struct GSF_PendingRequestData *prd; |
418 | 408 | ||
419 | if (NULL == data) | 409 | if (NULL == data) |
420 | { | 410 | { |
421 | /* local-only request, with no result, clean up. */ | 411 | /* local-only request, with no result, clean up. */ |
422 | if (NULL == cr->kill_task) | 412 | if (NULL == cr->kill_task) |
423 | cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, | 413 | cr->kill_task = GNUNET_SCHEDULER_add_now(&client_request_destroy, |
424 | cr); | 414 | cr); |
425 | return; | 415 | return; |
426 | } | 416 | } |
427 | prd = GSF_pending_request_get_data_ (pr); | 417 | prd = GSF_pending_request_get_data_(pr); |
428 | GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY); | 418 | GNUNET_break(type != GNUNET_BLOCK_TYPE_ANY); |
429 | if ((prd->type != type) && (prd->type != GNUNET_BLOCK_TYPE_ANY)) | 419 | if ((prd->type != type) && (prd->type != GNUNET_BLOCK_TYPE_ANY)) |
430 | { | 420 | { |
431 | GNUNET_break (0); | 421 | GNUNET_break(0); |
432 | return; | 422 | return; |
433 | } | 423 | } |
434 | GNUNET_STATISTICS_update (GSF_stats, | 424 | GNUNET_STATISTICS_update(GSF_stats, |
435 | gettext_noop | 425 | gettext_noop |
436 | ("# replies received for local clients"), 1, | 426 | ("# replies received for local clients"), 1, |
437 | GNUNET_NO); | 427 | GNUNET_NO); |
438 | GNUNET_assert (pr == cr->pr); | 428 | GNUNET_assert(pr == cr->pr); |
439 | lc = cr->lc; | 429 | lc = cr->lc; |
440 | env = GNUNET_MQ_msg_extra (pm, | 430 | env = GNUNET_MQ_msg_extra(pm, |
441 | data_len, | 431 | data_len, |
442 | GNUNET_MESSAGE_TYPE_FS_PUT); | 432 | GNUNET_MESSAGE_TYPE_FS_PUT); |
443 | pm->type = htonl (type); | 433 | pm->type = htonl(type); |
444 | pm->expiration = GNUNET_TIME_absolute_hton (expiration); | 434 | pm->expiration = GNUNET_TIME_absolute_hton(expiration); |
445 | pm->last_transmission = GNUNET_TIME_absolute_hton (last_transmission); | 435 | pm->last_transmission = GNUNET_TIME_absolute_hton(last_transmission); |
446 | pm->num_transmissions = htonl (prd->num_transmissions); | 436 | pm->num_transmissions = htonl(prd->num_transmissions); |
447 | pm->respect_offered = htonl (prd->respect_offered); | 437 | pm->respect_offered = htonl(prd->respect_offered); |
448 | GNUNET_memcpy (&pm[1], | 438 | GNUNET_memcpy(&pm[1], |
449 | data, | 439 | data, |
450 | data_len); | 440 | data_len); |
451 | GNUNET_MQ_send (lc->mq, | 441 | GNUNET_MQ_send(lc->mq, |
452 | env); | 442 | env); |
453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 443 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
454 | "Queued reply to query `%s' for local client\n", | 444 | "Queued reply to query `%s' for local client\n", |
455 | GNUNET_h2s (&prd->query)); | 445 | GNUNET_h2s(&prd->query)); |
456 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval) | 446 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval) |
457 | { | 447 | { |
458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 448 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
459 | "Evaluation %d - keeping query alive\n", | 449 | "Evaluation %d - keeping query alive\n", |
460 | (int) eval); | 450 | (int)eval); |
461 | return; | 451 | return; |
462 | } | 452 | } |
463 | if (NULL == cr->kill_task) | 453 | if (NULL == cr->kill_task) |
464 | cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, | 454 | cr->kill_task = GNUNET_SCHEDULER_add_now(&client_request_destroy, |
465 | cr); | 455 | cr); |
466 | } | 456 | } |
467 | 457 | ||
468 | 458 | ||
@@ -475,9 +465,9 @@ client_response_handler (void *cls, | |||
475 | * @param app_ctx the `struct GSF_LocalClient` | 465 | * @param app_ctx the `struct GSF_LocalClient` |
476 | */ | 466 | */ |
477 | static void | 467 | static void |
478 | client_disconnect_cb (void *cls, | 468 | client_disconnect_cb(void *cls, |
479 | struct GNUNET_SERVICE_Client *client, | 469 | struct GNUNET_SERVICE_Client *client, |
480 | void *app_ctx) | 470 | void *app_ctx) |
481 | { | 471 | { |
482 | struct GSF_LocalClient *lc = app_ctx; | 472 | struct GSF_LocalClient *lc = app_ctx; |
483 | struct IndexStartContext *isc; | 473 | struct IndexStartContext *isc; |
@@ -485,27 +475,27 @@ client_disconnect_cb (void *cls, | |||
485 | struct ClientResponse *res; | 475 | struct ClientResponse *res; |
486 | 476 | ||
487 | while (NULL != (cr = lc->cr_head)) | 477 | while (NULL != (cr = lc->cr_head)) |
488 | { | 478 | { |
489 | if (NULL != cr->kill_task) | 479 | if (NULL != cr->kill_task) |
490 | GNUNET_SCHEDULER_cancel (cr->kill_task); | 480 | GNUNET_SCHEDULER_cancel(cr->kill_task); |
491 | client_request_destroy (cr); | 481 | client_request_destroy(cr); |
492 | } | 482 | } |
493 | while (NULL != (res = lc->res_head)) | 483 | while (NULL != (res = lc->res_head)) |
494 | { | 484 | { |
495 | GNUNET_CONTAINER_DLL_remove (lc->res_head, | 485 | GNUNET_CONTAINER_DLL_remove(lc->res_head, |
496 | lc->res_tail, | 486 | lc->res_tail, |
497 | res); | 487 | res); |
498 | GNUNET_free (res); | 488 | GNUNET_free(res); |
499 | } | 489 | } |
500 | while (NULL != (isc = lc->isc_head)) | 490 | while (NULL != (isc = lc->isc_head)) |
501 | { | 491 | { |
502 | GNUNET_CONTAINER_DLL_remove (lc->isc_head, | 492 | GNUNET_CONTAINER_DLL_remove(lc->isc_head, |
503 | lc->isc_tail, | 493 | lc->isc_tail, |
504 | isc); | 494 | isc); |
505 | GNUNET_CRYPTO_hash_file_cancel (isc->fhc); | 495 | GNUNET_CRYPTO_hash_file_cancel(isc->fhc); |
506 | GNUNET_free (isc); | 496 | GNUNET_free(isc); |
507 | } | 497 | } |
508 | GNUNET_free (lc); | 498 | GNUNET_free(lc); |
509 | } | 499 | } |
510 | 500 | ||
511 | 501 | ||
@@ -518,14 +508,14 @@ client_disconnect_cb (void *cls, | |||
518 | * @param cls unused closure | 508 | * @param cls unused closure |
519 | */ | 509 | */ |
520 | static void | 510 | static void |
521 | age_cover_counters (void *cls) | 511 | age_cover_counters(void *cls) |
522 | { | 512 | { |
523 | GSF_cover_content_count = (GSF_cover_content_count * 15) / 16; | 513 | GSF_cover_content_count = (GSF_cover_content_count * 15) / 16; |
524 | GSF_cover_query_count = (GSF_cover_query_count * 15) / 16; | 514 | GSF_cover_query_count = (GSF_cover_query_count * 15) / 16; |
525 | cover_age_task = | 515 | cover_age_task = |
526 | GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, | 516 | GNUNET_SCHEDULER_add_delayed(COVER_AGE_FREQUENCY, |
527 | &age_cover_counters, | 517 | &age_cover_counters, |
528 | NULL); | 518 | NULL); |
529 | } | 519 | } |
530 | 520 | ||
531 | 521 | ||
@@ -536,12 +526,12 @@ age_cover_counters (void *cls) | |||
536 | * @param start time when the datastore request was issued | 526 | * @param start time when the datastore request was issued |
537 | */ | 527 | */ |
538 | void | 528 | void |
539 | GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start) | 529 | GSF_update_datastore_delay_(struct GNUNET_TIME_Absolute start) |
540 | { | 530 | { |
541 | struct GNUNET_TIME_Relative delay; | 531 | struct GNUNET_TIME_Relative delay; |
542 | 532 | ||
543 | delay = GNUNET_TIME_absolute_get_duration (start); | 533 | delay = GNUNET_TIME_absolute_get_duration(start); |
544 | GNUNET_LOAD_update (datastore_get_load, delay.rel_value_us); | 534 | GNUNET_LOAD_update(datastore_get_load, delay.rel_value_us); |
545 | } | 535 | } |
546 | 536 | ||
547 | 537 | ||
@@ -556,11 +546,11 @@ GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start) | |||
556 | * #GNUNET_SYSERR to process for free (load low) | 546 | * #GNUNET_SYSERR to process for free (load low) |
557 | */ | 547 | */ |
558 | int | 548 | int |
559 | GSF_test_get_load_too_high_ (uint32_t priority) | 549 | GSF_test_get_load_too_high_(uint32_t priority) |
560 | { | 550 | { |
561 | double ld; | 551 | double ld; |
562 | 552 | ||
563 | ld = GNUNET_LOAD_get_load (datastore_get_load); | 553 | ld = GNUNET_LOAD_get_load(datastore_get_load); |
564 | if (ld < 1) | 554 | if (ld < 1) |
565 | return GNUNET_SYSERR; | 555 | return GNUNET_SYSERR; |
566 | if (ld <= priority) | 556 | if (ld <= priority) |
@@ -581,30 +571,30 @@ GSF_test_get_load_too_high_ (uint32_t priority) | |||
581 | * @param prop performance data for the address (as far as known) | 571 | * @param prop performance data for the address (as far as known) |
582 | */ | 572 | */ |
583 | static void | 573 | static void |
584 | update_latencies (void *cls, | 574 | update_latencies(void *cls, |
585 | const struct GNUNET_HELLO_Address *address, | 575 | const struct GNUNET_HELLO_Address *address, |
586 | int active, | 576 | int active, |
587 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 577 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
588 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 578 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
589 | const struct GNUNET_ATS_Properties *prop) | 579 | const struct GNUNET_ATS_Properties *prop) |
590 | { | 580 | { |
591 | if (NULL == address) | 581 | if (NULL == address) |
592 | { | 582 | { |
593 | /* ATS service temporarily disconnected */ | 583 | /* ATS service temporarily disconnected */ |
594 | return; | 584 | return; |
595 | } | 585 | } |
596 | 586 | ||
597 | if (GNUNET_YES != active) | 587 | if (GNUNET_YES != active) |
598 | return; | 588 | return; |
599 | GSF_update_peer_latency_ (&address->peer, | 589 | GSF_update_peer_latency_(&address->peer, |
600 | prop->delay); | 590 | prop->delay); |
601 | GSF_avg_latency.rel_value_us = | 591 | GSF_avg_latency.rel_value_us = |
602 | (GSF_avg_latency.rel_value_us * 31 + | 592 | (GSF_avg_latency.rel_value_us * 31 + |
603 | GNUNET_MIN (5000, prop->delay.rel_value_us)) / 32; | 593 | GNUNET_MIN(5000, prop->delay.rel_value_us)) / 32; |
604 | GNUNET_STATISTICS_set (GSF_stats, | 594 | GNUNET_STATISTICS_set(GSF_stats, |
605 | gettext_noop ("# running average P2P latency (ms)"), | 595 | gettext_noop("# running average P2P latency (ms)"), |
606 | GSF_avg_latency.rel_value_us / 1000LL, | 596 | GSF_avg_latency.rel_value_us / 1000LL, |
607 | GNUNET_NO); | 597 | GNUNET_NO); |
608 | } | 598 | } |
609 | 599 | ||
610 | 600 | ||
@@ -617,17 +607,17 @@ update_latencies (void *cls, | |||
617 | * #GNUNET_SYSERR to close it (signal serious error) | 607 | * #GNUNET_SYSERR to close it (signal serious error) |
618 | */ | 608 | */ |
619 | static int | 609 | static int |
620 | check_p2p_put (void *cls, | 610 | check_p2p_put(void *cls, |
621 | const struct PutMessage *put) | 611 | const struct PutMessage *put) |
622 | { | 612 | { |
623 | enum GNUNET_BLOCK_Type type; | 613 | enum GNUNET_BLOCK_Type type; |
624 | 614 | ||
625 | type = ntohl (put->type); | 615 | type = ntohl(put->type); |
626 | if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) | 616 | if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) |
627 | { | 617 | { |
628 | GNUNET_break_op (0); | 618 | GNUNET_break_op(0); |
629 | return GNUNET_SYSERR; | 619 | return GNUNET_SYSERR; |
630 | } | 620 | } |
631 | return GNUNET_OK; | 621 | return GNUNET_OK; |
632 | } | 622 | } |
633 | 623 | ||
@@ -642,25 +632,25 @@ check_p2p_put (void *cls, | |||
642 | * @param ppd peer performance data | 632 | * @param ppd peer performance data |
643 | */ | 633 | */ |
644 | static void | 634 | static void |
645 | consider_request_for_forwarding (void *cls, | 635 | consider_request_for_forwarding(void *cls, |
646 | const struct GNUNET_PeerIdentity *peer, | 636 | const struct GNUNET_PeerIdentity *peer, |
647 | struct GSF_ConnectedPeer *cp, | 637 | struct GSF_ConnectedPeer *cp, |
648 | const struct GSF_PeerPerformanceData *ppd) | 638 | const struct GSF_PeerPerformanceData *ppd) |
649 | { | 639 | { |
650 | struct GSF_PendingRequest *pr = cls; | 640 | struct GSF_PendingRequest *pr = cls; |
651 | 641 | ||
652 | if (GNUNET_YES != | 642 | if (GNUNET_YES != |
653 | GSF_pending_request_test_target_ (pr, peer)) | 643 | GSF_pending_request_test_target_(pr, peer)) |
654 | { | 644 | { |
655 | #if INSANE_STATISTICS | 645 | #if INSANE_STATISTICS |
656 | GNUNET_STATISTICS_update (GSF_stats, | 646 | GNUNET_STATISTICS_update(GSF_stats, |
657 | gettext_noop ("# Loopback routes suppressed"), 1, | 647 | gettext_noop("# Loopback routes suppressed"), 1, |
658 | GNUNET_NO); | 648 | GNUNET_NO); |
659 | #endif | 649 | #endif |
660 | return; | 650 | return; |
661 | } | 651 | } |
662 | GSF_plan_add_ (cp, | 652 | GSF_plan_add_(cp, |
663 | pr); | 653 | pr); |
664 | } | 654 | } |
665 | 655 | ||
666 | 656 | ||
@@ -675,17 +665,17 @@ consider_request_for_forwarding (void *cls, | |||
675 | * @param result final datastore lookup result | 665 | * @param result final datastore lookup result |
676 | */ | 666 | */ |
677 | void | 667 | void |
678 | GSF_consider_forwarding (void *cls, | 668 | GSF_consider_forwarding(void *cls, |
679 | struct GSF_PendingRequest *pr, | 669 | struct GSF_PendingRequest *pr, |
680 | enum GNUNET_BLOCK_EvaluationResult result) | 670 | enum GNUNET_BLOCK_EvaluationResult result) |
681 | { | 671 | { |
682 | if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) | 672 | if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) |
683 | return; /* we're done... */ | 673 | return; /* we're done... */ |
684 | if (GNUNET_YES != | 674 | if (GNUNET_YES != |
685 | GSF_pending_request_test_active_ (pr)) | 675 | GSF_pending_request_test_active_(pr)) |
686 | return; /* request is not actually active, skip! */ | 676 | return; /* request is not actually active, skip! */ |
687 | GSF_iterate_connected_peers_ (&consider_request_for_forwarding, | 677 | GSF_iterate_connected_peers_(&consider_request_for_forwarding, |
688 | pr); | 678 | pr); |
689 | } | 679 | } |
690 | 680 | ||
691 | 681 | ||
@@ -698,35 +688,35 @@ GSF_consider_forwarding (void *cls, | |||
698 | * #GNUNET_SYSERR to close it (signal serious error) | 688 | * #GNUNET_SYSERR to close it (signal serious error) |
699 | */ | 689 | */ |
700 | static int | 690 | static int |
701 | check_p2p_get (void *cls, | 691 | check_p2p_get(void *cls, |
702 | const struct GetMessage *gm) | 692 | const struct GetMessage *gm) |
703 | { | 693 | { |
704 | size_t msize; | 694 | size_t msize; |
705 | unsigned int bm; | 695 | unsigned int bm; |
706 | unsigned int bits; | 696 | unsigned int bits; |
707 | size_t bfsize; | 697 | size_t bfsize; |
708 | 698 | ||
709 | msize = ntohs (gm->header.size); | 699 | msize = ntohs(gm->header.size); |
710 | bm = ntohl (gm->hash_bitmap); | 700 | bm = ntohl(gm->hash_bitmap); |
711 | bits = 0; | 701 | bits = 0; |
712 | while (bm > 0) | 702 | while (bm > 0) |
713 | { | 703 | { |
714 | if (1 == (bm & 1)) | 704 | if (1 == (bm & 1)) |
715 | bits++; | 705 | bits++; |
716 | bm >>= 1; | 706 | bm >>= 1; |
717 | } | 707 | } |
718 | if (msize < sizeof (struct GetMessage) + bits * sizeof (struct GNUNET_PeerIdentity)) | 708 | if (msize < sizeof(struct GetMessage) + bits * sizeof(struct GNUNET_PeerIdentity)) |
719 | { | 709 | { |
720 | GNUNET_break_op (0); | 710 | GNUNET_break_op(0); |
721 | return GNUNET_SYSERR; | 711 | return GNUNET_SYSERR; |
722 | } | 712 | } |
723 | bfsize = msize - sizeof (struct GetMessage) - bits * sizeof (struct GNUNET_PeerIdentity); | 713 | bfsize = msize - sizeof(struct GetMessage) - bits * sizeof(struct GNUNET_PeerIdentity); |
724 | /* bfsize must be power of 2, check! */ | 714 | /* bfsize must be power of 2, check! */ |
725 | if (0 != ((bfsize - 1) & bfsize)) | 715 | if (0 != ((bfsize - 1) & bfsize)) |
726 | { | 716 | { |
727 | GNUNET_break_op (0); | 717 | GNUNET_break_op(0); |
728 | return GNUNET_SYSERR; | 718 | return GNUNET_SYSERR; |
729 | } | 719 | } |
730 | return GNUNET_OK; | 720 | return GNUNET_OK; |
731 | } | 721 | } |
732 | 722 | ||
@@ -742,46 +732,48 @@ check_p2p_get (void *cls, | |||
742 | * @param result final datastore lookup result | 732 | * @param result final datastore lookup result |
743 | */ | 733 | */ |
744 | static void | 734 | static void |
745 | start_p2p_processing (void *cls, | 735 | start_p2p_processing(void *cls, |
746 | struct GSF_PendingRequest *pr, | 736 | struct GSF_PendingRequest *pr, |
747 | enum GNUNET_BLOCK_EvaluationResult result) | 737 | enum GNUNET_BLOCK_EvaluationResult result) |
748 | { | 738 | { |
749 | struct GSF_LocalClient *lc = cls; | 739 | struct GSF_LocalClient *lc = cls; |
750 | struct GSF_PendingRequestData *prd; | 740 | struct GSF_PendingRequestData *prd; |
751 | 741 | ||
752 | GNUNET_SERVICE_client_continue (lc->client); | 742 | GNUNET_SERVICE_client_continue(lc->client); |
753 | if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) | 743 | if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) |
754 | return; /* we're done, 'pr' was already destroyed... */ | 744 | return; /* we're done, 'pr' was already destroyed... */ |
755 | prd = GSF_pending_request_get_data_ (pr); | 745 | prd = GSF_pending_request_get_data_(pr); |
756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 746 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
757 | "Finished database lookup for local request `%s' with result %d\n", | 747 | "Finished database lookup for local request `%s' with result %d\n", |
758 | GNUNET_h2s (&prd->query), | 748 | GNUNET_h2s(&prd->query), |
759 | result); | 749 | result); |
760 | if (0 == prd->anonymity_level) | 750 | if (0 == prd->anonymity_level) |
761 | { | ||
762 | switch (prd->type) | ||
763 | { | 751 | { |
764 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | 752 | switch (prd->type) |
765 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | 753 | { |
766 | /* the above block types MAY be available via 'cadet' */ | 754 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
767 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 755 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: |
768 | "Considering cadet-based download for block\n"); | 756 | /* the above block types MAY be available via 'cadet' */ |
769 | GSF_cadet_lookup_ (pr); | 757 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
770 | break; | 758 | "Considering cadet-based download for block\n"); |
771 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | 759 | GSF_cadet_lookup_(pr); |
772 | /* the above block types are in the DHT */ | 760 | break; |
773 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 761 | |
774 | "Considering DHT-based search for block\n"); | 762 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
775 | GSF_dht_lookup_ (pr); | 763 | /* the above block types are in the DHT */ |
776 | break; | 764 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
777 | default: | 765 | "Considering DHT-based search for block\n"); |
778 | GNUNET_break (0); | 766 | GSF_dht_lookup_(pr); |
779 | break; | 767 | break; |
768 | |||
769 | default: | ||
770 | GNUNET_break(0); | ||
771 | break; | ||
772 | } | ||
780 | } | 773 | } |
781 | } | 774 | GSF_consider_forwarding(NULL, |
782 | GSF_consider_forwarding (NULL, | 775 | pr, |
783 | pr, | 776 | result); |
784 | result); | ||
785 | } | 777 | } |
786 | 778 | ||
787 | 779 | ||
@@ -794,17 +786,17 @@ start_p2p_processing (void *cls, | |||
794 | * @return #GNUNET_OK if @a sm is well-formed | 786 | * @return #GNUNET_OK if @a sm is well-formed |
795 | */ | 787 | */ |
796 | static int | 788 | static int |
797 | check_client_start_search (void *cls, | 789 | check_client_start_search(void *cls, |
798 | const struct SearchMessage *sm) | 790 | const struct SearchMessage *sm) |
799 | { | 791 | { |
800 | uint16_t msize; | 792 | uint16_t msize; |
801 | 793 | ||
802 | msize = ntohs (sm->header.size) - sizeof (struct SearchMessage); | 794 | msize = ntohs(sm->header.size) - sizeof(struct SearchMessage); |
803 | if (0 != msize % sizeof (struct GNUNET_HashCode)) | 795 | if (0 != msize % sizeof(struct GNUNET_HashCode)) |
804 | { | 796 | { |
805 | GNUNET_break (0); | 797 | GNUNET_break(0); |
806 | return GNUNET_SYSERR; | 798 | return GNUNET_SYSERR; |
807 | } | 799 | } |
808 | return GNUNET_OK; | 800 | return GNUNET_OK; |
809 | } | 801 | } |
810 | 802 | ||
@@ -820,8 +812,8 @@ check_client_start_search (void *cls, | |||
820 | * @param sm the actual message | 812 | * @param sm the actual message |
821 | */ | 813 | */ |
822 | static void | 814 | static void |
823 | handle_client_start_search (void *cls, | 815 | handle_client_start_search(void *cls, |
824 | const struct SearchMessage *sm) | 816 | const struct SearchMessage *sm) |
825 | { | 817 | { |
826 | static struct GNUNET_PeerIdentity all_zeros; | 818 | static struct GNUNET_PeerIdentity all_zeros; |
827 | struct GSF_LocalClient *lc = cls; | 819 | struct GSF_LocalClient *lc = cls; |
@@ -832,90 +824,90 @@ handle_client_start_search (void *cls, | |||
832 | enum GNUNET_BLOCK_Type type; | 824 | enum GNUNET_BLOCK_Type type; |
833 | enum GSF_PendingRequestOptions options; | 825 | enum GSF_PendingRequestOptions options; |
834 | 826 | ||
835 | GNUNET_STATISTICS_update (GSF_stats, | 827 | GNUNET_STATISTICS_update(GSF_stats, |
836 | gettext_noop ("# client searches received"), | 828 | gettext_noop("# client searches received"), |
837 | 1, | 829 | 1, |
838 | GNUNET_NO); | 830 | GNUNET_NO); |
839 | msize = ntohs (sm->header.size) - sizeof (struct SearchMessage); | 831 | msize = ntohs(sm->header.size) - sizeof(struct SearchMessage); |
840 | sc = msize / sizeof (struct GNUNET_HashCode); | 832 | sc = msize / sizeof(struct GNUNET_HashCode); |
841 | type = ntohl (sm->type); | 833 | type = ntohl(sm->type); |
842 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 834 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
843 | "Received request for `%s' of type %u from local client\n", | 835 | "Received request for `%s' of type %u from local client\n", |
844 | GNUNET_h2s (&sm->query), | 836 | GNUNET_h2s(&sm->query), |
845 | (unsigned int) type); | 837 | (unsigned int)type); |
846 | cr = NULL; | 838 | cr = NULL; |
847 | /* detect duplicate UBLOCK requests */ | 839 | /* detect duplicate UBLOCK requests */ |
848 | if ((type == GNUNET_BLOCK_TYPE_FS_UBLOCK) || | 840 | if ((type == GNUNET_BLOCK_TYPE_FS_UBLOCK) || |
849 | (type == GNUNET_BLOCK_TYPE_ANY)) | 841 | (type == GNUNET_BLOCK_TYPE_ANY)) |
850 | { | ||
851 | cr = lc->cr_head; | ||
852 | while (NULL != cr) | ||
853 | { | 842 | { |
854 | prd = GSF_pending_request_get_data_ (cr->pr); | 843 | cr = lc->cr_head; |
855 | /* only unify with queries that hae not yet started local processing | 844 | while (NULL != cr) |
856 | (SEARCH_MESSAGE_OPTION_CONTINUED was always set) and that have a | 845 | { |
857 | matching query and type */ | 846 | prd = GSF_pending_request_get_data_(cr->pr); |
858 | if ((GNUNET_YES != prd->has_started) && | 847 | /* only unify with queries that hae not yet started local processing |
859 | (0 != memcmp (&prd->query, | 848 | (SEARCH_MESSAGE_OPTION_CONTINUED was always set) and that have a |
860 | &sm->query, | 849 | matching query and type */ |
861 | sizeof (struct GNUNET_HashCode))) && | 850 | if ((GNUNET_YES != prd->has_started) && |
862 | (prd->type == type)) | 851 | (0 != memcmp(&prd->query, |
863 | break; | 852 | &sm->query, |
864 | cr = cr->next; | 853 | sizeof(struct GNUNET_HashCode))) && |
854 | (prd->type == type)) | ||
855 | break; | ||
856 | cr = cr->next; | ||
857 | } | ||
865 | } | 858 | } |
866 | } | ||
867 | if (NULL != cr) | 859 | if (NULL != cr) |
868 | { | 860 | { |
869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 861 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
870 | "Have existing request, merging content-seen lists.\n"); | 862 | "Have existing request, merging content-seen lists.\n"); |
871 | GSF_pending_request_update_ (cr->pr, | 863 | GSF_pending_request_update_(cr->pr, |
872 | (const struct GNUNET_HashCode *) &sm[1], | 864 | (const struct GNUNET_HashCode *)&sm[1], |
873 | sc); | 865 | sc); |
874 | GNUNET_STATISTICS_update (GSF_stats, | 866 | GNUNET_STATISTICS_update(GSF_stats, |
875 | gettext_noop ("# client searches updated (merged content seen list)"), | 867 | gettext_noop("# client searches updated (merged content seen list)"), |
876 | 1, | 868 | 1, |
877 | GNUNET_NO); | 869 | GNUNET_NO); |
878 | } | 870 | } |
879 | else | 871 | else |
880 | { | 872 | { |
881 | GNUNET_STATISTICS_update (GSF_stats, | 873 | GNUNET_STATISTICS_update(GSF_stats, |
882 | gettext_noop ("# client searches active"), | 874 | gettext_noop("# client searches active"), |
883 | 1, | 875 | 1, |
884 | GNUNET_NO); | 876 | GNUNET_NO); |
885 | cr = GNUNET_new (struct ClientRequest); | 877 | cr = GNUNET_new(struct ClientRequest); |
886 | cr->lc = lc; | 878 | cr->lc = lc; |
887 | GNUNET_CONTAINER_DLL_insert (lc->cr_head, | 879 | GNUNET_CONTAINER_DLL_insert(lc->cr_head, |
888 | lc->cr_tail, | 880 | lc->cr_tail, |
889 | cr); | 881 | cr); |
890 | options = GSF_PRO_LOCAL_REQUEST; | 882 | options = GSF_PRO_LOCAL_REQUEST; |
891 | if (0 != (SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY & ntohl (sm->options))) | 883 | if (0 != (SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY & ntohl(sm->options))) |
892 | options |= GSF_PRO_LOCAL_ONLY; | 884 | options |= GSF_PRO_LOCAL_ONLY; |
893 | cr->pr = GSF_pending_request_create_ (options, type, | 885 | cr->pr = GSF_pending_request_create_(options, type, |
894 | &sm->query, | 886 | &sm->query, |
895 | (0 != | 887 | (0 != |
896 | memcmp (&sm->target, | 888 | memcmp(&sm->target, |
897 | &all_zeros, | 889 | &all_zeros, |
898 | sizeof (struct GNUNET_PeerIdentity))) | 890 | sizeof(struct GNUNET_PeerIdentity))) |
899 | ? &sm->target : NULL, NULL, 0, | 891 | ? &sm->target : NULL, NULL, 0, |
900 | 0 /* bf */ , | 892 | 0 /* bf */, |
901 | ntohl (sm->anonymity_level), | 893 | ntohl(sm->anonymity_level), |
902 | 0 /* priority */ , | 894 | 0 /* priority */, |
903 | 0 /* ttl */ , | 895 | 0 /* ttl */, |
904 | 0 /* sender PID */ , | 896 | 0 /* sender PID */, |
905 | 0 /* origin PID */ , | 897 | 0 /* origin PID */, |
906 | (const struct GNUNET_HashCode *) &sm[1], sc, | 898 | (const struct GNUNET_HashCode *)&sm[1], sc, |
907 | &client_response_handler, | 899 | &client_response_handler, |
908 | cr); | 900 | cr); |
909 | } | 901 | } |
910 | if (0 != (SEARCH_MESSAGE_OPTION_CONTINUED & ntohl (sm->options))) | 902 | if (0 != (SEARCH_MESSAGE_OPTION_CONTINUED & ntohl(sm->options))) |
911 | { | 903 | { |
912 | GNUNET_SERVICE_client_continue (lc->client); | 904 | GNUNET_SERVICE_client_continue(lc->client); |
913 | return; | 905 | return; |
914 | } | 906 | } |
915 | GSF_pending_request_get_data_ (cr->pr)->has_started = GNUNET_YES; | 907 | GSF_pending_request_get_data_(cr->pr)->has_started = GNUNET_YES; |
916 | GSF_local_lookup_ (cr->pr, | 908 | GSF_local_lookup_(cr->pr, |
917 | &start_p2p_processing, | 909 | &start_p2p_processing, |
918 | lc); | 910 | lc); |
919 | } | 911 | } |
920 | 912 | ||
921 | 913 | ||
@@ -926,8 +918,8 @@ handle_client_start_search (void *cls, | |||
926 | * @param msg the actual message | 918 | * @param msg the actual message |
927 | */ | 919 | */ |
928 | static void | 920 | static void |
929 | handle_client_loc_sign (void *cls, | 921 | handle_client_loc_sign(void *cls, |
930 | const struct RequestLocSignatureMessage *msg) | 922 | const struct RequestLocSignatureMessage *msg) |
931 | { | 923 | { |
932 | struct GSF_LocalClient *lc = cls; | 924 | struct GSF_LocalClient *lc = cls; |
933 | struct GNUNET_FS_Uri base; | 925 | struct GNUNET_FS_Uri base; |
@@ -935,24 +927,24 @@ handle_client_loc_sign (void *cls, | |||
935 | struct GNUNET_MQ_Envelope *env; | 927 | struct GNUNET_MQ_Envelope *env; |
936 | struct ResponseLocSignatureMessage *resp; | 928 | struct ResponseLocSignatureMessage *resp; |
937 | 929 | ||
938 | GNUNET_break (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT == | 930 | GNUNET_break(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT == |
939 | ntohl (msg->purpose)); | 931 | ntohl(msg->purpose)); |
940 | base.type = GNUNET_FS_URI_CHK; | 932 | base.type = GNUNET_FS_URI_CHK; |
941 | base.data.chk.chk = msg->chk; | 933 | base.data.chk.chk = msg->chk; |
942 | base.data.chk.file_length = GNUNET_ntohll (msg->file_length); | 934 | base.data.chk.file_length = GNUNET_ntohll(msg->file_length); |
943 | loc = GNUNET_FS_uri_loc_create (&base, | 935 | loc = GNUNET_FS_uri_loc_create(&base, |
944 | pk, | 936 | pk, |
945 | GNUNET_TIME_absolute_ntoh (msg->expiration_time)); | 937 | GNUNET_TIME_absolute_ntoh(msg->expiration_time)); |
946 | env = GNUNET_MQ_msg (resp, | 938 | env = GNUNET_MQ_msg(resp, |
947 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE); | 939 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE); |
948 | resp->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | 940 | resp->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); |
949 | resp->expiration_time = GNUNET_TIME_absolute_hton (loc->data.loc.expirationTime); | 941 | resp->expiration_time = GNUNET_TIME_absolute_hton(loc->data.loc.expirationTime); |
950 | resp->signature = loc->data.loc.contentSignature; | 942 | resp->signature = loc->data.loc.contentSignature; |
951 | resp->peer = loc->data.loc.peer; | 943 | resp->peer = loc->data.loc.peer; |
952 | GNUNET_FS_uri_destroy (loc); | 944 | GNUNET_FS_uri_destroy(loc); |
953 | GNUNET_MQ_send (lc->mq, | 945 | GNUNET_MQ_send(lc->mq, |
954 | env); | 946 | env); |
955 | GNUNET_SERVICE_client_continue (lc->client); | 947 | GNUNET_SERVICE_client_continue(lc->client); |
956 | } | 948 | } |
957 | 949 | ||
958 | 950 | ||
@@ -964,24 +956,24 @@ handle_client_loc_sign (void *cls, | |||
964 | * @return #GNUNET_OK if @a ism is well-formed | 956 | * @return #GNUNET_OK if @a ism is well-formed |
965 | */ | 957 | */ |
966 | static int | 958 | static int |
967 | check_client_index_start (void *cls, | 959 | check_client_index_start(void *cls, |
968 | const struct IndexStartMessage *ism) | 960 | const struct IndexStartMessage *ism) |
969 | { | 961 | { |
970 | char *fn; | 962 | char *fn; |
971 | 963 | ||
972 | GNUNET_MQ_check_zero_termination (ism); | 964 | GNUNET_MQ_check_zero_termination(ism); |
973 | if (0 != ism->reserved) | 965 | if (0 != ism->reserved) |
974 | { | 966 | { |
975 | GNUNET_break (0); | 967 | GNUNET_break(0); |
976 | return GNUNET_SYSERR; | 968 | return GNUNET_SYSERR; |
977 | } | 969 | } |
978 | fn = GNUNET_STRINGS_filename_expand ((const char *) &ism[1]); | 970 | fn = GNUNET_STRINGS_filename_expand((const char *)&ism[1]); |
979 | if (NULL == fn) | 971 | if (NULL == fn) |
980 | { | 972 | { |
981 | GNUNET_break (0); | 973 | GNUNET_break(0); |
982 | return GNUNET_SYSERR; | 974 | return GNUNET_SYSERR; |
983 | } | 975 | } |
984 | GNUNET_free (fn); | 976 | GNUNET_free(fn); |
985 | return GNUNET_OK; | 977 | return GNUNET_OK; |
986 | } | 978 | } |
987 | 979 | ||
@@ -993,21 +985,21 @@ check_client_index_start (void *cls, | |||
993 | * @param isc the data about the index info entry for the request | 985 | * @param isc the data about the index info entry for the request |
994 | */ | 986 | */ |
995 | static void | 987 | static void |
996 | signal_index_ok (struct IndexStartContext *isc) | 988 | signal_index_ok(struct IndexStartContext *isc) |
997 | { | 989 | { |
998 | struct GSF_LocalClient *lc = isc->lc; | 990 | struct GSF_LocalClient *lc = isc->lc; |
999 | struct GNUNET_MQ_Envelope *env; | 991 | struct GNUNET_MQ_Envelope *env; |
1000 | struct GNUNET_MessageHeader *msg; | 992 | struct GNUNET_MessageHeader *msg; |
1001 | 993 | ||
1002 | GNUNET_FS_add_to_index (isc->filename, | 994 | GNUNET_FS_add_to_index(isc->filename, |
1003 | &isc->file_id); | 995 | &isc->file_id); |
1004 | env = GNUNET_MQ_msg (msg, | 996 | env = GNUNET_MQ_msg(msg, |
1005 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); | 997 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); |
1006 | GNUNET_MQ_send (lc->mq, | 998 | GNUNET_MQ_send(lc->mq, |
1007 | env); | 999 | env); |
1008 | GNUNET_free (isc->filename); | 1000 | GNUNET_free(isc->filename); |
1009 | GNUNET_free (isc); | 1001 | GNUNET_free(isc); |
1010 | GNUNET_SERVICE_client_continue (lc->client); | 1002 | GNUNET_SERVICE_client_continue(lc->client); |
1011 | } | 1003 | } |
1012 | 1004 | ||
1013 | 1005 | ||
@@ -1019,36 +1011,36 @@ signal_index_ok (struct IndexStartContext *isc) | |||
1019 | * @param res resulting hash, NULL on error | 1011 | * @param res resulting hash, NULL on error |
1020 | */ | 1012 | */ |
1021 | static void | 1013 | static void |
1022 | hash_for_index_val (void *cls, | 1014 | hash_for_index_val(void *cls, |
1023 | const struct GNUNET_HashCode *res) | 1015 | const struct GNUNET_HashCode *res) |
1024 | { | 1016 | { |
1025 | struct IndexStartContext *isc = cls; | 1017 | struct IndexStartContext *isc = cls; |
1026 | struct GSF_LocalClient *lc = isc->lc; | 1018 | struct GSF_LocalClient *lc = isc->lc; |
1027 | struct GNUNET_MQ_Envelope *env; | 1019 | struct GNUNET_MQ_Envelope *env; |
1028 | struct GNUNET_MessageHeader *msg; | 1020 | struct GNUNET_MessageHeader *msg; |
1029 | 1021 | ||
1030 | GNUNET_CONTAINER_DLL_remove (lc->isc_head, | 1022 | GNUNET_CONTAINER_DLL_remove(lc->isc_head, |
1031 | lc->isc_tail, | 1023 | lc->isc_tail, |
1032 | isc); | 1024 | isc); |
1033 | isc->fhc = NULL; | 1025 | isc->fhc = NULL; |
1034 | if ( (NULL == res) || | 1026 | if ((NULL == res) || |
1035 | (0 != memcmp (res, | 1027 | (0 != memcmp(res, |
1036 | &isc->file_id, | 1028 | &isc->file_id, |
1037 | sizeof (struct GNUNET_HashCode)))) | 1029 | sizeof(struct GNUNET_HashCode)))) |
1038 | { | 1030 | { |
1039 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1031 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1040 | _("Hash mismatch trying to index file `%s' which does not have hash `%s'\n"), | 1032 | _("Hash mismatch trying to index file `%s' which does not have hash `%s'\n"), |
1041 | isc->filename, | 1033 | isc->filename, |
1042 | GNUNET_h2s (&isc->file_id)); | 1034 | GNUNET_h2s(&isc->file_id)); |
1043 | env = GNUNET_MQ_msg (msg, | 1035 | env = GNUNET_MQ_msg(msg, |
1044 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); | 1036 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); |
1045 | GNUNET_MQ_send (lc->mq, | 1037 | GNUNET_MQ_send(lc->mq, |
1046 | env); | 1038 | env); |
1047 | GNUNET_SERVICE_client_continue (lc->client); | 1039 | GNUNET_SERVICE_client_continue(lc->client); |
1048 | GNUNET_free (isc); | 1040 | GNUNET_free(isc); |
1049 | return; | 1041 | return; |
1050 | } | 1042 | } |
1051 | signal_index_ok (isc); | 1043 | signal_index_ok(isc); |
1052 | } | 1044 | } |
1053 | 1045 | ||
1054 | 1046 | ||
@@ -1059,8 +1051,8 @@ hash_for_index_val (void *cls, | |||
1059 | * @param message the actual message | 1051 | * @param message the actual message |
1060 | */ | 1052 | */ |
1061 | static void | 1053 | static void |
1062 | handle_client_index_start (void *cls, | 1054 | handle_client_index_start(void *cls, |
1063 | const struct IndexStartMessage *ism) | 1055 | const struct IndexStartMessage *ism) |
1064 | { | 1056 | { |
1065 | struct GSF_LocalClient *lc = cls; | 1057 | struct GSF_LocalClient *lc = cls; |
1066 | struct IndexStartContext *isc; | 1058 | struct IndexStartContext *isc; |
@@ -1070,49 +1062,49 @@ handle_client_index_start (void *cls, | |||
1070 | uint64_t mydev; | 1062 | uint64_t mydev; |
1071 | uint64_t myino; | 1063 | uint64_t myino; |
1072 | 1064 | ||
1073 | fn = GNUNET_STRINGS_filename_expand ((const char *) &ism[1]); | 1065 | fn = GNUNET_STRINGS_filename_expand((const char *)&ism[1]); |
1074 | GNUNET_assert (NULL != fn); | 1066 | GNUNET_assert(NULL != fn); |
1075 | dev = GNUNET_ntohll (ism->device); | 1067 | dev = GNUNET_ntohll(ism->device); |
1076 | ino = GNUNET_ntohll (ism->inode); | 1068 | ino = GNUNET_ntohll(ism->inode); |
1077 | isc = GNUNET_new (struct IndexStartContext); | 1069 | isc = GNUNET_new(struct IndexStartContext); |
1078 | isc->filename = fn; | 1070 | isc->filename = fn; |
1079 | isc->file_id = ism->file_id; | 1071 | isc->file_id = ism->file_id; |
1080 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1072 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1081 | "Received START_INDEX message for file `%s'\n", | 1073 | "Received START_INDEX message for file `%s'\n", |
1082 | isc->filename); | 1074 | isc->filename); |
1083 | isc->lc = lc; | 1075 | isc->lc = lc; |
1084 | mydev = 0; | 1076 | mydev = 0; |
1085 | myino = 0; | 1077 | myino = 0; |
1086 | if ( ( (dev != 0) || | 1078 | if (((dev != 0) || |
1087 | (ino != 0) ) && | 1079 | (ino != 0)) && |
1088 | (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn, | 1080 | (GNUNET_OK == GNUNET_DISK_file_get_identifiers(fn, |
1089 | &mydev, | 1081 | &mydev, |
1090 | &myino)) && | 1082 | &myino)) && |
1091 | (dev == mydev) && | 1083 | (dev == mydev) && |
1092 | (ino == myino) ) | 1084 | (ino == myino)) |
1093 | { | 1085 | { |
1094 | /* fast validation OK! */ | 1086 | /* fast validation OK! */ |
1095 | signal_index_ok (isc); | 1087 | signal_index_ok(isc); |
1096 | return; | 1088 | return; |
1097 | } | 1089 | } |
1098 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1090 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1099 | "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n", | 1091 | "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n", |
1100 | (unsigned long long) ino, | 1092 | (unsigned long long)ino, |
1101 | (unsigned long long) myino, | 1093 | (unsigned long long)myino, |
1102 | (unsigned int) dev, | 1094 | (unsigned int)dev, |
1103 | (unsigned int) mydev); | 1095 | (unsigned int)mydev); |
1104 | /* slow validation, need to hash full file (again) */ | 1096 | /* slow validation, need to hash full file (again) */ |
1105 | GNUNET_CONTAINER_DLL_insert (lc->isc_head, | 1097 | GNUNET_CONTAINER_DLL_insert(lc->isc_head, |
1106 | lc->isc_tail, | 1098 | lc->isc_tail, |
1107 | isc); | 1099 | isc); |
1108 | isc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1100 | isc->fhc = GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, |
1109 | isc->filename, | 1101 | isc->filename, |
1110 | HASHING_BLOCKSIZE, | 1102 | HASHING_BLOCKSIZE, |
1111 | &hash_for_index_val, | 1103 | &hash_for_index_val, |
1112 | isc); | 1104 | isc); |
1113 | if (NULL == isc->fhc) | 1105 | if (NULL == isc->fhc) |
1114 | hash_for_index_val (isc, | 1106 | hash_for_index_val(isc, |
1115 | NULL); | 1107 | NULL); |
1116 | } | 1108 | } |
1117 | 1109 | ||
1118 | 1110 | ||
@@ -1123,13 +1115,13 @@ handle_client_index_start (void *cls, | |||
1123 | * @param message the actual message | 1115 | * @param message the actual message |
1124 | */ | 1116 | */ |
1125 | static void | 1117 | static void |
1126 | handle_client_index_list_get (void *cls, | 1118 | handle_client_index_list_get(void *cls, |
1127 | const struct GNUNET_MessageHeader *message) | 1119 | const struct GNUNET_MessageHeader *message) |
1128 | { | 1120 | { |
1129 | struct GSF_LocalClient *lc = cls; | 1121 | struct GSF_LocalClient *lc = cls; |
1130 | 1122 | ||
1131 | GNUNET_FS_indexing_send_list (lc->mq); | 1123 | GNUNET_FS_indexing_send_list(lc->mq); |
1132 | GNUNET_SERVICE_client_continue (lc->client); | 1124 | GNUNET_SERVICE_client_continue(lc->client); |
1133 | } | 1125 | } |
1134 | 1126 | ||
1135 | 1127 | ||
@@ -1140,25 +1132,25 @@ handle_client_index_list_get (void *cls, | |||
1140 | * @param message the actual message | 1132 | * @param message the actual message |
1141 | */ | 1133 | */ |
1142 | static void | 1134 | static void |
1143 | handle_client_unindex (void *cls, | 1135 | handle_client_unindex(void *cls, |
1144 | const struct UnindexMessage *um) | 1136 | const struct UnindexMessage *um) |
1145 | { | 1137 | { |
1146 | struct GSF_LocalClient *lc = cls; | 1138 | struct GSF_LocalClient *lc = cls; |
1147 | struct GNUNET_MQ_Envelope *env; | 1139 | struct GNUNET_MQ_Envelope *env; |
1148 | struct GNUNET_MessageHeader *msg; | 1140 | struct GNUNET_MessageHeader *msg; |
1149 | int found; | 1141 | int found; |
1150 | 1142 | ||
1151 | GNUNET_break (0 == um->reserved); | 1143 | GNUNET_break(0 == um->reserved); |
1152 | found = GNUNET_FS_indexing_do_unindex (&um->file_id); | 1144 | found = GNUNET_FS_indexing_do_unindex(&um->file_id); |
1153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1145 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1154 | "Client requested unindexing of file `%s': %s\n", | 1146 | "Client requested unindexing of file `%s': %s\n", |
1155 | GNUNET_h2s (&um->file_id), | 1147 | GNUNET_h2s(&um->file_id), |
1156 | found ? "found" : "not found"); | 1148 | found ? "found" : "not found"); |
1157 | env = GNUNET_MQ_msg (msg, | 1149 | env = GNUNET_MQ_msg(msg, |
1158 | GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); | 1150 | GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); |
1159 | GNUNET_MQ_send (lc->mq, | 1151 | GNUNET_MQ_send(lc->mq, |
1160 | env); | 1152 | env); |
1161 | GNUNET_SERVICE_client_continue (lc->client); | 1153 | GNUNET_SERVICE_client_continue(lc->client); |
1162 | } | 1154 | } |
1163 | 1155 | ||
1164 | 1156 | ||
@@ -1168,44 +1160,44 @@ handle_client_unindex (void *cls, | |||
1168 | * @param cls unused | 1160 | * @param cls unused |
1169 | */ | 1161 | */ |
1170 | static void | 1162 | static void |
1171 | shutdown_task (void *cls) | 1163 | shutdown_task(void *cls) |
1172 | { | 1164 | { |
1173 | GSF_cadet_stop_server (); | 1165 | GSF_cadet_stop_server(); |
1174 | if (NULL != GSF_core) | 1166 | if (NULL != GSF_core) |
1175 | { | 1167 | { |
1176 | GNUNET_CORE_disconnect (GSF_core); | 1168 | GNUNET_CORE_disconnect(GSF_core); |
1177 | GSF_core = NULL; | 1169 | GSF_core = NULL; |
1178 | } | 1170 | } |
1179 | if (NULL != GSF_ats) | 1171 | if (NULL != GSF_ats) |
1180 | { | 1172 | { |
1181 | GNUNET_ATS_performance_done (GSF_ats); | 1173 | GNUNET_ATS_performance_done(GSF_ats); |
1182 | GSF_ats = NULL; | 1174 | GSF_ats = NULL; |
1183 | } | 1175 | } |
1184 | GSF_put_done_ (); | 1176 | GSF_put_done_(); |
1185 | GSF_push_done_ (); | 1177 | GSF_push_done_(); |
1186 | GSF_pending_request_done_ (); | 1178 | GSF_pending_request_done_(); |
1187 | GSF_plan_done (); | 1179 | GSF_plan_done(); |
1188 | GSF_connected_peer_done_ (); | 1180 | GSF_connected_peer_done_(); |
1189 | GNUNET_DATASTORE_disconnect (GSF_dsh, | 1181 | GNUNET_DATASTORE_disconnect(GSF_dsh, |
1190 | GNUNET_NO); | 1182 | GNUNET_NO); |
1191 | GSF_dsh = NULL; | 1183 | GSF_dsh = NULL; |
1192 | GNUNET_DHT_disconnect (GSF_dht); | 1184 | GNUNET_DHT_disconnect(GSF_dht); |
1193 | GSF_dht = NULL; | 1185 | GSF_dht = NULL; |
1194 | GNUNET_BLOCK_context_destroy (GSF_block_ctx); | 1186 | GNUNET_BLOCK_context_destroy(GSF_block_ctx); |
1195 | GSF_block_ctx = NULL; | 1187 | GSF_block_ctx = NULL; |
1196 | GNUNET_CONFIGURATION_destroy (block_cfg); | 1188 | GNUNET_CONFIGURATION_destroy(block_cfg); |
1197 | block_cfg = NULL; | 1189 | block_cfg = NULL; |
1198 | GNUNET_STATISTICS_destroy (GSF_stats, GNUNET_NO); | 1190 | GNUNET_STATISTICS_destroy(GSF_stats, GNUNET_NO); |
1199 | GSF_stats = NULL; | 1191 | GSF_stats = NULL; |
1200 | if (NULL != cover_age_task) | 1192 | if (NULL != cover_age_task) |
1201 | { | 1193 | { |
1202 | GNUNET_SCHEDULER_cancel (cover_age_task); | 1194 | GNUNET_SCHEDULER_cancel(cover_age_task); |
1203 | cover_age_task = NULL; | 1195 | cover_age_task = NULL; |
1204 | } | 1196 | } |
1205 | GNUNET_FS_indexing_done (); | 1197 | GNUNET_FS_indexing_done(); |
1206 | GNUNET_LOAD_value_free (datastore_get_load); | 1198 | GNUNET_LOAD_value_free(datastore_get_load); |
1207 | datastore_get_load = NULL; | 1199 | datastore_get_load = NULL; |
1208 | GNUNET_LOAD_value_free (GSF_rt_entry_lifetime); | 1200 | GNUNET_LOAD_value_free(GSF_rt_entry_lifetime); |
1209 | GSF_rt_entry_lifetime = NULL; | 1201 | GSF_rt_entry_lifetime = NULL; |
1210 | } | 1202 | } |
1211 | 1203 | ||
@@ -1221,16 +1213,16 @@ shutdown_task (void *cls) | |||
1221 | * @param my_identity ID of this peer, NULL if we failed | 1213 | * @param my_identity ID of this peer, NULL if we failed |
1222 | */ | 1214 | */ |
1223 | static void | 1215 | static void |
1224 | peer_init_handler (void *cls, | 1216 | peer_init_handler(void *cls, |
1225 | const struct GNUNET_PeerIdentity *my_identity) | 1217 | const struct GNUNET_PeerIdentity *my_identity) |
1226 | { | 1218 | { |
1227 | if (0 != GNUNET_memcmp (&GSF_my_id, | 1219 | if (0 != GNUNET_memcmp(&GSF_my_id, |
1228 | my_identity)) | 1220 | my_identity)) |
1229 | { | 1221 | { |
1230 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1222 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1231 | "Peer identity mismatch, refusing to start!\n"); | 1223 | "Peer identity mismatch, refusing to start!\n"); |
1232 | GNUNET_SCHEDULER_shutdown (); | 1224 | GNUNET_SCHEDULER_shutdown(); |
1233 | } | 1225 | } |
1234 | } | 1226 | } |
1235 | 1227 | ||
1236 | 1228 | ||
@@ -1240,25 +1232,25 @@ peer_init_handler (void *cls, | |||
1240 | * @param c configuration to use | 1232 | * @param c configuration to use |
1241 | */ | 1233 | */ |
1242 | static int | 1234 | static int |
1243 | main_init (const struct GNUNET_CONFIGURATION_Handle *c) | 1235 | main_init(const struct GNUNET_CONFIGURATION_Handle *c) |
1244 | { | 1236 | { |
1245 | struct GNUNET_MQ_MessageHandler no_p2p_handlers[] = { | 1237 | struct GNUNET_MQ_MessageHandler no_p2p_handlers[] = { |
1246 | GNUNET_MQ_handler_end () | 1238 | GNUNET_MQ_handler_end() |
1247 | }; | 1239 | }; |
1248 | struct GNUNET_MQ_MessageHandler p2p_handlers[] = { | 1240 | struct GNUNET_MQ_MessageHandler p2p_handlers[] = { |
1249 | GNUNET_MQ_hd_var_size (p2p_get, | 1241 | GNUNET_MQ_hd_var_size(p2p_get, |
1250 | GNUNET_MESSAGE_TYPE_FS_GET, | 1242 | GNUNET_MESSAGE_TYPE_FS_GET, |
1251 | struct GetMessage, | 1243 | struct GetMessage, |
1252 | NULL), | 1244 | NULL), |
1253 | GNUNET_MQ_hd_var_size (p2p_put, | 1245 | GNUNET_MQ_hd_var_size(p2p_put, |
1254 | GNUNET_MESSAGE_TYPE_FS_PUT, | 1246 | GNUNET_MESSAGE_TYPE_FS_PUT, |
1255 | struct PutMessage, | 1247 | struct PutMessage, |
1256 | NULL), | 1248 | NULL), |
1257 | GNUNET_MQ_hd_fixed_size (p2p_migration_stop, | 1249 | GNUNET_MQ_hd_fixed_size(p2p_migration_stop, |
1258 | GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP, | 1250 | GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP, |
1259 | struct MigrationStopMessage, | 1251 | struct MigrationStopMessage, |
1260 | NULL), | 1252 | NULL), |
1261 | GNUNET_MQ_handler_end () | 1253 | GNUNET_MQ_handler_end() |
1262 | }; | 1254 | }; |
1263 | int anon_p2p_off; | 1255 | int anon_p2p_off; |
1264 | char *keyfile; | 1256 | char *keyfile; |
@@ -1266,54 +1258,54 @@ main_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
1266 | /* this option is really only for testcases that need to disable | 1258 | /* this option is really only for testcases that need to disable |
1267 | _anonymous_ file-sharing for some reason */ | 1259 | _anonymous_ file-sharing for some reason */ |
1268 | anon_p2p_off = (GNUNET_YES == | 1260 | anon_p2p_off = (GNUNET_YES == |
1269 | GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, | 1261 | GNUNET_CONFIGURATION_get_value_yesno(GSF_cfg, |
1270 | "fs", | 1262 | "fs", |
1271 | "DISABLE_ANON_TRANSFER")); | 1263 | "DISABLE_ANON_TRANSFER")); |
1272 | 1264 | ||
1273 | if (GNUNET_OK != | 1265 | if (GNUNET_OK != |
1274 | GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, | 1266 | GNUNET_CONFIGURATION_get_value_filename(GSF_cfg, |
1275 | "PEER", | 1267 | "PEER", |
1276 | "PRIVATE_KEY", | 1268 | "PRIVATE_KEY", |
1277 | &keyfile)) | 1269 | &keyfile)) |
1278 | { | 1270 | { |
1279 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1271 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1280 | _("FS service is lacking HOSTKEY configuration setting. Exiting.\n")); | 1272 | _("FS service is lacking HOSTKEY configuration setting. Exiting.\n")); |
1281 | GNUNET_SCHEDULER_shutdown (); | 1273 | GNUNET_SCHEDULER_shutdown(); |
1282 | return GNUNET_SYSERR; | 1274 | return GNUNET_SYSERR; |
1283 | } | 1275 | } |
1284 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); | 1276 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile); |
1285 | GNUNET_free (keyfile); | 1277 | GNUNET_free(keyfile); |
1286 | GNUNET_assert (NULL != pk); | 1278 | GNUNET_assert(NULL != pk); |
1287 | GNUNET_CRYPTO_eddsa_key_get_public (pk, | 1279 | GNUNET_CRYPTO_eddsa_key_get_public(pk, |
1288 | &GSF_my_id.public_key); | 1280 | &GSF_my_id.public_key); |
1289 | 1281 | ||
1290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1282 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1291 | "I am peer %s\n", | 1283 | "I am peer %s\n", |
1292 | GNUNET_i2s (&GSF_my_id)); | 1284 | GNUNET_i2s(&GSF_my_id)); |
1293 | GSF_core | 1285 | GSF_core |
1294 | = GNUNET_CORE_connect (GSF_cfg, | 1286 | = GNUNET_CORE_connect(GSF_cfg, |
1295 | NULL, | 1287 | NULL, |
1296 | &peer_init_handler, | 1288 | &peer_init_handler, |
1297 | &GSF_peer_connect_handler, | 1289 | &GSF_peer_connect_handler, |
1298 | &GSF_peer_disconnect_handler, | 1290 | &GSF_peer_disconnect_handler, |
1299 | (GNUNET_YES == anon_p2p_off) | 1291 | (GNUNET_YES == anon_p2p_off) |
1300 | ? no_p2p_handlers | 1292 | ? no_p2p_handlers |
1301 | : p2p_handlers); | 1293 | : p2p_handlers); |
1302 | if (NULL == GSF_core) | 1294 | if (NULL == GSF_core) |
1303 | { | 1295 | { |
1304 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1296 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1305 | _("Failed to connect to `%s' service.\n"), | 1297 | _("Failed to connect to `%s' service.\n"), |
1306 | "core"); | 1298 | "core"); |
1307 | return GNUNET_SYSERR; | 1299 | return GNUNET_SYSERR; |
1308 | } | 1300 | } |
1309 | cover_age_task = | 1301 | cover_age_task = |
1310 | GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, | 1302 | GNUNET_SCHEDULER_add_delayed(COVER_AGE_FREQUENCY, |
1311 | &age_cover_counters, | 1303 | &age_cover_counters, |
1312 | NULL); | 1304 | NULL); |
1313 | datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); | 1305 | datastore_get_load = GNUNET_LOAD_value_init(DATASTORE_LOAD_AUTODECLINE); |
1314 | GSF_cadet_start_server (); | 1306 | GSF_cadet_start_server(); |
1315 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 1307 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, |
1316 | NULL); | 1308 | NULL); |
1317 | return GNUNET_OK; | 1309 | return GNUNET_OK; |
1318 | } | 1310 | } |
1319 | 1311 | ||
@@ -1326,55 +1318,55 @@ main_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
1326 | * @param service the initialized service | 1318 | * @param service the initialized service |
1327 | */ | 1319 | */ |
1328 | static void | 1320 | static void |
1329 | run (void *cls, | 1321 | run(void *cls, |
1330 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1322 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1331 | struct GNUNET_SERVICE_Handle *service) | 1323 | struct GNUNET_SERVICE_Handle *service) |
1332 | { | 1324 | { |
1333 | unsigned long long dqs; | 1325 | unsigned long long dqs; |
1334 | 1326 | ||
1335 | GSF_cfg = cfg; | 1327 | GSF_cfg = cfg; |
1336 | if (GNUNET_OK != | 1328 | if (GNUNET_OK != |
1337 | GNUNET_CONFIGURATION_get_value_size (GSF_cfg, | 1329 | GNUNET_CONFIGURATION_get_value_size(GSF_cfg, |
1338 | "fs", | 1330 | "fs", |
1339 | "DATASTORE_QUEUE_SIZE", | 1331 | "DATASTORE_QUEUE_SIZE", |
1340 | &dqs)) | 1332 | &dqs)) |
1341 | { | 1333 | { |
1342 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO, | 1334 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_INFO, |
1343 | "fs", | 1335 | "fs", |
1344 | "DATASTORE_QUEUE_SIZE"); | 1336 | "DATASTORE_QUEUE_SIZE"); |
1345 | dqs = 32; | 1337 | dqs = 32; |
1346 | } | 1338 | } |
1347 | GSF_datastore_queue_size = (unsigned int) dqs; | 1339 | GSF_datastore_queue_size = (unsigned int)dqs; |
1348 | GSF_enable_randomized_delays = | 1340 | GSF_enable_randomized_delays = |
1349 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "fs", "DELAY"); | 1341 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "fs", "DELAY"); |
1350 | GSF_dsh = GNUNET_DATASTORE_connect (cfg); | 1342 | GSF_dsh = GNUNET_DATASTORE_connect(cfg); |
1351 | if (NULL == GSF_dsh) | 1343 | if (NULL == GSF_dsh) |
1352 | { | 1344 | { |
1353 | GNUNET_SCHEDULER_shutdown (); | 1345 | GNUNET_SCHEDULER_shutdown(); |
1354 | return; | 1346 | return; |
1355 | } | 1347 | } |
1356 | GSF_rt_entry_lifetime = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_FOREVER_REL); | 1348 | GSF_rt_entry_lifetime = GNUNET_LOAD_value_init(GNUNET_TIME_UNIT_FOREVER_REL); |
1357 | GSF_stats = GNUNET_STATISTICS_create ("fs", cfg); | 1349 | GSF_stats = GNUNET_STATISTICS_create("fs", cfg); |
1358 | block_cfg = GNUNET_CONFIGURATION_create (); | 1350 | block_cfg = GNUNET_CONFIGURATION_create(); |
1359 | GSF_block_ctx = GNUNET_BLOCK_context_create (block_cfg); | 1351 | GSF_block_ctx = GNUNET_BLOCK_context_create(block_cfg); |
1360 | GNUNET_assert (NULL != GSF_block_ctx); | 1352 | GNUNET_assert(NULL != GSF_block_ctx); |
1361 | GSF_dht = GNUNET_DHT_connect (cfg, FS_DHT_HT_SIZE); | 1353 | GSF_dht = GNUNET_DHT_connect(cfg, FS_DHT_HT_SIZE); |
1362 | GSF_plan_init (); | 1354 | GSF_plan_init(); |
1363 | GSF_pending_request_init_ (); | 1355 | GSF_pending_request_init_(); |
1364 | GSF_connected_peer_init_ (); | 1356 | GSF_connected_peer_init_(); |
1365 | GSF_ats = GNUNET_ATS_performance_init (GSF_cfg, | 1357 | GSF_ats = GNUNET_ATS_performance_init(GSF_cfg, |
1366 | &update_latencies, | 1358 | &update_latencies, |
1367 | NULL); | 1359 | NULL); |
1368 | GSF_push_init_ (); | 1360 | GSF_push_init_(); |
1369 | GSF_put_init_ (); | 1361 | GSF_put_init_(); |
1370 | if ( (GNUNET_OK != GNUNET_FS_indexing_init (cfg, | 1362 | if ((GNUNET_OK != GNUNET_FS_indexing_init(cfg, |
1371 | GSF_dsh)) || | 1363 | GSF_dsh)) || |
1372 | (GNUNET_OK != main_init (cfg)) ) | 1364 | (GNUNET_OK != main_init(cfg))) |
1373 | { | 1365 | { |
1374 | GNUNET_SCHEDULER_shutdown (); | 1366 | GNUNET_SCHEDULER_shutdown(); |
1375 | shutdown_task (NULL); | 1367 | shutdown_task(NULL); |
1376 | return; | 1368 | return; |
1377 | } | 1369 | } |
1378 | } | 1370 | } |
1379 | 1371 | ||
1380 | 1372 | ||
@@ -1382,33 +1374,33 @@ run (void *cls, | |||
1382 | * Define "main" method using service macro. | 1374 | * Define "main" method using service macro. |
1383 | */ | 1375 | */ |
1384 | GNUNET_SERVICE_MAIN | 1376 | GNUNET_SERVICE_MAIN |
1385 | ("fs", | 1377 | ("fs", |
1386 | GNUNET_SERVICE_OPTION_NONE, | 1378 | GNUNET_SERVICE_OPTION_NONE, |
1387 | &run, | 1379 | &run, |
1388 | &client_connect_cb, | 1380 | &client_connect_cb, |
1389 | &client_disconnect_cb, | 1381 | &client_disconnect_cb, |
1390 | NULL, | 1382 | NULL, |
1391 | GNUNET_MQ_hd_var_size (client_index_start, | 1383 | GNUNET_MQ_hd_var_size(client_index_start, |
1392 | GNUNET_MESSAGE_TYPE_FS_INDEX_START, | 1384 | GNUNET_MESSAGE_TYPE_FS_INDEX_START, |
1393 | struct IndexStartMessage, | 1385 | struct IndexStartMessage, |
1394 | NULL), | 1386 | NULL), |
1395 | GNUNET_MQ_hd_fixed_size (client_index_list_get, | 1387 | GNUNET_MQ_hd_fixed_size(client_index_list_get, |
1396 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, | 1388 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, |
1397 | struct GNUNET_MessageHeader, | 1389 | struct GNUNET_MessageHeader, |
1398 | NULL), | 1390 | NULL), |
1399 | GNUNET_MQ_hd_fixed_size (client_unindex, | 1391 | GNUNET_MQ_hd_fixed_size(client_unindex, |
1400 | GNUNET_MESSAGE_TYPE_FS_UNINDEX, | 1392 | GNUNET_MESSAGE_TYPE_FS_UNINDEX, |
1401 | struct UnindexMessage, | 1393 | struct UnindexMessage, |
1402 | NULL), | 1394 | NULL), |
1403 | GNUNET_MQ_hd_var_size (client_start_search, | 1395 | GNUNET_MQ_hd_var_size(client_start_search, |
1404 | GNUNET_MESSAGE_TYPE_FS_START_SEARCH, | 1396 | GNUNET_MESSAGE_TYPE_FS_START_SEARCH, |
1405 | struct SearchMessage, | 1397 | struct SearchMessage, |
1406 | NULL), | 1398 | NULL), |
1407 | GNUNET_MQ_hd_fixed_size (client_loc_sign, | 1399 | GNUNET_MQ_hd_fixed_size(client_loc_sign, |
1408 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN, | 1400 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN, |
1409 | struct RequestLocSignatureMessage, | 1401 | struct RequestLocSignatureMessage, |
1410 | NULL), | 1402 | NULL), |
1411 | GNUNET_MQ_handler_end ()); | 1403 | GNUNET_MQ_handler_end()); |
1412 | 1404 | ||
1413 | 1405 | ||
1414 | /* end of gnunet-service-fs.c */ | 1406 | /* end of gnunet-service-fs.c */ |
diff --git a/src/fs/gnunet-service-fs.h b/src/fs/gnunet-service-fs.h index 661126f08..21a822c6d 100644 --- a/src/fs/gnunet-service-fs.h +++ b/src/fs/gnunet-service-fs.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs.h | 22 | * @file fs/gnunet-service-fs.h |
@@ -48,7 +48,7 @@ | |||
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(GNUNET_TIME_UNIT_MILLISECONDS, 250) |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Only the (mandatory) query is included. | 54 | * Only the (mandatory) query is included. |
@@ -79,9 +79,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
79 | /** | 79 | /** |
80 | * Message sent between peers asking for FS-content. | 80 | * Message sent between peers asking for FS-content. |
81 | */ | 81 | */ |
82 | struct GetMessage | 82 | struct GetMessage { |
83 | { | ||
84 | |||
85 | /** | 83 | /** |
86 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_GET. | 84 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_GET. |
87 | */ | 85 | */ |
@@ -136,8 +134,7 @@ struct GetMessage | |||
136 | * Message send by a peer that wants to be excluded | 134 | * Message send by a peer that wants to be excluded |
137 | * from migration for a while. | 135 | * from migration for a while. |
138 | */ | 136 | */ |
139 | struct MigrationStopMessage | 137 | struct MigrationStopMessage { |
140 | { | ||
141 | /** | 138 | /** |
142 | * Message type will be | 139 | * Message type will be |
143 | * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP. | 140 | * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP. |
@@ -153,7 +150,6 @@ struct MigrationStopMessage | |||
153 | * How long should the block last? | 150 | * How long should the block last? |
154 | */ | 151 | */ |
155 | struct GNUNET_TIME_RelativeNBO duration; | 152 | struct GNUNET_TIME_RelativeNBO duration; |
156 | |||
157 | }; | 153 | }; |
158 | GNUNET_NETWORK_STRUCT_END | 154 | GNUNET_NETWORK_STRUCT_END |
159 | 155 | ||
@@ -279,9 +275,9 @@ extern unsigned int GSF_datastore_queue_size; | |||
279 | * @param result final datastore lookup result | 275 | * @param result final datastore lookup result |
280 | */ | 276 | */ |
281 | void | 277 | void |
282 | GSF_consider_forwarding (void *cls, | 278 | GSF_consider_forwarding(void *cls, |
283 | struct GSF_PendingRequest *pr, | 279 | struct GSF_PendingRequest *pr, |
284 | enum GNUNET_BLOCK_EvaluationResult result); | 280 | enum GNUNET_BLOCK_EvaluationResult result); |
285 | 281 | ||
286 | 282 | ||
287 | /** | 283 | /** |
@@ -294,7 +290,7 @@ GSF_consider_forwarding (void *cls, | |||
294 | * #GNUNET_SYSERR to process for free (load low) | 290 | * #GNUNET_SYSERR to process for free (load low) |
295 | */ | 291 | */ |
296 | int | 292 | int |
297 | GSF_test_get_load_too_high_ (uint32_t priority); | 293 | GSF_test_get_load_too_high_(uint32_t priority); |
298 | 294 | ||
299 | 295 | ||
300 | /** | 296 | /** |
@@ -304,7 +300,7 @@ GSF_test_get_load_too_high_ (uint32_t priority); | |||
304 | * @param start time when the datastore request was issued | 300 | * @param start time when the datastore request was issued |
305 | */ | 301 | */ |
306 | void | 302 | void |
307 | GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start); | 303 | GSF_update_datastore_delay_(struct GNUNET_TIME_Absolute start); |
308 | 304 | ||
309 | 305 | ||
310 | #endif | 306 | #endif |
diff --git a/src/fs/gnunet-service-fs_cadet.h b/src/fs/gnunet-service-fs_cadet.h index 728faaf27..61bd8b314 100644 --- a/src/fs/gnunet-service-fs_cadet.h +++ b/src/fs/gnunet-service-fs_cadet.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_cadet.h | 22 | * @file 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,9 +120,7 @@ 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 | { | ||
125 | |||
126 | /** | 124 | /** |
127 | * Type is GNUNET_MESSAGE_TYPE_FS_CADET_QUERY. | 125 | * Type is GNUNET_MESSAGE_TYPE_FS_CADET_QUERY. |
128 | */ | 126 | */ |
@@ -137,16 +135,13 @@ struct CadetQueryMessage | |||
137 | * Query hash from CHK (hash of encrypted block). | 135 | * Query hash from CHK (hash of encrypted block). |
138 | */ | 136 | */ |
139 | struct GNUNET_HashCode query; | 137 | struct GNUNET_HashCode query; |
140 | |||
141 | }; | 138 | }; |
142 | 139 | ||
143 | 140 | ||
144 | /** | 141 | /** |
145 | * Reply to a CadetQueryMessage. | 142 | * Reply to a CadetQueryMessage. |
146 | */ | 143 | */ |
147 | struct CadetReplyMessage | 144 | struct CadetReplyMessage { |
148 | { | ||
149 | |||
150 | /** | 145 | /** |
151 | * Type is GNUNET_MESSAGE_TYPE_FS_CADET_REPLY. | 146 | * Type is GNUNET_MESSAGE_TYPE_FS_CADET_REPLY. |
152 | */ | 147 | */ |
@@ -163,7 +158,6 @@ struct CadetReplyMessage | |||
163 | struct GNUNET_TIME_AbsoluteNBO expiration; | 158 | struct GNUNET_TIME_AbsoluteNBO expiration; |
164 | 159 | ||
165 | /* followed by the encrypted block */ | 160 | /* followed by the encrypted block */ |
166 | |||
167 | }; | 161 | }; |
168 | 162 | ||
169 | GNUNET_NETWORK_STRUCT_END | 163 | GNUNET_NETWORK_STRUCT_END |
diff --git a/src/fs/gnunet-service-fs_cadet_client.c b/src/fs/gnunet-service-fs_cadet_client.c index 81afe0411..a494ba751 100644 --- a/src/fs/gnunet-service-fs_cadet_client.c +++ b/src/fs/gnunet-service-fs_cadet_client.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_cadet_client.c | 22 | * @file 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,9 +54,7 @@ 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 | { | ||
59 | |||
60 | /** | 58 | /** |
61 | * DLL. | 59 | * DLL. |
62 | */ | 60 | */ |
@@ -103,8 +101,7 @@ struct GSF_CadetRequest | |||
103 | /** | 101 | /** |
104 | * Handle for a cadet to another peer. | 102 | * Handle for a cadet to another peer. |
105 | */ | 103 | */ |
106 | struct CadetHandle | 104 | struct CadetHandle { |
107 | { | ||
108 | /** | 105 | /** |
109 | * Head of DLL of pending requests on this cadet. | 106 | * Head of DLL of pending requests on this cadet. |
110 | */ | 107 | */ |
@@ -168,7 +165,7 @@ struct GNUNET_CONTAINER_MultiPeerMap *cadet_map; | |||
168 | * @param cls `struct CadetHandle` to process | 165 | * @param cls `struct CadetHandle` to process |
169 | */ | 166 | */ |
170 | static void | 167 | static void |
171 | transmit_pending (void *cls); | 168 | transmit_pending(void *cls); |
172 | 169 | ||
173 | 170 | ||
174 | /** | 171 | /** |
@@ -181,15 +178,15 @@ transmit_pending (void *cls); | |||
181 | * @return #GNUNET_YES (continue to iterate) | 178 | * @return #GNUNET_YES (continue to iterate) |
182 | */ | 179 | */ |
183 | static int | 180 | static int |
184 | move_to_pending (void *cls, const struct GNUNET_HashCode *key, void *value) | 181 | move_to_pending(void *cls, const struct GNUNET_HashCode *key, void *value) |
185 | { | 182 | { |
186 | struct CadetHandle *mh = cls; | 183 | struct CadetHandle *mh = cls; |
187 | struct GSF_CadetRequest *sr = value; | 184 | struct GSF_CadetRequest *sr = value; |
188 | 185 | ||
189 | GNUNET_assert ( | 186 | GNUNET_assert( |
190 | GNUNET_YES == | 187 | GNUNET_YES == |
191 | GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, key, value)); | 188 | GNUNET_CONTAINER_multihashmap_remove(mh->waiting_map, key, value)); |
192 | GNUNET_CONTAINER_DLL_insert (mh->pending_head, mh->pending_tail, sr); | 189 | GNUNET_CONTAINER_DLL_insert(mh->pending_head, mh->pending_tail, sr); |
193 | sr->was_transmitted = GNUNET_NO; | 190 | sr->was_transmitted = GNUNET_NO; |
194 | return GNUNET_YES; | 191 | return GNUNET_YES; |
195 | } | 192 | } |
@@ -204,7 +201,7 @@ move_to_pending (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
204 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing | 201 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing |
205 | */ | 202 | */ |
206 | static int | 203 | static int |
207 | check_reply (void *cls, const struct CadetReplyMessage *srm) | 204 | check_reply(void *cls, const struct CadetReplyMessage *srm) |
208 | { | 205 | { |
209 | /* We check later... */ | 206 | /* We check later... */ |
210 | return GNUNET_OK; | 207 | return GNUNET_OK; |
@@ -217,7 +214,7 @@ check_reply (void *cls, const struct CadetReplyMessage *srm) | |||
217 | * @param cls the `struct CadetHandle` to tear down | 214 | * @param cls the `struct CadetHandle` to tear down |
218 | */ | 215 | */ |
219 | static void | 216 | static void |
220 | reset_cadet_task (void *cls); | 217 | reset_cadet_task(void *cls); |
221 | 218 | ||
222 | 219 | ||
223 | /** | 220 | /** |
@@ -227,20 +224,18 @@ reset_cadet_task (void *cls); | |||
227 | * @param mh cadet to reset | 224 | * @param mh cadet to reset |
228 | */ | 225 | */ |
229 | static void | 226 | static void |
230 | reset_cadet_async (struct CadetHandle *mh) | 227 | reset_cadet_async(struct CadetHandle *mh) |
231 | { | 228 | { |
232 | if (NULL != mh->reset_task) | 229 | if (NULL != mh->reset_task) |
233 | GNUNET_SCHEDULER_cancel (mh->reset_task); | 230 | GNUNET_SCHEDULER_cancel(mh->reset_task); |
234 | mh->reset_task = GNUNET_SCHEDULER_add_now (&reset_cadet_task, mh); | 231 | mh->reset_task = GNUNET_SCHEDULER_add_now(&reset_cadet_task, mh); |
235 | } | 232 | } |
236 | 233 | ||
237 | 234 | ||
238 | /** | 235 | /** |
239 | * Closure for handle_reply(). | 236 | * Closure for handle_reply(). |
240 | */ | 237 | */ |
241 | struct HandleReplyClosure | 238 | struct HandleReplyClosure { |
242 | { | ||
243 | |||
244 | /** | 239 | /** |
245 | * Reply payload. | 240 | * Reply payload. |
246 | */ | 241 | */ |
@@ -278,18 +273,18 @@ struct HandleReplyClosure | |||
278 | * @return #GNUNET_YES (continue to iterate) | 273 | * @return #GNUNET_YES (continue to iterate) |
279 | */ | 274 | */ |
280 | static int | 275 | static int |
281 | process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) | 276 | process_reply(void *cls, const struct GNUNET_HashCode *key, void *value) |
282 | { | 277 | { |
283 | struct HandleReplyClosure *hrc = cls; | 278 | struct HandleReplyClosure *hrc = cls; |
284 | struct GSF_CadetRequest *sr = value; | 279 | struct GSF_CadetRequest *sr = value; |
285 | 280 | ||
286 | sr->proc (sr->proc_cls, | 281 | sr->proc(sr->proc_cls, |
287 | hrc->type, | 282 | hrc->type, |
288 | hrc->expiration, | 283 | hrc->expiration, |
289 | hrc->data_size, | 284 | hrc->data_size, |
290 | hrc->data); | 285 | hrc->data); |
291 | sr->proc = NULL; | 286 | sr->proc = NULL; |
292 | GSF_cadet_query_cancel (sr); | 287 | GSF_cadet_query_cancel(sr); |
293 | hrc->found = GNUNET_YES; | 288 | hrc->found = GNUNET_YES; |
294 | return GNUNET_YES; | 289 | return GNUNET_YES; |
295 | } | 290 | } |
@@ -306,11 +301,11 @@ process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
306 | * @return #GNUNET_YES (continue to iterate) | 301 | * @return #GNUNET_YES (continue to iterate) |
307 | */ | 302 | */ |
308 | static int | 303 | static int |
309 | free_waiting_entry (void *cls, const struct GNUNET_HashCode *key, void *value) | 304 | free_waiting_entry(void *cls, const struct GNUNET_HashCode *key, void *value) |
310 | { | 305 | { |
311 | struct GSF_CadetRequest *sr = value; | 306 | struct GSF_CadetRequest *sr = value; |
312 | 307 | ||
313 | GSF_cadet_query_cancel (sr); | 308 | GSF_cadet_query_cancel(sr); |
314 | return GNUNET_YES; | 309 | return GNUNET_YES; |
315 | } | 310 | } |
316 | 311 | ||
@@ -323,7 +318,7 @@ free_waiting_entry (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
323 | * @param srm the actual message | 318 | * @param srm the actual message |
324 | */ | 319 | */ |
325 | static void | 320 | static void |
326 | handle_reply (void *cls, const struct CadetReplyMessage *srm) | 321 | handle_reply(void *cls, const struct CadetReplyMessage *srm) |
327 | { | 322 | { |
328 | struct CadetHandle *mh = cls; | 323 | struct CadetHandle *mh = cls; |
329 | struct HandleReplyClosure hrc; | 324 | struct HandleReplyClosure hrc; |
@@ -331,47 +326,47 @@ handle_reply (void *cls, const struct CadetReplyMessage *srm) | |||
331 | enum GNUNET_BLOCK_Type type; | 326 | enum GNUNET_BLOCK_Type type; |
332 | struct GNUNET_HashCode query; | 327 | struct GNUNET_HashCode query; |
333 | 328 | ||
334 | msize = ntohs (srm->header.size) - sizeof (struct CadetReplyMessage); | 329 | msize = ntohs(srm->header.size) - sizeof(struct CadetReplyMessage); |
335 | type = (enum GNUNET_BLOCK_Type) ntohl (srm->type); | 330 | type = (enum GNUNET_BLOCK_Type)ntohl(srm->type); |
336 | if (GNUNET_YES != | 331 | if (GNUNET_YES != |
337 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, &srm[1], msize, &query)) | 332 | GNUNET_BLOCK_get_key(GSF_block_ctx, type, &srm[1], msize, &query)) |
338 | { | 333 | { |
339 | GNUNET_break_op (0); | 334 | GNUNET_break_op(0); |
340 | GNUNET_log ( | 335 | GNUNET_log( |
341 | GNUNET_ERROR_TYPE_WARNING, | 336 | GNUNET_ERROR_TYPE_WARNING, |
342 | "Received bogus reply of type %u with %u bytes via cadet from peer %s\n", | 337 | "Received bogus reply of type %u with %u bytes via cadet from peer %s\n", |
343 | type, | 338 | type, |
344 | msize, | 339 | msize, |
345 | GNUNET_i2s (&mh->target)); | 340 | GNUNET_i2s(&mh->target)); |
346 | reset_cadet_async (mh); | 341 | reset_cadet_async(mh); |
347 | return; | 342 | return; |
348 | } | 343 | } |
349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 344 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
350 | "Received reply `%s' via cadet from peer %s\n", | 345 | "Received reply `%s' via cadet from peer %s\n", |
351 | GNUNET_h2s (&query), | 346 | GNUNET_h2s(&query), |
352 | GNUNET_i2s (&mh->target)); | 347 | GNUNET_i2s(&mh->target)); |
353 | GNUNET_CADET_receive_done (mh->channel); | 348 | GNUNET_CADET_receive_done(mh->channel); |
354 | GNUNET_STATISTICS_update (GSF_stats, | 349 | GNUNET_STATISTICS_update(GSF_stats, |
355 | gettext_noop ("# replies received via cadet"), | 350 | gettext_noop("# replies received via cadet"), |
356 | 1, | 351 | 1, |
357 | GNUNET_NO); | 352 | GNUNET_NO); |
358 | hrc.data = &srm[1]; | 353 | hrc.data = &srm[1]; |
359 | hrc.data_size = msize; | 354 | hrc.data_size = msize; |
360 | hrc.expiration = GNUNET_TIME_absolute_ntoh (srm->expiration); | 355 | hrc.expiration = GNUNET_TIME_absolute_ntoh(srm->expiration); |
361 | hrc.type = type; | 356 | hrc.type = type; |
362 | hrc.found = GNUNET_NO; | 357 | hrc.found = GNUNET_NO; |
363 | GNUNET_CONTAINER_multihashmap_get_multiple (mh->waiting_map, | 358 | GNUNET_CONTAINER_multihashmap_get_multiple(mh->waiting_map, |
364 | &query, | 359 | &query, |
365 | &process_reply, | 360 | &process_reply, |
366 | &hrc); | 361 | &hrc); |
367 | if (GNUNET_NO == hrc.found) | 362 | if (GNUNET_NO == hrc.found) |
368 | { | 363 | { |
369 | GNUNET_STATISTICS_update (GSF_stats, | 364 | GNUNET_STATISTICS_update(GSF_stats, |
370 | gettext_noop ( | 365 | gettext_noop( |
371 | "# replies received via cadet dropped"), | 366 | "# replies received via cadet dropped"), |
372 | 1, | 367 | 1, |
373 | GNUNET_NO); | 368 | GNUNET_NO); |
374 | } | 369 | } |
375 | } | 370 | } |
376 | 371 | ||
377 | 372 | ||
@@ -383,34 +378,34 @@ handle_reply (void *cls, const struct CadetReplyMessage *srm) | |||
383 | * @param channel channel of the disconnecting client | 378 | * @param channel channel of the disconnecting client |
384 | */ | 379 | */ |
385 | static void | 380 | static void |
386 | disconnect_cb (void *cls, const struct GNUNET_CADET_Channel *channel) | 381 | disconnect_cb(void *cls, const struct GNUNET_CADET_Channel *channel) |
387 | { | 382 | { |
388 | struct CadetHandle *mh = cls; | 383 | struct CadetHandle *mh = cls; |
389 | struct GSF_CadetRequest *sr; | 384 | struct GSF_CadetRequest *sr; |
390 | 385 | ||
391 | if (NULL == mh->channel) | 386 | if (NULL == mh->channel) |
392 | return; /* being destroyed elsewhere */ | 387 | return; /* being destroyed elsewhere */ |
393 | GNUNET_assert (channel == mh->channel); | 388 | GNUNET_assert(channel == mh->channel); |
394 | mh->channel = NULL; | 389 | mh->channel = NULL; |
395 | while (NULL != (sr = mh->pending_head)) | 390 | while (NULL != (sr = mh->pending_head)) |
396 | GSF_cadet_query_cancel (sr); | 391 | GSF_cadet_query_cancel(sr); |
397 | /* first remove `mh` from the `cadet_map`, so that if the | 392 | /* first remove `mh` from the `cadet_map`, so that if the |
398 | callback from `free_waiting_entry()` happens to re-issue | 393 | callback from `free_waiting_entry()` happens to re-issue |
399 | the request, we don't immediately have it back in the | 394 | the request, we don't immediately have it back in the |
400 | `waiting_map`. */ | 395 | `waiting_map`. */ |
401 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (cadet_map, | 396 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove(cadet_map, |
402 | &mh->target, | 397 | &mh->target, |
403 | mh)); | 398 | mh)); |
404 | GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map, | 399 | GNUNET_CONTAINER_multihashmap_iterate(mh->waiting_map, |
405 | &free_waiting_entry, | 400 | &free_waiting_entry, |
406 | mh); | 401 | mh); |
407 | if (NULL != mh->timeout_task) | 402 | if (NULL != mh->timeout_task) |
408 | GNUNET_SCHEDULER_cancel (mh->timeout_task); | 403 | GNUNET_SCHEDULER_cancel(mh->timeout_task); |
409 | if (NULL != mh->reset_task) | 404 | if (NULL != mh->reset_task) |
410 | GNUNET_SCHEDULER_cancel (mh->reset_task); | 405 | GNUNET_SCHEDULER_cancel(mh->reset_task); |
411 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)); | 406 | GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap_size(mh->waiting_map)); |
412 | GNUNET_CONTAINER_multihashmap_destroy (mh->waiting_map); | 407 | GNUNET_CONTAINER_multihashmap_destroy(mh->waiting_map); |
413 | GNUNET_free (mh); | 408 | GNUNET_free(mh); |
414 | } | 409 | } |
415 | 410 | ||
416 | 411 | ||
@@ -429,16 +424,16 @@ disconnect_cb (void *cls, const struct GNUNET_CADET_Channel *channel) | |||
429 | * this value will be negative.. | 424 | * this value will be negative.. |
430 | */ | 425 | */ |
431 | static void | 426 | static void |
432 | window_change_cb (void *cls, | 427 | window_change_cb(void *cls, |
433 | const struct GNUNET_CADET_Channel *channel, | 428 | const struct GNUNET_CADET_Channel *channel, |
434 | int window_size) | 429 | int window_size) |
435 | { | 430 | { |
436 | /* FIXME: for flow control, implement? */ | 431 | /* FIXME: for flow control, implement? */ |
437 | #if 0 | 432 | #if 0 |
438 | /* Something like this instead of the GNUNET_MQ_notify_sent() in | 433 | /* Something like this instead of the GNUNET_MQ_notify_sent() in |
439 | transmit_pending() might be good (once the window change CB works...) */ | 434 | transmit_pending() might be good (once the window change CB works...) */ |
440 | if (0 < window_size) /* test needed? */ | 435 | if (0 < window_size) /* test needed? */ |
441 | transmit_pending (mh); | 436 | transmit_pending(mh); |
442 | #endif | 437 | #endif |
443 | } | 438 | } |
444 | 439 | ||
@@ -449,38 +444,38 @@ window_change_cb (void *cls, | |||
449 | * @param mh cadet to reset | 444 | * @param mh cadet to reset |
450 | */ | 445 | */ |
451 | static void | 446 | static void |
452 | reset_cadet (struct CadetHandle *mh) | 447 | reset_cadet(struct CadetHandle *mh) |
453 | { | 448 | { |
454 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 449 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
455 | "Resetting cadet channel to %s\n", | 450 | "Resetting cadet channel to %s\n", |
456 | GNUNET_i2s (&mh->target)); | 451 | GNUNET_i2s(&mh->target)); |
457 | if (NULL != mh->channel) | 452 | if (NULL != mh->channel) |
458 | { | 453 | { |
459 | GNUNET_CADET_channel_destroy (mh->channel); | 454 | GNUNET_CADET_channel_destroy(mh->channel); |
460 | mh->channel = NULL; | 455 | mh->channel = NULL; |
461 | } | 456 | } |
462 | GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map, &move_to_pending, mh); | 457 | GNUNET_CONTAINER_multihashmap_iterate(mh->waiting_map, &move_to_pending, mh); |
463 | { | 458 | { |
464 | struct GNUNET_MQ_MessageHandler handlers[] = | 459 | struct GNUNET_MQ_MessageHandler handlers[] = |
465 | {GNUNET_MQ_hd_var_size (reply, | 460 | { GNUNET_MQ_hd_var_size(reply, |
466 | GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, | 461 | GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, |
467 | struct CadetReplyMessage, | 462 | struct CadetReplyMessage, |
468 | mh), | 463 | mh), |
469 | GNUNET_MQ_handler_end ()}; | 464 | GNUNET_MQ_handler_end() }; |
470 | struct GNUNET_HashCode port; | 465 | struct GNUNET_HashCode port; |
471 | 466 | ||
472 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, | 467 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, |
473 | strlen (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), | 468 | strlen(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), |
474 | &port); | 469 | &port); |
475 | mh->channel = GNUNET_CADET_channel_create (cadet_handle, | 470 | mh->channel = GNUNET_CADET_channel_create(cadet_handle, |
476 | mh, | 471 | mh, |
477 | &mh->target, | 472 | &mh->target, |
478 | &port, | 473 | &port, |
479 | &window_change_cb, | 474 | &window_change_cb, |
480 | &disconnect_cb, | 475 | &disconnect_cb, |
481 | handlers); | 476 | handlers); |
482 | } | 477 | } |
483 | transmit_pending (mh); | 478 | transmit_pending(mh); |
484 | } | 479 | } |
485 | 480 | ||
486 | 481 | ||
@@ -490,19 +485,19 @@ reset_cadet (struct CadetHandle *mh) | |||
490 | * @param cls the `struct CadetHandle` to tear down | 485 | * @param cls the `struct CadetHandle` to tear down |
491 | */ | 486 | */ |
492 | static void | 487 | static void |
493 | cadet_timeout (void *cls) | 488 | cadet_timeout(void *cls) |
494 | { | 489 | { |
495 | struct CadetHandle *mh = cls; | 490 | struct CadetHandle *mh = cls; |
496 | struct GNUNET_CADET_Channel *tun; | 491 | struct GNUNET_CADET_Channel *tun; |
497 | 492 | ||
498 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 493 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
499 | "Timeout on cadet channel to %s\n", | 494 | "Timeout on cadet channel to %s\n", |
500 | GNUNET_i2s (&mh->target)); | 495 | GNUNET_i2s(&mh->target)); |
501 | mh->timeout_task = NULL; | 496 | mh->timeout_task = NULL; |
502 | tun = mh->channel; | 497 | tun = mh->channel; |
503 | mh->channel = NULL; | 498 | mh->channel = NULL; |
504 | if (NULL != tun) | 499 | if (NULL != tun) |
505 | GNUNET_CADET_channel_destroy (tun); | 500 | GNUNET_CADET_channel_destroy(tun); |
506 | } | 501 | } |
507 | 502 | ||
508 | 503 | ||
@@ -512,12 +507,12 @@ cadet_timeout (void *cls) | |||
512 | * @param cls the `struct CadetHandle` to tear down | 507 | * @param cls the `struct CadetHandle` to tear down |
513 | */ | 508 | */ |
514 | static void | 509 | static void |
515 | reset_cadet_task (void *cls) | 510 | reset_cadet_task(void *cls) |
516 | { | 511 | { |
517 | struct CadetHandle *mh = cls; | 512 | struct CadetHandle *mh = cls; |
518 | 513 | ||
519 | mh->reset_task = NULL; | 514 | mh->reset_task = NULL; |
520 | reset_cadet (mh); | 515 | reset_cadet(mh); |
521 | } | 516 | } |
522 | 517 | ||
523 | 518 | ||
@@ -527,36 +522,36 @@ reset_cadet_task (void *cls) | |||
527 | * @param cls `struct CadetHandle` to process | 522 | * @param cls `struct CadetHandle` to process |
528 | */ | 523 | */ |
529 | static void | 524 | static void |
530 | transmit_pending (void *cls) | 525 | transmit_pending(void *cls) |
531 | { | 526 | { |
532 | struct CadetHandle *mh = cls; | 527 | struct CadetHandle *mh = cls; |
533 | struct GNUNET_MQ_Handle *mq = GNUNET_CADET_get_mq (mh->channel); | 528 | struct GNUNET_MQ_Handle *mq = GNUNET_CADET_get_mq(mh->channel); |
534 | struct GSF_CadetRequest *sr; | 529 | struct GSF_CadetRequest *sr; |
535 | struct GNUNET_MQ_Envelope *env; | 530 | struct GNUNET_MQ_Envelope *env; |
536 | struct CadetQueryMessage *sqm; | 531 | struct CadetQueryMessage *sqm; |
537 | 532 | ||
538 | if ((0 != GNUNET_MQ_get_length (mq)) || (NULL == (sr = mh->pending_head))) | 533 | if ((0 != GNUNET_MQ_get_length(mq)) || (NULL == (sr = mh->pending_head))) |
539 | return; | 534 | return; |
540 | GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr); | 535 | GNUNET_CONTAINER_DLL_remove(mh->pending_head, mh->pending_tail, sr); |
541 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( | 536 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( |
542 | mh->waiting_map, | 537 | mh->waiting_map, |
543 | &sr->query, | 538 | &sr->query, |
544 | sr, | 539 | sr, |
545 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 540 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
546 | sr->was_transmitted = GNUNET_YES; | 541 | sr->was_transmitted = GNUNET_YES; |
547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 542 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
548 | "Sending query for %s via cadet to %s\n", | 543 | "Sending query for %s via cadet to %s\n", |
549 | GNUNET_h2s (&sr->query), | 544 | GNUNET_h2s(&sr->query), |
550 | GNUNET_i2s (&mh->target)); | 545 | GNUNET_i2s(&mh->target)); |
551 | env = GNUNET_MQ_msg (sqm, GNUNET_MESSAGE_TYPE_FS_CADET_QUERY); | 546 | env = GNUNET_MQ_msg(sqm, GNUNET_MESSAGE_TYPE_FS_CADET_QUERY); |
552 | GNUNET_MQ_env_set_options (env, | 547 | GNUNET_MQ_env_set_options(env, |
553 | GNUNET_MQ_PREF_GOODPUT | | 548 | GNUNET_MQ_PREF_GOODPUT | |
554 | GNUNET_MQ_PREF_CORK_ALLOWED | | 549 | GNUNET_MQ_PREF_CORK_ALLOWED | |
555 | GNUNET_MQ_PREF_OUT_OF_ORDER); | 550 | GNUNET_MQ_PREF_OUT_OF_ORDER); |
556 | sqm->type = htonl (sr->type); | 551 | sqm->type = htonl(sr->type); |
557 | sqm->query = sr->query; | 552 | sqm->query = sr->query; |
558 | GNUNET_MQ_notify_sent (env, &transmit_pending, mh); | 553 | GNUNET_MQ_notify_sent(env, &transmit_pending, mh); |
559 | GNUNET_MQ_send (mq, env); | 554 | GNUNET_MQ_send(mq, env); |
560 | } | 555 | } |
561 | 556 | ||
562 | 557 | ||
@@ -566,53 +561,53 @@ transmit_pending (void *cls) | |||
566 | * @param target peer we want to communicate with | 561 | * @param target peer we want to communicate with |
567 | */ | 562 | */ |
568 | static struct CadetHandle * | 563 | static struct CadetHandle * |
569 | get_cadet (const struct GNUNET_PeerIdentity *target) | 564 | get_cadet(const struct GNUNET_PeerIdentity *target) |
570 | { | 565 | { |
571 | struct CadetHandle *mh; | 566 | struct CadetHandle *mh; |
572 | 567 | ||
573 | mh = GNUNET_CONTAINER_multipeermap_get (cadet_map, target); | 568 | mh = GNUNET_CONTAINER_multipeermap_get(cadet_map, target); |
574 | if (NULL != mh) | 569 | if (NULL != mh) |
575 | { | ||
576 | if (NULL != mh->timeout_task) | ||
577 | { | 570 | { |
578 | GNUNET_SCHEDULER_cancel (mh->timeout_task); | 571 | if (NULL != mh->timeout_task) |
579 | mh->timeout_task = NULL; | 572 | { |
573 | GNUNET_SCHEDULER_cancel(mh->timeout_task); | ||
574 | mh->timeout_task = NULL; | ||
575 | } | ||
576 | return mh; | ||
580 | } | 577 | } |
581 | return mh; | 578 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
582 | } | 579 | "Creating cadet channel to %s\n", |
583 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 580 | GNUNET_i2s(target)); |
584 | "Creating cadet channel to %s\n", | 581 | mh = GNUNET_new(struct CadetHandle); |
585 | GNUNET_i2s (target)); | ||
586 | mh = GNUNET_new (struct CadetHandle); | ||
587 | mh->reset_task = | 582 | mh->reset_task = |
588 | GNUNET_SCHEDULER_add_delayed (CLIENT_RETRY_TIMEOUT, &reset_cadet_task, mh); | 583 | GNUNET_SCHEDULER_add_delayed(CLIENT_RETRY_TIMEOUT, &reset_cadet_task, mh); |
589 | mh->waiting_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES); | 584 | mh->waiting_map = GNUNET_CONTAINER_multihashmap_create(16, GNUNET_YES); |
590 | mh->target = *target; | 585 | mh->target = *target; |
591 | GNUNET_assert (GNUNET_OK == | 586 | GNUNET_assert(GNUNET_OK == |
592 | GNUNET_CONTAINER_multipeermap_put ( | 587 | GNUNET_CONTAINER_multipeermap_put( |
593 | cadet_map, | 588 | cadet_map, |
594 | &mh->target, | 589 | &mh->target, |
595 | mh, | 590 | mh, |
596 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 591 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
597 | { | 592 | { |
598 | struct GNUNET_MQ_MessageHandler handlers[] = | 593 | struct GNUNET_MQ_MessageHandler handlers[] = |
599 | {GNUNET_MQ_hd_var_size (reply, | 594 | { GNUNET_MQ_hd_var_size(reply, |
600 | GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, | 595 | GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, |
601 | struct CadetReplyMessage, | 596 | struct CadetReplyMessage, |
602 | mh), | 597 | mh), |
603 | GNUNET_MQ_handler_end ()}; | 598 | GNUNET_MQ_handler_end() }; |
604 | struct GNUNET_HashCode port; | 599 | struct GNUNET_HashCode port; |
605 | 600 | ||
606 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, | 601 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, |
607 | strlen (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), | 602 | strlen(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), |
608 | &port); | 603 | &port); |
609 | mh->channel = GNUNET_CADET_channel_create (cadet_handle, | 604 | mh->channel = GNUNET_CADET_channel_create(cadet_handle, |
610 | mh, | 605 | mh, |
611 | &mh->target, | 606 | &mh->target, |
612 | &port, | 607 | &port, |
613 | &window_change_cb, | 608 | &window_change_cb, |
614 | &disconnect_cb, | 609 | &disconnect_cb, |
615 | handlers); | 610 | handlers); |
616 | } | 611 | } |
617 | return mh; | 612 | return mh; |
618 | } | 613 | } |
@@ -629,28 +624,28 @@ get_cadet (const struct GNUNET_PeerIdentity *target) | |||
629 | * @return handle to cancel the operation | 624 | * @return handle to cancel the operation |
630 | */ | 625 | */ |
631 | struct GSF_CadetRequest * | 626 | struct GSF_CadetRequest * |
632 | GSF_cadet_query (const struct GNUNET_PeerIdentity *target, | 627 | GSF_cadet_query(const struct GNUNET_PeerIdentity *target, |
633 | const struct GNUNET_HashCode *query, | 628 | const struct GNUNET_HashCode *query, |
634 | enum GNUNET_BLOCK_Type type, | 629 | enum GNUNET_BLOCK_Type type, |
635 | GSF_CadetReplyProcessor proc, | 630 | GSF_CadetReplyProcessor proc, |
636 | void *proc_cls) | 631 | void *proc_cls) |
637 | { | 632 | { |
638 | struct CadetHandle *mh; | 633 | struct CadetHandle *mh; |
639 | struct GSF_CadetRequest *sr; | 634 | struct GSF_CadetRequest *sr; |
640 | 635 | ||
641 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 636 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
642 | "Preparing to send query for %s via cadet to %s\n", | 637 | "Preparing to send query for %s via cadet to %s\n", |
643 | GNUNET_h2s (query), | 638 | GNUNET_h2s(query), |
644 | GNUNET_i2s (target)); | 639 | GNUNET_i2s(target)); |
645 | mh = get_cadet (target); | 640 | mh = get_cadet(target); |
646 | sr = GNUNET_new (struct GSF_CadetRequest); | 641 | sr = GNUNET_new(struct GSF_CadetRequest); |
647 | sr->mh = mh; | 642 | sr->mh = mh; |
648 | sr->proc = proc; | 643 | sr->proc = proc; |
649 | sr->proc_cls = proc_cls; | 644 | sr->proc_cls = proc_cls; |
650 | sr->type = type; | 645 | sr->type = type; |
651 | sr->query = *query; | 646 | sr->query = *query; |
652 | GNUNET_CONTAINER_DLL_insert (mh->pending_head, mh->pending_tail, sr); | 647 | GNUNET_CONTAINER_DLL_insert(mh->pending_head, mh->pending_tail, sr); |
653 | transmit_pending (mh); | 648 | transmit_pending(mh); |
654 | return sr; | 649 | return sr; |
655 | } | 650 | } |
656 | 651 | ||
@@ -662,7 +657,7 @@ GSF_cadet_query (const struct GNUNET_PeerIdentity *target, | |||
662 | * @param sr request to cancel | 657 | * @param sr request to cancel |
663 | */ | 658 | */ |
664 | void | 659 | void |
665 | GSF_cadet_query_cancel (struct GSF_CadetRequest *sr) | 660 | GSF_cadet_query_cancel(struct GSF_CadetRequest *sr) |
666 | { | 661 | { |
667 | struct CadetHandle *mh = sr->mh; | 662 | struct CadetHandle *mh = sr->mh; |
668 | GSF_CadetReplyProcessor p; | 663 | GSF_CadetReplyProcessor p; |
@@ -670,26 +665,26 @@ GSF_cadet_query_cancel (struct GSF_CadetRequest *sr) | |||
670 | p = sr->proc; | 665 | p = sr->proc; |
671 | sr->proc = NULL; | 666 | sr->proc = NULL; |
672 | if (NULL != p) | 667 | if (NULL != p) |
673 | { | 668 | { |
674 | /* signal failure / cancellation to callback */ | 669 | /* signal failure / cancellation to callback */ |
675 | p (sr->proc_cls, GNUNET_BLOCK_TYPE_ANY, GNUNET_TIME_UNIT_ZERO_ABS, 0, NULL); | 670 | p(sr->proc_cls, GNUNET_BLOCK_TYPE_ANY, GNUNET_TIME_UNIT_ZERO_ABS, 0, NULL); |
676 | } | 671 | } |
677 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 672 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
678 | "Cancelled query for %s via cadet to %s\n", | 673 | "Cancelled query for %s via cadet to %s\n", |
679 | GNUNET_h2s (&sr->query), | 674 | GNUNET_h2s(&sr->query), |
680 | GNUNET_i2s (&sr->mh->target)); | 675 | GNUNET_i2s(&sr->mh->target)); |
681 | if (GNUNET_YES == sr->was_transmitted) | 676 | if (GNUNET_YES == sr->was_transmitted) |
682 | GNUNET_assert ( | 677 | GNUNET_assert( |
683 | GNUNET_OK == | 678 | GNUNET_OK == |
684 | GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, &sr->query, sr)); | 679 | GNUNET_CONTAINER_multihashmap_remove(mh->waiting_map, &sr->query, sr)); |
685 | else | 680 | else |
686 | GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr); | 681 | GNUNET_CONTAINER_DLL_remove(mh->pending_head, mh->pending_tail, sr); |
687 | GNUNET_free (sr); | 682 | GNUNET_free(sr); |
688 | if ((0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)) && | 683 | if ((0 == GNUNET_CONTAINER_multihashmap_size(mh->waiting_map)) && |
689 | (NULL == mh->pending_head)) | 684 | (NULL == mh->pending_head)) |
690 | mh->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 685 | mh->timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
691 | &cadet_timeout, | 686 | &cadet_timeout, |
692 | mh); | 687 | mh); |
693 | } | 688 | } |
694 | 689 | ||
695 | 690 | ||
@@ -702,27 +697,27 @@ GSF_cadet_query_cancel (struct GSF_CadetRequest *sr) | |||
702 | * @return #GNUNET_YES (continue to iterate) | 697 | * @return #GNUNET_YES (continue to iterate) |
703 | */ | 698 | */ |
704 | int | 699 | int |
705 | GSF_cadet_release_clients (void *cls, | 700 | GSF_cadet_release_clients(void *cls, |
706 | const struct GNUNET_PeerIdentity *key, | 701 | const struct GNUNET_PeerIdentity *key, |
707 | void *value) | 702 | void *value) |
708 | { | 703 | { |
709 | struct CadetHandle *mh = value; | 704 | struct CadetHandle *mh = value; |
710 | 705 | ||
711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 706 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
712 | "Timeout on cadet channel to %s\n", | 707 | "Timeout on cadet channel to %s\n", |
713 | GNUNET_i2s (&mh->target)); | 708 | GNUNET_i2s(&mh->target)); |
714 | if (NULL != mh->channel) | 709 | if (NULL != mh->channel) |
715 | { | 710 | { |
716 | struct GNUNET_CADET_Channel *channel = mh->channel; | 711 | struct GNUNET_CADET_Channel *channel = mh->channel; |
717 | 712 | ||
718 | mh->channel = NULL; | 713 | mh->channel = NULL; |
719 | GNUNET_CADET_channel_destroy (channel); | 714 | GNUNET_CADET_channel_destroy(channel); |
720 | } | 715 | } |
721 | if (NULL != mh->reset_task) | 716 | if (NULL != mh->reset_task) |
722 | { | 717 | { |
723 | GNUNET_SCHEDULER_cancel (mh->reset_task); | 718 | GNUNET_SCHEDULER_cancel(mh->reset_task); |
724 | mh->reset_task = NULL; | 719 | mh->reset_task = NULL; |
725 | } | 720 | } |
726 | return GNUNET_YES; | 721 | return GNUNET_YES; |
727 | } | 722 | } |
728 | 723 | ||
diff --git a/src/fs/gnunet-service-fs_cadet_server.c b/src/fs/gnunet-service-fs_cadet_server.c index bb320806a..68e87f092 100644 --- a/src/fs/gnunet-service-fs_cadet_server.c +++ b/src/fs/gnunet-service-fs_cadet_server.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_cadet_server.c | 22 | * @file fs/gnunet-service-fs_cadet_server.c |
@@ -40,14 +40,13 @@ | |||
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 | { | ||
51 | /** | 50 | /** |
52 | * Kept in a DLL. | 51 | * Kept in a DLL. |
53 | */ | 52 | */ |
@@ -68,8 +67,7 @@ struct WriteQueueItem | |||
68 | /** | 67 | /** |
69 | * Information we keep around for each active cadeting client. | 68 | * Information we keep around for each active cadeting client. |
70 | */ | 69 | */ |
71 | struct CadetClient | 70 | struct CadetClient { |
72 | { | ||
73 | /** | 71 | /** |
74 | * DLL | 72 | * DLL |
75 | */ | 73 | */ |
@@ -114,7 +112,6 @@ struct CadetClient | |||
114 | * Size of the last write that was initiated. | 112 | * Size of the last write that was initiated. |
115 | */ | 113 | */ |
116 | size_t reply_size; | 114 | size_t reply_size; |
117 | |||
118 | }; | 115 | }; |
119 | 116 | ||
120 | 117 | ||
@@ -151,7 +148,7 @@ static unsigned long long sc_count_max; | |||
151 | * @param cls the 'struct CadetClient' | 148 | * @param cls the 'struct CadetClient' |
152 | */ | 149 | */ |
153 | static void | 150 | static void |
154 | timeout_cadet_task (void *cls) | 151 | timeout_cadet_task(void *cls) |
155 | { | 152 | { |
156 | struct CadetClient *sc = cls; | 153 | struct CadetClient *sc = cls; |
157 | struct GNUNET_CADET_Channel *tun; | 154 | struct GNUNET_CADET_Channel *tun; |
@@ -159,10 +156,10 @@ timeout_cadet_task (void *cls) | |||
159 | sc->timeout_task = NULL; | 156 | sc->timeout_task = NULL; |
160 | tun = sc->channel; | 157 | tun = sc->channel; |
161 | sc->channel = NULL; | 158 | sc->channel = NULL; |
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 159 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
163 | "Timeout for inactive cadet client %p\n", | 160 | "Timeout for inactive cadet client %p\n", |
164 | sc); | 161 | sc); |
165 | GNUNET_CADET_channel_destroy (tun); | 162 | GNUNET_CADET_channel_destroy(tun); |
166 | } | 163 | } |
167 | 164 | ||
168 | 165 | ||
@@ -172,13 +169,13 @@ timeout_cadet_task (void *cls) | |||
172 | * @param sc client handle to reset timeout for | 169 | * @param sc client handle to reset timeout for |
173 | */ | 170 | */ |
174 | static void | 171 | static void |
175 | refresh_timeout_task (struct CadetClient *sc) | 172 | refresh_timeout_task(struct CadetClient *sc) |
176 | { | 173 | { |
177 | if (NULL != sc->timeout_task) | 174 | if (NULL != sc->timeout_task) |
178 | GNUNET_SCHEDULER_cancel (sc->timeout_task); | 175 | GNUNET_SCHEDULER_cancel(sc->timeout_task); |
179 | sc->timeout_task = GNUNET_SCHEDULER_add_delayed (IDLE_TIMEOUT, | 176 | sc->timeout_task = GNUNET_SCHEDULER_add_delayed(IDLE_TIMEOUT, |
180 | &timeout_cadet_task, | 177 | &timeout_cadet_task, |
181 | sc); | 178 | sc); |
182 | } | 179 | } |
183 | 180 | ||
184 | 181 | ||
@@ -189,23 +186,23 @@ refresh_timeout_task (struct CadetClient *sc) | |||
189 | * @param cls where to process the write queue | 186 | * @param cls where to process the write queue |
190 | */ | 187 | */ |
191 | static void | 188 | static void |
192 | continue_writing (void *cls) | 189 | continue_writing(void *cls) |
193 | { | 190 | { |
194 | struct CadetClient *sc = cls; | 191 | struct CadetClient *sc = cls; |
195 | struct GNUNET_MQ_Handle *mq; | 192 | struct GNUNET_MQ_Handle *mq; |
196 | 193 | ||
197 | mq = GNUNET_CADET_get_mq (sc->channel); | 194 | mq = GNUNET_CADET_get_mq(sc->channel); |
198 | if (0 != GNUNET_MQ_get_length (mq)) | 195 | if (0 != GNUNET_MQ_get_length(mq)) |
199 | { | 196 | { |
200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
201 | "Write pending, waiting for it to complete\n"); | 198 | "Write pending, waiting for it to complete\n"); |
202 | return; | 199 | return; |
203 | } | 200 | } |
204 | refresh_timeout_task (sc); | 201 | refresh_timeout_task(sc); |
205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 202 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
206 | "Finished processing cadet request from client %p, ready to receive the next one\n", | 203 | "Finished processing cadet request from client %p, ready to receive the next one\n", |
207 | sc); | 204 | sc); |
208 | GNUNET_CADET_receive_done (sc->channel); | 205 | GNUNET_CADET_receive_done(sc->channel); |
209 | } | 206 | } |
210 | 207 | ||
211 | 208 | ||
@@ -225,103 +222,103 @@ continue_writing (void *cls) | |||
225 | * maybe 0 if no unique identifier is available | 222 | * maybe 0 if no unique identifier is available |
226 | */ | 223 | */ |
227 | static void | 224 | static void |
228 | handle_datastore_reply (void *cls, | 225 | handle_datastore_reply(void *cls, |
229 | const struct GNUNET_HashCode *key, | 226 | const struct GNUNET_HashCode *key, |
230 | size_t size, | 227 | size_t size, |
231 | const void *data, | 228 | const void *data, |
232 | enum GNUNET_BLOCK_Type type, | 229 | enum GNUNET_BLOCK_Type type, |
233 | uint32_t priority, | 230 | uint32_t priority, |
234 | uint32_t anonymity, | 231 | uint32_t anonymity, |
235 | uint32_t replication, | 232 | uint32_t replication, |
236 | struct GNUNET_TIME_Absolute expiration, | 233 | struct GNUNET_TIME_Absolute expiration, |
237 | uint64_t uid) | 234 | uint64_t uid) |
238 | { | 235 | { |
239 | struct CadetClient *sc = cls; | 236 | struct CadetClient *sc = cls; |
240 | size_t msize = size + sizeof (struct CadetReplyMessage); | 237 | size_t msize = size + sizeof(struct CadetReplyMessage); |
241 | struct GNUNET_MQ_Envelope *env; | 238 | struct GNUNET_MQ_Envelope *env; |
242 | struct CadetReplyMessage *srm; | 239 | struct CadetReplyMessage *srm; |
243 | 240 | ||
244 | sc->qe = NULL; | 241 | sc->qe = NULL; |
245 | if (NULL == data) | 242 | if (NULL == data) |
246 | { | ||
247 | /* no result, this should not really happen, as for | ||
248 | non-anonymous routing only peers that HAVE the | ||
249 | answers should be queried; OTOH, this is not a | ||
250 | hard error as we might have had the answer in the | ||
251 | past and the user might have unindexed it. Hence | ||
252 | we log at level "INFO" for now. */ | ||
253 | if (NULL == key) | ||
254 | { | ||
255 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
256 | "Have no answer and the query was NULL\n"); | ||
257 | } | ||
258 | else | ||
259 | { | 243 | { |
260 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 244 | /* no result, this should not really happen, as for |
261 | "Have no answer for query `%s'\n", | 245 | non-anonymous routing only peers that HAVE the |
262 | GNUNET_h2s (key)); | 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; | ||
263 | } | 267 | } |
264 | GNUNET_STATISTICS_update (GSF_stats, | ||
265 | gettext_noop ("# 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) | 268 | 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)) | ||
288 | { | 269 | { |
289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 270 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
290 | "On-demand encoding request failed\n"); | 271 | "Performing on-demand encoding for query %s\n", |
291 | continue_writing (sc); | 272 | 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; | ||
292 | } | 291 | } |
293 | return; | ||
294 | } | ||
295 | if (msize > GNUNET_MAX_MESSAGE_SIZE) | 292 | if (msize > GNUNET_MAX_MESSAGE_SIZE) |
296 | { | 293 | { |
297 | GNUNET_break (0); | 294 | GNUNET_break(0); |
298 | continue_writing (sc); | 295 | continue_writing(sc); |
299 | return; | 296 | return; |
300 | } | 297 | } |
301 | GNUNET_break (GNUNET_BLOCK_TYPE_ANY != type); | 298 | GNUNET_break(GNUNET_BLOCK_TYPE_ANY != type); |
302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 299 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
303 | "Starting transmission of %u byte reply of type %d for query `%s' via cadet to %p\n", | 300 | "Starting transmission of %u byte reply of type %d for query `%s' via cadet to %p\n", |
304 | (unsigned int) size, | 301 | (unsigned int)size, |
305 | (unsigned int) type, | 302 | (unsigned int)type, |
306 | GNUNET_h2s (key), | 303 | GNUNET_h2s(key), |
307 | sc); | 304 | sc); |
308 | env = GNUNET_MQ_msg_extra (srm, | 305 | env = GNUNET_MQ_msg_extra(srm, |
309 | size, | 306 | size, |
310 | GNUNET_MESSAGE_TYPE_FS_CADET_REPLY); | 307 | GNUNET_MESSAGE_TYPE_FS_CADET_REPLY); |
311 | srm->type = htonl (type); | 308 | srm->type = htonl(type); |
312 | srm->expiration = GNUNET_TIME_absolute_hton (expiration); | 309 | srm->expiration = GNUNET_TIME_absolute_hton(expiration); |
313 | GNUNET_memcpy (&srm[1], | 310 | GNUNET_memcpy(&srm[1], |
314 | data, | 311 | data, |
315 | size); | 312 | size); |
316 | GNUNET_MQ_notify_sent (env, | 313 | GNUNET_MQ_notify_sent(env, |
317 | &continue_writing, | 314 | &continue_writing, |
318 | sc); | 315 | sc); |
319 | GNUNET_STATISTICS_update (GSF_stats, | 316 | GNUNET_STATISTICS_update(GSF_stats, |
320 | gettext_noop ("# Blocks transferred via cadet"), | 317 | gettext_noop("# Blocks transferred via cadet"), |
321 | 1, | 318 | 1, |
322 | GNUNET_NO); | 319 | GNUNET_NO); |
323 | GNUNET_MQ_send (GNUNET_CADET_get_mq (sc->channel), | 320 | GNUNET_MQ_send(GNUNET_CADET_get_mq(sc->channel), |
324 | env); | 321 | env); |
325 | } | 322 | } |
326 | 323 | ||
327 | 324 | ||
@@ -333,35 +330,35 @@ handle_datastore_reply (void *cls, | |||
333 | * @param sqm the actual message | 330 | * @param sqm the actual message |
334 | */ | 331 | */ |
335 | static void | 332 | static void |
336 | handle_request (void *cls, | 333 | handle_request(void *cls, |
337 | const struct CadetQueryMessage *sqm) | 334 | const struct CadetQueryMessage *sqm) |
338 | { | 335 | { |
339 | struct CadetClient *sc = cls; | 336 | struct CadetClient *sc = cls; |
340 | 337 | ||
341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 338 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
342 | "Received query for `%s' via cadet from client %p\n", | 339 | "Received query for `%s' via cadet from client %p\n", |
343 | GNUNET_h2s (&sqm->query), | 340 | GNUNET_h2s(&sqm->query), |
344 | sc); | 341 | sc); |
345 | GNUNET_STATISTICS_update (GSF_stats, | 342 | GNUNET_STATISTICS_update(GSF_stats, |
346 | gettext_noop ("# queries received via cadet"), | 343 | gettext_noop("# queries received via cadet"), |
347 | 1, | 344 | 1, |
348 | GNUNET_NO); | 345 | GNUNET_NO); |
349 | refresh_timeout_task (sc); | 346 | refresh_timeout_task(sc); |
350 | sc->qe = GNUNET_DATASTORE_get_key (GSF_dsh, | 347 | sc->qe = GNUNET_DATASTORE_get_key(GSF_dsh, |
351 | 0 /* next_uid */, | 348 | 0 /* next_uid */, |
352 | false /* random */, | 349 | false /* random */, |
353 | &sqm->query, | 350 | &sqm->query, |
354 | ntohl (sqm->type), | 351 | ntohl(sqm->type), |
355 | 0 /* priority */, | 352 | 0 /* priority */, |
356 | GSF_datastore_queue_size, | 353 | GSF_datastore_queue_size, |
357 | &handle_datastore_reply, | 354 | &handle_datastore_reply, |
358 | sc); | 355 | sc); |
359 | if (NULL == sc->qe) | 356 | if (NULL == sc->qe) |
360 | { | 357 | { |
361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 358 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
362 | "Queueing request with datastore failed (queue full?)\n"); | 359 | "Queueing request with datastore failed (queue full?)\n"); |
363 | continue_writing (sc); | 360 | continue_writing(sc); |
364 | } | 361 | } |
365 | } | 362 | } |
366 | 363 | ||
367 | 364 | ||
@@ -375,37 +372,37 @@ handle_request (void *cls, | |||
375 | * @return initial channel context (our `struct CadetClient`) | 372 | * @return initial channel context (our `struct CadetClient`) |
376 | */ | 373 | */ |
377 | static void * | 374 | static void * |
378 | connect_cb (void *cls, | 375 | connect_cb(void *cls, |
379 | struct GNUNET_CADET_Channel *channel, | 376 | struct GNUNET_CADET_Channel *channel, |
380 | const struct GNUNET_PeerIdentity *initiator) | 377 | const struct GNUNET_PeerIdentity *initiator) |
381 | { | 378 | { |
382 | struct CadetClient *sc; | 379 | struct CadetClient *sc; |
383 | 380 | ||
384 | GNUNET_assert (NULL != channel); | 381 | GNUNET_assert(NULL != channel); |
385 | if (sc_count >= sc_count_max) | 382 | if (sc_count >= sc_count_max) |
386 | { | 383 | { |
387 | GNUNET_STATISTICS_update (GSF_stats, | 384 | GNUNET_STATISTICS_update(GSF_stats, |
388 | gettext_noop ("# cadet client connections rejected"), | 385 | gettext_noop("# cadet client connections rejected"), |
389 | 1, | 386 | 1, |
390 | GNUNET_NO); | 387 | GNUNET_NO); |
391 | GNUNET_CADET_channel_destroy (channel); | 388 | GNUNET_CADET_channel_destroy(channel); |
392 | return NULL; | 389 | return NULL; |
393 | } | 390 | } |
394 | GNUNET_STATISTICS_update (GSF_stats, | 391 | GNUNET_STATISTICS_update(GSF_stats, |
395 | gettext_noop ("# cadet connections active"), | 392 | gettext_noop("# cadet connections active"), |
396 | 1, | 393 | 1, |
397 | GNUNET_NO); | 394 | GNUNET_NO); |
398 | sc = GNUNET_new (struct CadetClient); | 395 | sc = GNUNET_new(struct CadetClient); |
399 | sc->channel = channel; | 396 | sc->channel = channel; |
400 | GNUNET_CONTAINER_DLL_insert (sc_head, | 397 | GNUNET_CONTAINER_DLL_insert(sc_head, |
401 | sc_tail, | 398 | sc_tail, |
402 | sc); | 399 | sc); |
403 | sc_count++; | 400 | sc_count++; |
404 | refresh_timeout_task (sc); | 401 | refresh_timeout_task(sc); |
405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 402 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
406 | "Accepting inbound cadet connection from `%s' as client %p\n", | 403 | "Accepting inbound cadet connection from `%s' as client %p\n", |
407 | GNUNET_i2s (initiator), | 404 | GNUNET_i2s(initiator), |
408 | sc); | 405 | sc); |
409 | return sc; | 406 | return sc; |
410 | } | 407 | } |
411 | 408 | ||
@@ -419,8 +416,8 @@ connect_cb (void *cls, | |||
419 | * @param channel_ctx | 416 | * @param channel_ctx |
420 | */ | 417 | */ |
421 | static void | 418 | static void |
422 | disconnect_cb (void *cls, | 419 | disconnect_cb(void *cls, |
423 | const struct GNUNET_CADET_Channel *channel) | 420 | const struct GNUNET_CADET_Channel *channel) |
424 | { | 421 | { |
425 | struct CadetClient *sc = cls; | 422 | struct CadetClient *sc = cls; |
426 | struct WriteQueueItem *wqi; | 423 | struct WriteQueueItem *wqi; |
@@ -428,30 +425,30 @@ disconnect_cb (void *cls, | |||
428 | if (NULL == sc) | 425 | if (NULL == sc) |
429 | return; | 426 | return; |
430 | sc->channel = NULL; | 427 | sc->channel = NULL; |
431 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 428 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
432 | "Terminating cadet connection with client %p\n", | 429 | "Terminating cadet connection with client %p\n", |
433 | sc); | 430 | sc); |
434 | GNUNET_STATISTICS_update (GSF_stats, | 431 | GNUNET_STATISTICS_update(GSF_stats, |
435 | gettext_noop ("# cadet connections active"), -1, | 432 | gettext_noop("# cadet connections active"), -1, |
436 | GNUNET_NO); | 433 | GNUNET_NO); |
437 | if (NULL != sc->terminate_task) | 434 | if (NULL != sc->terminate_task) |
438 | GNUNET_SCHEDULER_cancel (sc->terminate_task); | 435 | GNUNET_SCHEDULER_cancel(sc->terminate_task); |
439 | if (NULL != sc->timeout_task) | 436 | if (NULL != sc->timeout_task) |
440 | GNUNET_SCHEDULER_cancel (sc->timeout_task); | 437 | GNUNET_SCHEDULER_cancel(sc->timeout_task); |
441 | if (NULL != sc->qe) | 438 | if (NULL != sc->qe) |
442 | GNUNET_DATASTORE_cancel (sc->qe); | 439 | GNUNET_DATASTORE_cancel(sc->qe); |
443 | while (NULL != (wqi = sc->wqi_head)) | 440 | while (NULL != (wqi = sc->wqi_head)) |
444 | { | 441 | { |
445 | GNUNET_CONTAINER_DLL_remove (sc->wqi_head, | 442 | GNUNET_CONTAINER_DLL_remove(sc->wqi_head, |
446 | sc->wqi_tail, | 443 | sc->wqi_tail, |
447 | wqi); | 444 | wqi); |
448 | GNUNET_free (wqi); | 445 | GNUNET_free(wqi); |
449 | } | 446 | } |
450 | GNUNET_CONTAINER_DLL_remove (sc_head, | 447 | GNUNET_CONTAINER_DLL_remove(sc_head, |
451 | sc_tail, | 448 | sc_tail, |
452 | sc); | 449 | sc); |
453 | sc_count--; | 450 | sc_count--; |
454 | GNUNET_free (sc); | 451 | GNUNET_free(sc); |
455 | } | 452 | } |
456 | 453 | ||
457 | 454 | ||
@@ -470,9 +467,9 @@ disconnect_cb (void *cls, | |||
470 | * this value will be negative.. | 467 | * this value will be negative.. |
471 | */ | 468 | */ |
472 | static void | 469 | static void |
473 | window_change_cb (void *cls, | 470 | window_change_cb(void *cls, |
474 | const struct GNUNET_CADET_Channel *channel, | 471 | const struct GNUNET_CADET_Channel *channel, |
475 | int window_size) | 472 | int window_size) |
476 | { | 473 | { |
477 | /* FIXME: could do flow control here... */ | 474 | /* FIXME: could do flow control here... */ |
478 | } | 475 | } |
@@ -482,39 +479,39 @@ window_change_cb (void *cls, | |||
482 | * Initialize subsystem for non-anonymous file-sharing. | 479 | * Initialize subsystem for non-anonymous file-sharing. |
483 | */ | 480 | */ |
484 | void | 481 | void |
485 | GSF_cadet_start_server () | 482 | GSF_cadet_start_server() |
486 | { | 483 | { |
487 | struct GNUNET_MQ_MessageHandler handlers[] = { | 484 | struct GNUNET_MQ_MessageHandler handlers[] = { |
488 | GNUNET_MQ_hd_fixed_size (request, | 485 | GNUNET_MQ_hd_fixed_size(request, |
489 | GNUNET_MESSAGE_TYPE_FS_CADET_QUERY, | 486 | GNUNET_MESSAGE_TYPE_FS_CADET_QUERY, |
490 | struct CadetQueryMessage, | 487 | struct CadetQueryMessage, |
491 | NULL), | 488 | NULL), |
492 | GNUNET_MQ_handler_end () | 489 | GNUNET_MQ_handler_end() |
493 | }; | 490 | }; |
494 | struct GNUNET_HashCode port; | 491 | struct GNUNET_HashCode port; |
495 | 492 | ||
496 | if (GNUNET_YES != | 493 | if (GNUNET_YES != |
497 | GNUNET_CONFIGURATION_get_value_number (GSF_cfg, | 494 | GNUNET_CONFIGURATION_get_value_number(GSF_cfg, |
498 | "fs", | 495 | "fs", |
499 | "MAX_CADET_CLIENTS", | 496 | "MAX_CADET_CLIENTS", |
500 | &sc_count_max)) | 497 | &sc_count_max)) |
501 | return; | 498 | return; |
502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 499 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
503 | "Initializing cadet FS server with a limit of %llu connections\n", | 500 | "Initializing cadet FS server with a limit of %llu connections\n", |
504 | sc_count_max); | 501 | sc_count_max); |
505 | cadet_map = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); | 502 | cadet_map = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES); |
506 | cadet_handle = GNUNET_CADET_connect (GSF_cfg); | 503 | cadet_handle = GNUNET_CADET_connect(GSF_cfg); |
507 | GNUNET_assert (NULL != cadet_handle); | 504 | GNUNET_assert(NULL != cadet_handle); |
508 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, | 505 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, |
509 | strlen (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), | 506 | strlen(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), |
510 | &port); | 507 | &port); |
511 | cadet_port = GNUNET_CADET_open_port (cadet_handle, | 508 | cadet_port = GNUNET_CADET_open_port(cadet_handle, |
512 | &port, | 509 | &port, |
513 | &connect_cb, | 510 | &connect_cb, |
514 | NULL, | 511 | NULL, |
515 | &window_change_cb, | 512 | &window_change_cb, |
516 | &disconnect_cb, | 513 | &disconnect_cb, |
517 | handlers); | 514 | handlers); |
518 | } | 515 | } |
519 | 516 | ||
520 | 517 | ||
@@ -522,25 +519,25 @@ GSF_cadet_start_server () | |||
522 | * Shutdown subsystem for non-anonymous file-sharing. | 519 | * Shutdown subsystem for non-anonymous file-sharing. |
523 | */ | 520 | */ |
524 | void | 521 | void |
525 | GSF_cadet_stop_server () | 522 | GSF_cadet_stop_server() |
526 | { | 523 | { |
527 | GNUNET_CONTAINER_multipeermap_iterate (cadet_map, | 524 | GNUNET_CONTAINER_multipeermap_iterate(cadet_map, |
528 | &GSF_cadet_release_clients, | 525 | &GSF_cadet_release_clients, |
529 | NULL); | 526 | NULL); |
530 | GNUNET_CONTAINER_multipeermap_destroy (cadet_map); | 527 | GNUNET_CONTAINER_multipeermap_destroy(cadet_map); |
531 | cadet_map = NULL; | 528 | cadet_map = NULL; |
532 | if (NULL != cadet_port) | 529 | if (NULL != cadet_port) |
533 | { | 530 | { |
534 | GNUNET_CADET_close_port (cadet_port); | 531 | GNUNET_CADET_close_port(cadet_port); |
535 | cadet_port = NULL; | 532 | cadet_port = NULL; |
536 | } | 533 | } |
537 | if (NULL != cadet_handle) | 534 | if (NULL != cadet_handle) |
538 | { | 535 | { |
539 | GNUNET_CADET_disconnect (cadet_handle); | 536 | GNUNET_CADET_disconnect(cadet_handle); |
540 | cadet_handle = NULL; | 537 | cadet_handle = NULL; |
541 | } | 538 | } |
542 | GNUNET_assert (NULL == sc_head); | 539 | GNUNET_assert(NULL == sc_head); |
543 | GNUNET_assert (0 == sc_count); | 540 | GNUNET_assert(0 == sc_count); |
544 | } | 541 | } |
545 | 542 | ||
546 | /* end of gnunet-service-fs_cadet.c */ | 543 | /* 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 a3a521221..6dab37869 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/gnunet-service-fs_cp.c | 21 | * @file fs/gnunet-service-fs_cp.c |
22 | * @brief API to handle 'connected peers' | 22 | * @brief API to handle 'connected peers' |
@@ -43,12 +43,12 @@ | |||
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(GNUNET_TIME_UNIT_MINUTES, 5) |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * After how long do we discard a reply? | 49 | * After how long do we discard a reply? |
50 | */ | 50 | */ |
51 | #define REPLY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) | 51 | #define REPLY_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Collect an instane number of statistics? May cause excessive IPC. | 54 | * Collect an instane number of statistics? May cause excessive IPC. |
@@ -59,9 +59,7 @@ | |||
59 | /** | 59 | /** |
60 | * Handle to cancel a transmission request. | 60 | * Handle to cancel a transmission request. |
61 | */ | 61 | */ |
62 | struct GSF_PeerTransmitHandle | 62 | struct GSF_PeerTransmitHandle { |
63 | { | ||
64 | |||
65 | /** | 63 | /** |
66 | * Kept in a doubly-linked list. | 64 | * Kept in a doubly-linked list. |
67 | */ | 65 | */ |
@@ -101,16 +99,13 @@ struct GSF_PeerTransmitHandle | |||
101 | * Priority of this request. | 99 | * Priority of this request. |
102 | */ | 100 | */ |
103 | uint32_t priority; | 101 | uint32_t priority; |
104 | |||
105 | }; | 102 | }; |
106 | 103 | ||
107 | 104 | ||
108 | /** | 105 | /** |
109 | * Handle for an entry in our delay list. | 106 | * Handle for an entry in our delay list. |
110 | */ | 107 | */ |
111 | struct GSF_DelayedHandle | 108 | struct GSF_DelayedHandle { |
112 | { | ||
113 | |||
114 | /** | 109 | /** |
115 | * Kept in a doubly-linked list. | 110 | * Kept in a doubly-linked list. |
116 | */ | 111 | */ |
@@ -140,16 +135,13 @@ struct GSF_DelayedHandle | |||
140 | * Size of the message. | 135 | * Size of the message. |
141 | */ | 136 | */ |
142 | size_t msize; | 137 | size_t msize; |
143 | |||
144 | }; | 138 | }; |
145 | 139 | ||
146 | 140 | ||
147 | /** | 141 | /** |
148 | * Information per peer and request. | 142 | * Information per peer and request. |
149 | */ | 143 | */ |
150 | struct PeerRequest | 144 | struct PeerRequest { |
151 | { | ||
152 | |||
153 | /** | 145 | /** |
154 | * Handle to generic request (generic: from peer or local client). | 146 | * Handle to generic request (generic: from peer or local client). |
155 | */ | 147 | */ |
@@ -164,16 +156,13 @@ struct PeerRequest | |||
164 | * Task for asynchronous stopping of this request. | 156 | * Task for asynchronous stopping of this request. |
165 | */ | 157 | */ |
166 | struct GNUNET_SCHEDULER_Task *kill_task; | 158 | struct GNUNET_SCHEDULER_Task *kill_task; |
167 | |||
168 | }; | 159 | }; |
169 | 160 | ||
170 | 161 | ||
171 | /** | 162 | /** |
172 | * A connected peer. | 163 | * A connected peer. |
173 | */ | 164 | */ |
174 | struct GSF_ConnectedPeer | 165 | struct GSF_ConnectedPeer { |
175 | { | ||
176 | |||
177 | /** | 166 | /** |
178 | * Performance data for this peer. | 167 | * Performance data for this peer. |
179 | */ | 168 | */ |
@@ -278,7 +267,6 @@ struct GSF_ConnectedPeer | |||
278 | * Handle to the PEERSTORE iterate request for peer respect value | 267 | * Handle to the PEERSTORE iterate request for peer respect value |
279 | */ | 268 | */ |
280 | struct GNUNET_PEERSTORE_IterateContext *respect_iterate_req; | 269 | struct GNUNET_PEERSTORE_IterateContext *respect_iterate_req; |
281 | |||
282 | }; | 270 | }; |
283 | 271 | ||
284 | 272 | ||
@@ -305,16 +293,16 @@ static struct GNUNET_SCHEDULER_Task *fr_task; | |||
305 | * @param latency current latency value | 293 | * @param latency current latency value |
306 | */ | 294 | */ |
307 | void | 295 | void |
308 | GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id, | 296 | GSF_update_peer_latency_(const struct GNUNET_PeerIdentity *id, |
309 | struct GNUNET_TIME_Relative latency) | 297 | struct GNUNET_TIME_Relative latency) |
310 | { | 298 | { |
311 | struct GSF_ConnectedPeer *cp; | 299 | struct GSF_ConnectedPeer *cp; |
312 | 300 | ||
313 | cp = GSF_peer_get_ (id); | 301 | cp = GSF_peer_get_(id); |
314 | if (NULL == cp) | 302 | if (NULL == cp) |
315 | return; /* we're not yet connected at the core level, ignore */ | 303 | return; /* we're not yet connected at the core level, ignore */ |
316 | GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, | 304 | GNUNET_LOAD_value_set_decline(cp->ppd.transmission_delay, |
317 | latency); | 305 | latency); |
318 | } | 306 | } |
319 | 307 | ||
320 | 308 | ||
@@ -325,7 +313,7 @@ GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id, | |||
325 | * @return performance data record for the peer | 313 | * @return performance data record for the peer |
326 | */ | 314 | */ |
327 | struct GSF_PeerPerformanceData * | 315 | struct GSF_PeerPerformanceData * |
328 | GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp) | 316 | GSF_get_peer_performance_data_(struct GSF_ConnectedPeer *cp) |
329 | { | 317 | { |
330 | return &cp->ppd; | 318 | return &cp->ppd; |
331 | } | 319 | } |
@@ -337,7 +325,7 @@ GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp) | |||
337 | * @param cp which peer to send a message to | 325 | * @param cp which peer to send a message to |
338 | */ | 326 | */ |
339 | static void | 327 | static void |
340 | peer_transmit (struct GSF_ConnectedPeer *cp); | 328 | peer_transmit(struct GSF_ConnectedPeer *cp); |
341 | 329 | ||
342 | 330 | ||
343 | /** | 331 | /** |
@@ -351,10 +339,10 @@ peer_transmit (struct GSF_ConnectedPeer *cp); | |||
351 | * long should the client wait until re-trying? | 339 | * long should the client wait until re-trying? |
352 | */ | 340 | */ |
353 | static void | 341 | static void |
354 | ats_reserve_callback (void *cls, | 342 | ats_reserve_callback(void *cls, |
355 | const struct GNUNET_PeerIdentity *peer, | 343 | const struct GNUNET_PeerIdentity *peer, |
356 | int32_t amount, | 344 | int32_t amount, |
357 | struct GNUNET_TIME_Relative res_delay); | 345 | struct GNUNET_TIME_Relative res_delay); |
358 | 346 | ||
359 | 347 | ||
360 | /** | 348 | /** |
@@ -364,42 +352,42 @@ ats_reserve_callback (void *cls, | |||
364 | * @param pth transmission handle to schedule | 352 | * @param pth transmission handle to schedule |
365 | */ | 353 | */ |
366 | static void | 354 | static void |
367 | schedule_transmission (struct GSF_PeerTransmitHandle *pth) | 355 | schedule_transmission(struct GSF_PeerTransmitHandle *pth) |
368 | { | 356 | { |
369 | struct GSF_ConnectedPeer *cp; | 357 | struct GSF_ConnectedPeer *cp; |
370 | struct GNUNET_PeerIdentity target; | 358 | struct GNUNET_PeerIdentity target; |
371 | 359 | ||
372 | cp = pth->cp; | 360 | cp = pth->cp; |
373 | GNUNET_assert (0 != cp->ppd.pid); | 361 | GNUNET_assert(0 != cp->ppd.pid); |
374 | GNUNET_PEER_resolve (cp->ppd.pid, &target); | 362 | GNUNET_PEER_resolve(cp->ppd.pid, &target); |
375 | 363 | ||
376 | if (0 != cp->inc_preference) | 364 | if (0 != cp->inc_preference) |
377 | { | 365 | { |
378 | GNUNET_ATS_performance_change_preference (GSF_ats, | 366 | GNUNET_ATS_performance_change_preference(GSF_ats, |
379 | &target, | 367 | &target, |
380 | GNUNET_ATS_PREFERENCE_BANDWIDTH, | 368 | GNUNET_ATS_PREFERENCE_BANDWIDTH, |
381 | (double) cp->inc_preference, | 369 | (double)cp->inc_preference, |
382 | GNUNET_ATS_PREFERENCE_END); | 370 | GNUNET_ATS_PREFERENCE_END); |
383 | cp->inc_preference = 0; | 371 | cp->inc_preference = 0; |
384 | } | 372 | } |
385 | 373 | ||
386 | if ( (GNUNET_YES == pth->is_query) && | 374 | if ((GNUNET_YES == pth->is_query) && |
387 | (GNUNET_YES != pth->was_reserved) ) | 375 | (GNUNET_YES != pth->was_reserved)) |
388 | { | 376 | { |
389 | /* query, need reservation */ | 377 | /* query, need reservation */ |
390 | if (GNUNET_YES != cp->did_reserve) | 378 | if (GNUNET_YES != cp->did_reserve) |
391 | return; /* not ready */ | 379 | return; /* not ready */ |
392 | cp->did_reserve = GNUNET_NO; | 380 | cp->did_reserve = GNUNET_NO; |
393 | /* reservation already done! */ | 381 | /* reservation already done! */ |
394 | pth->was_reserved = GNUNET_YES; | 382 | pth->was_reserved = GNUNET_YES; |
395 | cp->rc = GNUNET_ATS_reserve_bandwidth (GSF_ats, | 383 | cp->rc = GNUNET_ATS_reserve_bandwidth(GSF_ats, |
396 | &target, | 384 | &target, |
397 | DBLOCK_SIZE, | 385 | DBLOCK_SIZE, |
398 | &ats_reserve_callback, | 386 | &ats_reserve_callback, |
399 | cp); | 387 | cp); |
400 | return; | 388 | return; |
401 | } | 389 | } |
402 | peer_transmit (cp); | 390 | peer_transmit(cp); |
403 | } | 391 | } |
404 | 392 | ||
405 | 393 | ||
@@ -409,38 +397,38 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth) | |||
409 | * @param cp which peer to send a message to | 397 | * @param cp which peer to send a message to |
410 | */ | 398 | */ |
411 | static void | 399 | static void |
412 | peer_transmit (struct GSF_ConnectedPeer *cp) | 400 | peer_transmit(struct GSF_ConnectedPeer *cp) |
413 | { | 401 | { |
414 | struct GSF_PeerTransmitHandle *pth = cp->pth_head; | 402 | struct GSF_PeerTransmitHandle *pth = cp->pth_head; |
415 | struct GSF_PeerTransmitHandle *pos; | 403 | struct GSF_PeerTransmitHandle *pos; |
416 | 404 | ||
417 | if (NULL == pth) | 405 | if (NULL == pth) |
418 | return; | 406 | return; |
419 | GNUNET_CONTAINER_DLL_remove (cp->pth_head, | 407 | GNUNET_CONTAINER_DLL_remove(cp->pth_head, |
420 | cp->pth_tail, | 408 | cp->pth_tail, |
421 | pth); | 409 | pth); |
422 | if (GNUNET_YES == pth->is_query) | 410 | if (GNUNET_YES == pth->is_query) |
423 | { | 411 | { |
424 | cp->ppd.last_request_times[(cp->last_request_times_off++) % | 412 | cp->ppd.last_request_times[(cp->last_request_times_off++) % |
425 | MAX_QUEUE_PER_PEER] = | 413 | MAX_QUEUE_PER_PEER] = |
426 | GNUNET_TIME_absolute_get (); | 414 | GNUNET_TIME_absolute_get(); |
427 | GNUNET_assert (0 < cp->ppd.pending_queries--); | 415 | GNUNET_assert(0 < cp->ppd.pending_queries--); |
428 | } | 416 | } |
429 | else if (GNUNET_NO == pth->is_query) | 417 | else if (GNUNET_NO == pth->is_query) |
430 | { | 418 | { |
431 | GNUNET_assert (0 < cp->ppd.pending_replies--); | 419 | GNUNET_assert(0 < cp->ppd.pending_replies--); |
432 | } | 420 | } |
433 | GNUNET_LOAD_update (cp->ppd.transmission_delay, | 421 | GNUNET_LOAD_update(cp->ppd.transmission_delay, |
434 | GNUNET_TIME_absolute_get_duration | 422 | GNUNET_TIME_absolute_get_duration |
435 | (pth->transmission_request_start_time).rel_value_us); | 423 | (pth->transmission_request_start_time).rel_value_us); |
436 | GNUNET_MQ_send (cp->mq, | 424 | GNUNET_MQ_send(cp->mq, |
437 | pth->env); | 425 | pth->env); |
438 | GNUNET_free (pth); | 426 | GNUNET_free(pth); |
439 | if (NULL != (pos = cp->pth_head)) | 427 | if (NULL != (pos = cp->pth_head)) |
440 | { | 428 | { |
441 | GNUNET_assert (pos != pth); | 429 | GNUNET_assert(pos != pth); |
442 | schedule_transmission (pos); | 430 | schedule_transmission(pos); |
443 | } | 431 | } |
444 | } | 432 | } |
445 | 433 | ||
446 | 434 | ||
@@ -450,18 +438,18 @@ peer_transmit (struct GSF_ConnectedPeer *cp) | |||
450 | * @param cls the `struct GSF_ConnectedPeer` to reserve from | 438 | * @param cls the `struct GSF_ConnectedPeer` to reserve from |
451 | */ | 439 | */ |
452 | static void | 440 | static void |
453 | retry_reservation (void *cls) | 441 | retry_reservation(void *cls) |
454 | { | 442 | { |
455 | struct GSF_ConnectedPeer *cp = cls; | 443 | struct GSF_ConnectedPeer *cp = cls; |
456 | struct GNUNET_PeerIdentity target; | 444 | struct GNUNET_PeerIdentity target; |
457 | 445 | ||
458 | GNUNET_PEER_resolve (cp->ppd.pid, &target); | 446 | GNUNET_PEER_resolve(cp->ppd.pid, &target); |
459 | cp->rc_delay_task = NULL; | 447 | cp->rc_delay_task = NULL; |
460 | cp->rc = | 448 | cp->rc = |
461 | GNUNET_ATS_reserve_bandwidth (GSF_ats, | 449 | GNUNET_ATS_reserve_bandwidth(GSF_ats, |
462 | &target, | 450 | &target, |
463 | DBLOCK_SIZE, | 451 | DBLOCK_SIZE, |
464 | &ats_reserve_callback, cp); | 452 | &ats_reserve_callback, cp); |
465 | } | 453 | } |
466 | 454 | ||
467 | 455 | ||
@@ -476,34 +464,34 @@ retry_reservation (void *cls) | |||
476 | * long should the client wait until re-trying? | 464 | * long should the client wait until re-trying? |
477 | */ | 465 | */ |
478 | static void | 466 | static void |
479 | ats_reserve_callback (void *cls, | 467 | ats_reserve_callback(void *cls, |
480 | const struct GNUNET_PeerIdentity *peer, | 468 | const struct GNUNET_PeerIdentity *peer, |
481 | int32_t amount, | 469 | int32_t amount, |
482 | struct GNUNET_TIME_Relative res_delay) | 470 | struct GNUNET_TIME_Relative res_delay) |
483 | { | 471 | { |
484 | struct GSF_ConnectedPeer *cp = cls; | 472 | struct GSF_ConnectedPeer *cp = cls; |
485 | struct GSF_PeerTransmitHandle *pth; | 473 | struct GSF_PeerTransmitHandle *pth; |
486 | 474 | ||
487 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 475 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
488 | "Reserved %d bytes / need to wait %s for reservation\n", | 476 | "Reserved %d bytes / need to wait %s for reservation\n", |
489 | (int) amount, | 477 | (int)amount, |
490 | GNUNET_STRINGS_relative_time_to_string (res_delay, GNUNET_YES)); | 478 | GNUNET_STRINGS_relative_time_to_string(res_delay, GNUNET_YES)); |
491 | cp->rc = NULL; | 479 | cp->rc = NULL; |
492 | if (0 == amount) | 480 | if (0 == amount) |
493 | { | 481 | { |
494 | cp->rc_delay_task = | 482 | cp->rc_delay_task = |
495 | GNUNET_SCHEDULER_add_delayed (res_delay, | 483 | GNUNET_SCHEDULER_add_delayed(res_delay, |
496 | &retry_reservation, | 484 | &retry_reservation, |
497 | cp); | 485 | cp); |
498 | return; | 486 | return; |
499 | } | 487 | } |
500 | cp->did_reserve = GNUNET_YES; | 488 | cp->did_reserve = GNUNET_YES; |
501 | pth = cp->pth_head; | 489 | pth = cp->pth_head; |
502 | if (NULL != pth) | 490 | if (NULL != pth) |
503 | { | 491 | { |
504 | /* reservation success, try transmission now! */ | 492 | /* reservation success, try transmission now! */ |
505 | peer_transmit (cp); | 493 | peer_transmit(cp); |
506 | } | 494 | } |
507 | } | 495 | } |
508 | 496 | ||
509 | 497 | ||
@@ -515,22 +503,22 @@ ats_reserve_callback (void *cls, | |||
515 | * @param emsg error message, or NULL if no errors | 503 | * @param emsg error message, or NULL if no errors |
516 | */ | 504 | */ |
517 | static void | 505 | static void |
518 | peer_respect_cb (void *cls, | 506 | peer_respect_cb(void *cls, |
519 | const struct GNUNET_PEERSTORE_Record *record, | 507 | const struct GNUNET_PEERSTORE_Record *record, |
520 | const char *emsg) | 508 | const char *emsg) |
521 | { | 509 | { |
522 | struct GSF_ConnectedPeer *cp = cls; | 510 | struct GSF_ConnectedPeer *cp = cls; |
523 | 511 | ||
524 | GNUNET_assert (NULL != cp->respect_iterate_req); | 512 | GNUNET_assert(NULL != cp->respect_iterate_req); |
525 | if ( (NULL != record) && | 513 | if ((NULL != record) && |
526 | (sizeof (cp->disk_respect) == record->value_size)) | 514 | (sizeof(cp->disk_respect) == record->value_size)) |
527 | { | 515 | { |
528 | cp->disk_respect = *((uint32_t *)record->value); | 516 | cp->disk_respect = *((uint32_t *)record->value); |
529 | cp->ppd.respect += *((uint32_t *)record->value); | 517 | cp->ppd.respect += *((uint32_t *)record->value); |
530 | } | 518 | } |
531 | GSF_push_start_ (cp); | 519 | GSF_push_start_(cp); |
532 | if (NULL != record) | 520 | if (NULL != record) |
533 | GNUNET_PEERSTORE_iterate_cancel (cp->respect_iterate_req); | 521 | GNUNET_PEERSTORE_iterate_cancel(cp->respect_iterate_req); |
534 | cp->respect_iterate_req = NULL; | 522 | cp->respect_iterate_req = NULL; |
535 | } | 523 | } |
536 | 524 | ||
@@ -546,27 +534,27 @@ peer_respect_cb (void *cls, | |||
546 | * @return #GNUNET_YES to continue to iterate | 534 | * @return #GNUNET_YES to continue to iterate |
547 | */ | 535 | */ |
548 | static int | 536 | static int |
549 | consider_peer_for_forwarding (void *cls, | 537 | consider_peer_for_forwarding(void *cls, |
550 | const struct GNUNET_HashCode *key, | 538 | const struct GNUNET_HashCode *key, |
551 | struct GSF_PendingRequest *pr) | 539 | struct GSF_PendingRequest *pr) |
552 | { | 540 | { |
553 | struct GSF_ConnectedPeer *cp = cls; | 541 | struct GSF_ConnectedPeer *cp = cls; |
554 | struct GNUNET_PeerIdentity pid; | 542 | struct GNUNET_PeerIdentity pid; |
555 | 543 | ||
556 | if (GNUNET_YES != | 544 | if (GNUNET_YES != |
557 | GSF_pending_request_test_active_ (pr)) | 545 | GSF_pending_request_test_active_(pr)) |
558 | return GNUNET_YES; /* request is not actually active, skip! */ | 546 | return GNUNET_YES; /* request is not actually active, skip! */ |
559 | GSF_connected_peer_get_identity_ (cp, &pid); | 547 | GSF_connected_peer_get_identity_(cp, &pid); |
560 | if (GNUNET_YES != | 548 | if (GNUNET_YES != |
561 | GSF_pending_request_test_target_ (pr, &pid)) | 549 | GSF_pending_request_test_target_(pr, &pid)) |
562 | { | 550 | { |
563 | GNUNET_STATISTICS_update (GSF_stats, | 551 | GNUNET_STATISTICS_update(GSF_stats, |
564 | gettext_noop ("# Loopback routes suppressed"), | 552 | gettext_noop("# Loopback routes suppressed"), |
565 | 1, | 553 | 1, |
566 | GNUNET_NO); | 554 | GNUNET_NO); |
567 | return GNUNET_YES; | 555 | return GNUNET_YES; |
568 | } | 556 | } |
569 | GSF_plan_add_ (cp, pr); | 557 | GSF_plan_add_(cp, pr); |
570 | return GNUNET_YES; | 558 | return GNUNET_YES; |
571 | } | 559 | } |
572 | 560 | ||
@@ -581,49 +569,49 @@ consider_peer_for_forwarding (void *cls, | |||
581 | * @return our internal handle for the peer | 569 | * @return our internal handle for the peer |
582 | */ | 570 | */ |
583 | void * | 571 | void * |
584 | GSF_peer_connect_handler (void *cls, | 572 | GSF_peer_connect_handler(void *cls, |
585 | const struct GNUNET_PeerIdentity *peer, | 573 | const struct GNUNET_PeerIdentity *peer, |
586 | struct GNUNET_MQ_Handle *mq) | 574 | struct GNUNET_MQ_Handle *mq) |
587 | { | 575 | { |
588 | struct GSF_ConnectedPeer *cp; | 576 | struct GSF_ConnectedPeer *cp; |
589 | 577 | ||
590 | if (0 == | 578 | if (0 == |
591 | GNUNET_memcmp (&GSF_my_id, | 579 | GNUNET_memcmp(&GSF_my_id, |
592 | peer)) | 580 | peer)) |
593 | return NULL; | 581 | return NULL; |
594 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 582 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
595 | "Connected to peer %s\n", | 583 | "Connected to peer %s\n", |
596 | GNUNET_i2s (peer)); | 584 | GNUNET_i2s(peer)); |
597 | cp = GNUNET_new (struct GSF_ConnectedPeer); | 585 | cp = GNUNET_new(struct GSF_ConnectedPeer); |
598 | cp->ppd.pid = GNUNET_PEER_intern (peer); | 586 | cp->ppd.pid = GNUNET_PEER_intern(peer); |
599 | cp->ppd.peer = peer; | 587 | cp->ppd.peer = peer; |
600 | cp->mq = mq; | 588 | cp->mq = mq; |
601 | cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); | 589 | cp->ppd.transmission_delay = GNUNET_LOAD_value_init(GNUNET_TIME_UNIT_ZERO); |
602 | cp->rc = | 590 | cp->rc = |
603 | GNUNET_ATS_reserve_bandwidth (GSF_ats, | 591 | GNUNET_ATS_reserve_bandwidth(GSF_ats, |
604 | peer, | 592 | peer, |
605 | DBLOCK_SIZE, | 593 | DBLOCK_SIZE, |
606 | &ats_reserve_callback, cp); | 594 | &ats_reserve_callback, cp); |
607 | cp->request_map = GNUNET_CONTAINER_multihashmap_create (128, | 595 | cp->request_map = GNUNET_CONTAINER_multihashmap_create(128, |
608 | GNUNET_YES); | 596 | GNUNET_YES); |
609 | GNUNET_break (GNUNET_OK == | 597 | GNUNET_break(GNUNET_OK == |
610 | GNUNET_CONTAINER_multipeermap_put (cp_map, | 598 | GNUNET_CONTAINER_multipeermap_put(cp_map, |
611 | GSF_connected_peer_get_identity2_ (cp), | 599 | GSF_connected_peer_get_identity2_(cp), |
612 | cp, | 600 | cp, |
613 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 601 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
614 | GNUNET_STATISTICS_set (GSF_stats, | 602 | GNUNET_STATISTICS_set(GSF_stats, |
615 | gettext_noop ("# peers connected"), | 603 | gettext_noop("# peers connected"), |
616 | GNUNET_CONTAINER_multipeermap_size (cp_map), | 604 | GNUNET_CONTAINER_multipeermap_size(cp_map), |
617 | GNUNET_NO); | 605 | GNUNET_NO); |
618 | cp->respect_iterate_req | 606 | cp->respect_iterate_req |
619 | = GNUNET_PEERSTORE_iterate (peerstore, | 607 | = GNUNET_PEERSTORE_iterate(peerstore, |
620 | "fs", | 608 | "fs", |
621 | peer, | 609 | peer, |
622 | "respect", | 610 | "respect", |
623 | &peer_respect_cb, | 611 | &peer_respect_cb, |
612 | cp); | ||
613 | GSF_iterate_pending_requests_(&consider_peer_for_forwarding, | ||
624 | cp); | 614 | cp); |
625 | GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, | ||
626 | cp); | ||
627 | return cp; | 615 | return cp; |
628 | } | 616 | } |
629 | 617 | ||
@@ -635,21 +623,21 @@ GSF_peer_connect_handler (void *cls, | |||
635 | * @param cls the `struct GSF_ConnectedPeer` | 623 | * @param cls the `struct GSF_ConnectedPeer` |
636 | */ | 624 | */ |
637 | static void | 625 | static void |
638 | revive_migration (void *cls) | 626 | revive_migration(void *cls) |
639 | { | 627 | { |
640 | struct GSF_ConnectedPeer *cp = cls; | 628 | struct GSF_ConnectedPeer *cp = cls; |
641 | struct GNUNET_TIME_Relative bt; | 629 | struct GNUNET_TIME_Relative bt; |
642 | 630 | ||
643 | cp->mig_revive_task = NULL; | 631 | cp->mig_revive_task = NULL; |
644 | bt = GNUNET_TIME_absolute_get_remaining (cp->ppd.migration_blocked_until); | 632 | bt = GNUNET_TIME_absolute_get_remaining(cp->ppd.migration_blocked_until); |
645 | if (0 != bt.rel_value_us) | 633 | if (0 != bt.rel_value_us) |
646 | { | 634 | { |
647 | /* still time left... */ | 635 | /* still time left... */ |
648 | cp->mig_revive_task = | 636 | cp->mig_revive_task = |
649 | GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp); | 637 | GNUNET_SCHEDULER_add_delayed(bt, &revive_migration, cp); |
650 | return; | 638 | return; |
651 | } | 639 | } |
652 | GSF_push_start_ (cp); | 640 | GSF_push_start_(cp); |
653 | } | 641 | } |
654 | 642 | ||
655 | 643 | ||
@@ -660,44 +648,44 @@ revive_migration (void *cls) | |||
660 | * @return NULL if the peer is not currently connected | 648 | * @return NULL if the peer is not currently connected |
661 | */ | 649 | */ |
662 | struct GSF_ConnectedPeer * | 650 | struct GSF_ConnectedPeer * |
663 | GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer) | 651 | GSF_peer_get_(const struct GNUNET_PeerIdentity *peer) |
664 | { | 652 | { |
665 | if (NULL == cp_map) | 653 | if (NULL == cp_map) |
666 | return NULL; | 654 | return NULL; |
667 | return GNUNET_CONTAINER_multipeermap_get (cp_map, peer); | 655 | return GNUNET_CONTAINER_multipeermap_get(cp_map, peer); |
668 | } | 656 | } |
669 | 657 | ||
670 | 658 | ||
671 | /** | 659 | /** |
672 | * Handle P2P #GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP message. | 660 | * Handle P2P #GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP message. |
673 | * | 661 | * |
674 | * @param cls closure, the `struct GSF_ConnectedPeer` | 662 | * @param cls closure, the `struct GSF_ConnectedPeer` |
675 | * @param msm the actual message | 663 | * @param msm the actual message |
676 | */ | 664 | */ |
677 | void | 665 | void |
678 | handle_p2p_migration_stop (void *cls, | 666 | handle_p2p_migration_stop(void *cls, |
679 | const struct MigrationStopMessage *msm) | 667 | const struct MigrationStopMessage *msm) |
680 | { | 668 | { |
681 | struct GSF_ConnectedPeer *cp = cls; | 669 | struct GSF_ConnectedPeer *cp = cls; |
682 | struct GNUNET_TIME_Relative bt; | 670 | struct GNUNET_TIME_Relative bt; |
683 | 671 | ||
684 | GNUNET_STATISTICS_update (GSF_stats, | 672 | GNUNET_STATISTICS_update(GSF_stats, |
685 | gettext_noop ("# migration stop messages received"), | 673 | gettext_noop("# migration stop messages received"), |
686 | 1, GNUNET_NO); | 674 | 1, GNUNET_NO); |
687 | bt = GNUNET_TIME_relative_ntoh (msm->duration); | 675 | bt = GNUNET_TIME_relative_ntoh(msm->duration); |
688 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 676 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
689 | _("Migration of content to peer `%s' blocked for %s\n"), | 677 | _("Migration of content to peer `%s' blocked for %s\n"), |
690 | GNUNET_i2s (cp->ppd.peer), | 678 | GNUNET_i2s(cp->ppd.peer), |
691 | GNUNET_STRINGS_relative_time_to_string (bt, GNUNET_YES)); | 679 | GNUNET_STRINGS_relative_time_to_string(bt, GNUNET_YES)); |
692 | cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute (bt); | 680 | cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute(bt); |
693 | if ( (NULL == cp->mig_revive_task) && | 681 | if ((NULL == cp->mig_revive_task) && |
694 | (NULL == cp->respect_iterate_req) ) | 682 | (NULL == cp->respect_iterate_req)) |
695 | { | 683 | { |
696 | GSF_push_stop_ (cp); | 684 | GSF_push_stop_(cp); |
697 | cp->mig_revive_task = | 685 | cp->mig_revive_task = |
698 | GNUNET_SCHEDULER_add_delayed (bt, | 686 | GNUNET_SCHEDULER_add_delayed(bt, |
699 | &revive_migration, cp); | 687 | &revive_migration, cp); |
700 | } | 688 | } |
701 | } | 689 | } |
702 | 690 | ||
703 | 691 | ||
@@ -707,26 +695,26 @@ handle_p2p_migration_stop (void *cls, | |||
707 | * @param peerreq request to free | 695 | * @param peerreq request to free |
708 | */ | 696 | */ |
709 | static void | 697 | static void |
710 | free_pending_request (struct PeerRequest *peerreq) | 698 | free_pending_request(struct PeerRequest *peerreq) |
711 | { | 699 | { |
712 | struct GSF_ConnectedPeer *cp = peerreq->cp; | 700 | struct GSF_ConnectedPeer *cp = peerreq->cp; |
713 | struct GSF_PendingRequestData *prd; | 701 | struct GSF_PendingRequestData *prd; |
714 | 702 | ||
715 | prd = GSF_pending_request_get_data_ (peerreq->pr); | 703 | prd = GSF_pending_request_get_data_(peerreq->pr); |
716 | if (NULL != peerreq->kill_task) | 704 | if (NULL != peerreq->kill_task) |
717 | { | 705 | { |
718 | GNUNET_SCHEDULER_cancel (peerreq->kill_task); | 706 | GNUNET_SCHEDULER_cancel(peerreq->kill_task); |
719 | peerreq->kill_task = NULL; | 707 | peerreq->kill_task = NULL; |
720 | } | 708 | } |
721 | GNUNET_STATISTICS_update (GSF_stats, | 709 | GNUNET_STATISTICS_update(GSF_stats, |
722 | gettext_noop ("# P2P searches active"), | 710 | gettext_noop("# P2P searches active"), |
723 | -1, | 711 | -1, |
724 | GNUNET_NO); | 712 | GNUNET_NO); |
725 | GNUNET_break (GNUNET_YES == | 713 | GNUNET_break(GNUNET_YES == |
726 | GNUNET_CONTAINER_multihashmap_remove (cp->request_map, | 714 | GNUNET_CONTAINER_multihashmap_remove(cp->request_map, |
727 | &prd->query, | 715 | &prd->query, |
728 | peerreq)); | 716 | peerreq)); |
729 | GNUNET_free (peerreq); | 717 | GNUNET_free(peerreq); |
730 | } | 718 | } |
731 | 719 | ||
732 | 720 | ||
@@ -739,16 +727,16 @@ free_pending_request (struct PeerRequest *peerreq) | |||
739 | * @return #GNUNET_YES (continue to iterate) | 727 | * @return #GNUNET_YES (continue to iterate) |
740 | */ | 728 | */ |
741 | static int | 729 | static int |
742 | cancel_pending_request (void *cls, | 730 | cancel_pending_request(void *cls, |
743 | const struct GNUNET_HashCode *query, | 731 | const struct GNUNET_HashCode *query, |
744 | void *value) | 732 | void *value) |
745 | { | 733 | { |
746 | struct PeerRequest *peerreq = value; | 734 | struct PeerRequest *peerreq = value; |
747 | struct GSF_PendingRequest *pr = peerreq->pr; | 735 | struct GSF_PendingRequest *pr = peerreq->pr; |
748 | 736 | ||
749 | free_pending_request (peerreq); | 737 | free_pending_request(peerreq); |
750 | GSF_pending_request_cancel_ (pr, | 738 | GSF_pending_request_cancel_(pr, |
751 | GNUNET_NO); | 739 | GNUNET_NO); |
752 | return GNUNET_OK; | 740 | return GNUNET_OK; |
753 | } | 741 | } |
754 | 742 | ||
@@ -759,17 +747,17 @@ cancel_pending_request (void *cls, | |||
759 | * @param cls the request to free | 747 | * @param cls the request to free |
760 | */ | 748 | */ |
761 | static void | 749 | static void |
762 | peer_request_destroy (void *cls) | 750 | peer_request_destroy(void *cls) |
763 | { | 751 | { |
764 | struct PeerRequest *peerreq = cls; | 752 | struct PeerRequest *peerreq = cls; |
765 | struct GSF_PendingRequest *pr = peerreq->pr; | 753 | struct GSF_PendingRequest *pr = peerreq->pr; |
766 | struct GSF_PendingRequestData *prd; | 754 | struct GSF_PendingRequestData *prd; |
767 | 755 | ||
768 | peerreq->kill_task = NULL; | 756 | peerreq->kill_task = NULL; |
769 | prd = GSF_pending_request_get_data_ (pr); | 757 | prd = GSF_pending_request_get_data_(pr); |
770 | cancel_pending_request (NULL, | 758 | cancel_pending_request(NULL, |
771 | &prd->query, | 759 | &prd->query, |
772 | peerreq); | 760 | peerreq); |
773 | } | 761 | } |
774 | 762 | ||
775 | 763 | ||
@@ -779,20 +767,20 @@ peer_request_destroy (void *cls) | |||
779 | * @param cls the `struct GSF_DelayedHandle` with the message | 767 | * @param cls the `struct GSF_DelayedHandle` with the message |
780 | */ | 768 | */ |
781 | static void | 769 | static void |
782 | transmit_delayed_now (void *cls) | 770 | transmit_delayed_now(void *cls) |
783 | { | 771 | { |
784 | struct GSF_DelayedHandle *dh = cls; | 772 | struct GSF_DelayedHandle *dh = cls; |
785 | struct GSF_ConnectedPeer *cp = dh->cp; | 773 | struct GSF_ConnectedPeer *cp = dh->cp; |
786 | 774 | ||
787 | GNUNET_CONTAINER_DLL_remove (cp->delayed_head, | 775 | GNUNET_CONTAINER_DLL_remove(cp->delayed_head, |
788 | cp->delayed_tail, | 776 | cp->delayed_tail, |
789 | dh); | 777 | dh); |
790 | cp->delay_queue_size--; | 778 | cp->delay_queue_size--; |
791 | GSF_peer_transmit_ (cp, | 779 | GSF_peer_transmit_(cp, |
792 | GNUNET_NO, | 780 | GNUNET_NO, |
793 | UINT32_MAX, | 781 | UINT32_MAX, |
794 | dh->env); | 782 | dh->env); |
795 | GNUNET_free (dh); | 783 | GNUNET_free(dh); |
796 | } | 784 | } |
797 | 785 | ||
798 | 786 | ||
@@ -802,20 +790,20 @@ transmit_delayed_now (void *cls) | |||
802 | * @return desired delay | 790 | * @return desired delay |
803 | */ | 791 | */ |
804 | static struct GNUNET_TIME_Relative | 792 | static struct GNUNET_TIME_Relative |
805 | get_randomized_delay () | 793 | get_randomized_delay() |
806 | { | 794 | { |
807 | struct GNUNET_TIME_Relative ret; | 795 | struct GNUNET_TIME_Relative ret; |
808 | 796 | ||
809 | ret = | 797 | ret = |
810 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 798 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, |
811 | GNUNET_CRYPTO_random_u32 | 799 | GNUNET_CRYPTO_random_u32 |
812 | (GNUNET_CRYPTO_QUALITY_WEAK, | 800 | (GNUNET_CRYPTO_QUALITY_WEAK, |
813 | 2 * GSF_avg_latency.rel_value_us + 1)); | 801 | 2 * GSF_avg_latency.rel_value_us + 1)); |
814 | #if INSANE_STATISTICS | 802 | #if INSANE_STATISTICS |
815 | GNUNET_STATISTICS_update (GSF_stats, | 803 | GNUNET_STATISTICS_update(GSF_stats, |
816 | gettext_noop | 804 | gettext_noop |
817 | ("# artificial delays introduced (ms)"), | 805 | ("# artificial delays introduced (ms)"), |
818 | ret.rel_value_us / 1000LL, GNUNET_NO); | 806 | ret.rel_value_us / 1000LL, GNUNET_NO); |
819 | #endif | 807 | #endif |
820 | return ret; | 808 | return ret; |
821 | } | 809 | } |
@@ -840,15 +828,15 @@ get_randomized_delay () | |||
840 | * @param data_len number of bytes in @a data | 828 | * @param data_len number of bytes in @a data |
841 | */ | 829 | */ |
842 | static void | 830 | static void |
843 | handle_p2p_reply (void *cls, | 831 | handle_p2p_reply(void *cls, |
844 | enum GNUNET_BLOCK_EvaluationResult eval, | 832 | enum GNUNET_BLOCK_EvaluationResult eval, |
845 | struct GSF_PendingRequest *pr, | 833 | struct GSF_PendingRequest *pr, |
846 | uint32_t reply_anonymity_level, | 834 | uint32_t reply_anonymity_level, |
847 | struct GNUNET_TIME_Absolute expiration, | 835 | struct GNUNET_TIME_Absolute expiration, |
848 | struct GNUNET_TIME_Absolute last_transmission, | 836 | struct GNUNET_TIME_Absolute last_transmission, |
849 | enum GNUNET_BLOCK_Type type, | 837 | enum GNUNET_BLOCK_Type type, |
850 | const void *data, | 838 | const void *data, |
851 | size_t data_len) | 839 | size_t data_len) |
852 | { | 840 | { |
853 | struct PeerRequest *peerreq = cls; | 841 | struct PeerRequest *peerreq = cls; |
854 | struct GSF_ConnectedPeer *cp = peerreq->cp; | 842 | struct GSF_ConnectedPeer *cp = peerreq->cp; |
@@ -857,96 +845,96 @@ handle_p2p_reply (void *cls, | |||
857 | struct PutMessage *pm; | 845 | struct PutMessage *pm; |
858 | size_t msize; | 846 | size_t msize; |
859 | 847 | ||
860 | GNUNET_assert (data_len + sizeof (struct PutMessage) < | 848 | GNUNET_assert(data_len + sizeof(struct PutMessage) < |
861 | GNUNET_MAX_MESSAGE_SIZE); | 849 | GNUNET_MAX_MESSAGE_SIZE); |
862 | GNUNET_assert (peerreq->pr == pr); | 850 | GNUNET_assert(peerreq->pr == pr); |
863 | prd = GSF_pending_request_get_data_ (pr); | 851 | prd = GSF_pending_request_get_data_(pr); |
864 | if (NULL == data) | 852 | if (NULL == data) |
865 | { | 853 | { |
866 | free_pending_request (peerreq); | 854 | free_pending_request(peerreq); |
867 | return; | 855 | return; |
868 | } | 856 | } |
869 | GNUNET_break (GNUNET_BLOCK_TYPE_ANY != type); | 857 | GNUNET_break(GNUNET_BLOCK_TYPE_ANY != type); |
870 | if ((prd->type != type) && (GNUNET_BLOCK_TYPE_ANY != prd->type)) | 858 | if ((prd->type != type) && (GNUNET_BLOCK_TYPE_ANY != prd->type)) |
871 | { | 859 | { |
872 | GNUNET_STATISTICS_update (GSF_stats, | 860 | GNUNET_STATISTICS_update(GSF_stats, |
873 | gettext_noop | 861 | gettext_noop |
874 | ("# replies dropped due to type mismatch"), | 862 | ("# replies dropped due to type mismatch"), |
875 | 1, GNUNET_NO); | 863 | 1, GNUNET_NO); |
876 | return; | 864 | return; |
877 | } | 865 | } |
878 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 866 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
879 | "Transmitting result for query `%s' to peer\n", | 867 | "Transmitting result for query `%s' to peer\n", |
880 | GNUNET_h2s (&prd->query)); | 868 | GNUNET_h2s(&prd->query)); |
881 | GNUNET_STATISTICS_update (GSF_stats, | 869 | GNUNET_STATISTICS_update(GSF_stats, |
882 | gettext_noop ("# replies received for other peers"), | 870 | gettext_noop("# replies received for other peers"), |
883 | 1, GNUNET_NO); | 871 | 1, GNUNET_NO); |
884 | msize = sizeof (struct PutMessage) + data_len; | 872 | msize = sizeof(struct PutMessage) + data_len; |
885 | if (msize >= GNUNET_MAX_MESSAGE_SIZE) | 873 | if (msize >= GNUNET_MAX_MESSAGE_SIZE) |
886 | { | ||
887 | GNUNET_break (0); | ||
888 | return; | ||
889 | } | ||
890 | if ((UINT32_MAX != reply_anonymity_level) && (reply_anonymity_level > 1)) | ||
891 | { | ||
892 | if (reply_anonymity_level - 1 > GSF_cover_content_count) | ||
893 | { | 874 | { |
894 | GNUNET_STATISTICS_update (GSF_stats, | 875 | GNUNET_break(0); |
895 | gettext_noop | ||
896 | ("# replies dropped due to insufficient cover traffic"), | ||
897 | 1, GNUNET_NO); | ||
898 | return; | 876 | return; |
899 | } | 877 | } |
900 | GSF_cover_content_count -= (reply_anonymity_level - 1); | 878 | if ((UINT32_MAX != reply_anonymity_level) && (reply_anonymity_level > 1)) |
901 | } | 879 | { |
902 | 880 | if (reply_anonymity_level - 1 > GSF_cover_content_count) | |
903 | env = GNUNET_MQ_msg_extra (pm, | 881 | { |
904 | data_len, | 882 | GNUNET_STATISTICS_update(GSF_stats, |
905 | GNUNET_MESSAGE_TYPE_FS_PUT); | 883 | gettext_noop |
906 | pm->type = htonl (type); | 884 | ("# replies dropped due to insufficient cover traffic"), |
907 | pm->expiration = GNUNET_TIME_absolute_hton (expiration); | 885 | 1, GNUNET_NO); |
908 | GNUNET_memcpy (&pm[1], | 886 | return; |
909 | data, | 887 | } |
910 | data_len); | 888 | GSF_cover_content_count -= (reply_anonymity_level - 1); |
911 | if ( (UINT32_MAX != reply_anonymity_level) && | 889 | } |
912 | (0 != reply_anonymity_level) && | 890 | |
913 | (GNUNET_YES == GSF_enable_randomized_delays) ) | 891 | env = GNUNET_MQ_msg_extra(pm, |
914 | { | 892 | data_len, |
915 | struct GSF_DelayedHandle *dh; | 893 | GNUNET_MESSAGE_TYPE_FS_PUT); |
916 | 894 | pm->type = htonl(type); | |
917 | dh = GNUNET_new (struct GSF_DelayedHandle); | 895 | pm->expiration = GNUNET_TIME_absolute_hton(expiration); |
918 | dh->cp = cp; | 896 | GNUNET_memcpy(&pm[1], |
919 | dh->env = env; | 897 | data, |
920 | dh->msize = msize; | 898 | data_len); |
921 | GNUNET_CONTAINER_DLL_insert (cp->delayed_head, | 899 | if ((UINT32_MAX != reply_anonymity_level) && |
922 | cp->delayed_tail, | 900 | (0 != reply_anonymity_level) && |
923 | dh); | 901 | (GNUNET_YES == GSF_enable_randomized_delays)) |
924 | cp->delay_queue_size++; | 902 | { |
925 | dh->delay_task = | 903 | struct GSF_DelayedHandle *dh; |
926 | GNUNET_SCHEDULER_add_delayed (get_randomized_delay (), | 904 | |
927 | &transmit_delayed_now, | 905 | dh = GNUNET_new(struct GSF_DelayedHandle); |
928 | dh); | 906 | dh->cp = cp; |
929 | } | 907 | dh->env = env; |
908 | dh->msize = msize; | ||
909 | GNUNET_CONTAINER_DLL_insert(cp->delayed_head, | ||
910 | cp->delayed_tail, | ||
911 | dh); | ||
912 | cp->delay_queue_size++; | ||
913 | dh->delay_task = | ||
914 | GNUNET_SCHEDULER_add_delayed(get_randomized_delay(), | ||
915 | &transmit_delayed_now, | ||
916 | dh); | ||
917 | } | ||
930 | else | 918 | else |
931 | { | 919 | { |
932 | GSF_peer_transmit_ (cp, | 920 | GSF_peer_transmit_(cp, |
933 | GNUNET_NO, | 921 | GNUNET_NO, |
934 | UINT32_MAX, | 922 | UINT32_MAX, |
935 | env); | 923 | env); |
936 | } | 924 | } |
937 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval) | 925 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval) |
938 | return; | 926 | return; |
939 | if (NULL == peerreq->kill_task) | 927 | if (NULL == peerreq->kill_task) |
940 | { | 928 | { |
941 | GNUNET_STATISTICS_update (GSF_stats, | 929 | GNUNET_STATISTICS_update(GSF_stats, |
942 | gettext_noop | 930 | gettext_noop |
943 | ("# P2P searches destroyed due to ultimate reply"), | 931 | ("# P2P searches destroyed due to ultimate reply"), |
944 | 1, | 932 | 1, |
945 | GNUNET_NO); | 933 | GNUNET_NO); |
946 | peerreq->kill_task = | 934 | peerreq->kill_task = |
947 | GNUNET_SCHEDULER_add_now (&peer_request_destroy, | 935 | GNUNET_SCHEDULER_add_now(&peer_request_destroy, |
948 | peerreq); | 936 | peerreq); |
949 | } | 937 | } |
950 | } | 938 | } |
951 | 939 | ||
952 | 940 | ||
@@ -959,31 +947,31 @@ handle_p2p_reply (void *cls, | |||
959 | * @returns the actual change in respect (positive or negative) | 947 | * @returns the actual change in respect (positive or negative) |
960 | */ | 948 | */ |
961 | static int | 949 | static int |
962 | change_peer_respect (struct GSF_ConnectedPeer *cp, int value) | 950 | change_peer_respect(struct GSF_ConnectedPeer *cp, int value) |
963 | { | 951 | { |
964 | if (0 == value) | 952 | if (0 == value) |
965 | return 0; | 953 | return 0; |
966 | GNUNET_assert (NULL != cp); | 954 | GNUNET_assert(NULL != cp); |
967 | if (value > 0) | 955 | if (value > 0) |
968 | { | ||
969 | if (cp->ppd.respect + value < cp->ppd.respect) | ||
970 | { | 956 | { |
971 | value = UINT32_MAX - cp->ppd.respect; | 957 | if (cp->ppd.respect + value < cp->ppd.respect) |
972 | cp->ppd.respect = UINT32_MAX; | 958 | { |
959 | value = UINT32_MAX - cp->ppd.respect; | ||
960 | cp->ppd.respect = UINT32_MAX; | ||
961 | } | ||
962 | else | ||
963 | cp->ppd.respect += value; | ||
973 | } | 964 | } |
974 | else | ||
975 | cp->ppd.respect += value; | ||
976 | } | ||
977 | else | 965 | else |
978 | { | ||
979 | if (cp->ppd.respect < -value) | ||
980 | { | 966 | { |
981 | value = -cp->ppd.respect; | 967 | if (cp->ppd.respect < -value) |
982 | cp->ppd.respect = 0; | 968 | { |
969 | value = -cp->ppd.respect; | ||
970 | cp->ppd.respect = 0; | ||
971 | } | ||
972 | else | ||
973 | cp->ppd.respect += value; | ||
983 | } | 974 | } |
984 | else | ||
985 | cp->ppd.respect += value; | ||
986 | } | ||
987 | return value; | 975 | return value; |
988 | } | 976 | } |
989 | 977 | ||
@@ -997,58 +985,58 @@ change_peer_respect (struct GSF_ConnectedPeer *cp, int value) | |||
997 | * @return effective priority | 985 | * @return effective priority |
998 | */ | 986 | */ |
999 | static int32_t | 987 | static int32_t |
1000 | bound_priority (uint32_t prio_in, | 988 | bound_priority(uint32_t prio_in, |
1001 | struct GSF_ConnectedPeer *cp) | 989 | struct GSF_ConnectedPeer *cp) |
1002 | { | 990 | { |
1003 | #define N ((double)128.0) | 991 | #define N ((double)128.0) |
1004 | uint32_t ret; | 992 | uint32_t ret; |
1005 | double rret; | 993 | double rret; |
1006 | int ld; | 994 | int ld; |
1007 | 995 | ||
1008 | ld = GSF_test_get_load_too_high_ (0); | 996 | ld = GSF_test_get_load_too_high_(0); |
1009 | if (GNUNET_SYSERR == ld) | 997 | if (GNUNET_SYSERR == ld) |
1010 | { | 998 | { |
1011 | #if INSANE_STATISTICS | 999 | #if INSANE_STATISTICS |
1012 | GNUNET_STATISTICS_update (GSF_stats, | 1000 | GNUNET_STATISTICS_update(GSF_stats, |
1013 | gettext_noop | 1001 | gettext_noop |
1014 | ("# requests done for free (low load)"), 1, | 1002 | ("# requests done for free (low load)"), 1, |
1015 | GNUNET_NO); | 1003 | GNUNET_NO); |
1016 | #endif | 1004 | #endif |
1017 | return 0; /* excess resources */ | 1005 | return 0; /* excess resources */ |
1018 | } | 1006 | } |
1019 | if (prio_in > INT32_MAX) | 1007 | if (prio_in > INT32_MAX) |
1020 | prio_in = INT32_MAX; | 1008 | prio_in = INT32_MAX; |
1021 | ret = -change_peer_respect (cp, -(int) prio_in); | 1009 | ret = -change_peer_respect(cp, -(int)prio_in); |
1022 | if (ret > 0) | 1010 | if (ret > 0) |
1023 | { | 1011 | { |
1024 | if (ret > GSF_current_priorities + N) | 1012 | if (ret > GSF_current_priorities + N) |
1025 | rret = GSF_current_priorities + N; | 1013 | rret = GSF_current_priorities + N; |
1026 | else | 1014 | else |
1027 | rret = ret; | 1015 | rret = ret; |
1028 | GSF_current_priorities = (GSF_current_priorities * (N - 1) + rret) / N; | 1016 | GSF_current_priorities = (GSF_current_priorities * (N - 1) + rret) / N; |
1029 | } | 1017 | } |
1030 | if ((GNUNET_YES == ld) && (ret > 0)) | 1018 | if ((GNUNET_YES == ld) && (ret > 0)) |
1031 | { | 1019 | { |
1032 | /* try with charging */ | 1020 | /* try with charging */ |
1033 | ld = GSF_test_get_load_too_high_ (ret); | 1021 | ld = GSF_test_get_load_too_high_(ret); |
1034 | } | 1022 | } |
1035 | if (GNUNET_YES == ld) | 1023 | if (GNUNET_YES == ld) |
1036 | { | 1024 | { |
1037 | GNUNET_STATISTICS_update (GSF_stats, | 1025 | GNUNET_STATISTICS_update(GSF_stats, |
1038 | gettext_noop | 1026 | gettext_noop |
1039 | ("# request dropped, priority insufficient"), 1, | 1027 | ("# request dropped, priority insufficient"), 1, |
1040 | GNUNET_NO); | 1028 | GNUNET_NO); |
1041 | /* undo charge */ | 1029 | /* undo charge */ |
1042 | change_peer_respect (cp, (int) ret); | 1030 | change_peer_respect(cp, (int)ret); |
1043 | return -1; /* not enough resources */ | 1031 | return -1; /* not enough resources */ |
1044 | } | 1032 | } |
1045 | else | 1033 | else |
1046 | { | 1034 | { |
1047 | GNUNET_STATISTICS_update (GSF_stats, | 1035 | GNUNET_STATISTICS_update(GSF_stats, |
1048 | gettext_noop | 1036 | gettext_noop |
1049 | ("# requests done for a price (normal load)"), 1, | 1037 | ("# requests done for a price (normal load)"), 1, |
1050 | GNUNET_NO); | 1038 | GNUNET_NO); |
1051 | } | 1039 | } |
1052 | #undef N | 1040 | #undef N |
1053 | return ret; | 1041 | return ret; |
1054 | } | 1042 | } |
@@ -1064,20 +1052,20 @@ bound_priority (uint32_t prio_in, | |||
1064 | * otherwise the ttl-limit for the given @a prio | 1052 | * otherwise the ttl-limit for the given @a prio |
1065 | */ | 1053 | */ |
1066 | static int32_t | 1054 | static int32_t |
1067 | bound_ttl (int32_t ttl_in, | 1055 | bound_ttl(int32_t ttl_in, |
1068 | uint32_t prio) | 1056 | uint32_t prio) |
1069 | { | 1057 | { |
1070 | unsigned long long allowed; | 1058 | unsigned long long allowed; |
1071 | 1059 | ||
1072 | if (ttl_in <= 0) | 1060 | if (ttl_in <= 0) |
1073 | return ttl_in; | 1061 | return ttl_in; |
1074 | allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000; | 1062 | allowed = ((unsigned long long)prio) * TTL_DECREMENT / 1000; |
1075 | if (ttl_in > allowed) | 1063 | if (ttl_in > allowed) |
1076 | { | 1064 | { |
1077 | if (allowed >= (1 << 30)) | 1065 | if (allowed >= (1 << 30)) |
1078 | return 1 << 30; | 1066 | return 1 << 30; |
1079 | return allowed; | 1067 | return allowed; |
1080 | } | 1068 | } |
1081 | return ttl_in; | 1069 | return ttl_in; |
1082 | } | 1070 | } |
1083 | 1071 | ||
@@ -1085,9 +1073,7 @@ bound_ttl (int32_t ttl_in, | |||
1085 | /** | 1073 | /** |
1086 | * Closure for #test_exist_cb(). | 1074 | * Closure for #test_exist_cb(). |
1087 | */ | 1075 | */ |
1088 | struct TestExistClosure | 1076 | struct TestExistClosure { |
1089 | { | ||
1090 | |||
1091 | /** | 1077 | /** |
1092 | * Priority of the incoming request. | 1078 | * Priority of the incoming request. |
1093 | */ | 1079 | */ |
@@ -1107,7 +1093,6 @@ struct TestExistClosure | |||
1107 | * Set to #GNUNET_YES if we are done handling the query. | 1093 | * Set to #GNUNET_YES if we are done handling the query. |
1108 | */ | 1094 | */ |
1109 | int finished; | 1095 | int finished; |
1110 | |||
1111 | }; | 1096 | }; |
1112 | 1097 | ||
1113 | 1098 | ||
@@ -1122,9 +1107,9 @@ struct TestExistClosure | |||
1122 | * #GNUNET_NO if we successfully merged | 1107 | * #GNUNET_NO if we successfully merged |
1123 | */ | 1108 | */ |
1124 | static int | 1109 | static int |
1125 | test_exist_cb (void *cls, | 1110 | test_exist_cb(void *cls, |
1126 | const struct GNUNET_HashCode *hc, | 1111 | const struct GNUNET_HashCode *hc, |
1127 | void *value) | 1112 | void *value) |
1128 | { | 1113 | { |
1129 | struct TestExistClosure *tec = cls; | 1114 | struct TestExistClosure *tec = cls; |
1130 | struct PeerRequest *peerreq = value; | 1115 | struct PeerRequest *peerreq = value; |
@@ -1132,28 +1117,28 @@ test_exist_cb (void *cls, | |||
1132 | struct GSF_PendingRequestData *prd; | 1117 | struct GSF_PendingRequestData *prd; |
1133 | 1118 | ||
1134 | pr = peerreq->pr; | 1119 | pr = peerreq->pr; |
1135 | prd = GSF_pending_request_get_data_ (pr); | 1120 | prd = GSF_pending_request_get_data_(pr); |
1136 | if (prd->type != tec->type) | 1121 | if (prd->type != tec->type) |
1137 | return GNUNET_YES; | 1122 | return GNUNET_YES; |
1138 | if (prd->ttl.abs_value_us >= | 1123 | if (prd->ttl.abs_value_us >= |
1139 | GNUNET_TIME_absolute_get ().abs_value_us + tec->ttl * 1000LL) | 1124 | GNUNET_TIME_absolute_get().abs_value_us + tec->ttl * 1000LL) |
1140 | { | 1125 | { |
1141 | /* existing request has higher TTL, drop new one! */ | 1126 | /* existing request has higher TTL, drop new one! */ |
1142 | prd->priority += tec->priority; | 1127 | prd->priority += tec->priority; |
1143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1128 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1144 | "Have existing request with higher TTL, dropping new request.\n"); | 1129 | "Have existing request with higher TTL, dropping new request.\n"); |
1145 | GNUNET_STATISTICS_update (GSF_stats, | 1130 | GNUNET_STATISTICS_update(GSF_stats, |
1146 | gettext_noop | 1131 | gettext_noop |
1147 | ("# requests dropped due to higher-TTL request"), | 1132 | ("# requests dropped due to higher-TTL request"), |
1148 | 1, GNUNET_NO); | 1133 | 1, GNUNET_NO); |
1149 | tec->finished = GNUNET_YES; | 1134 | tec->finished = GNUNET_YES; |
1150 | return GNUNET_NO; | 1135 | return GNUNET_NO; |
1151 | } | 1136 | } |
1152 | /* existing request has lower TTL, drop old one! */ | 1137 | /* existing request has lower TTL, drop old one! */ |
1153 | tec->priority += prd->priority; | 1138 | tec->priority += prd->priority; |
1154 | free_pending_request (peerreq); | 1139 | free_pending_request(peerreq); |
1155 | GSF_pending_request_cancel_ (pr, | 1140 | GSF_pending_request_cancel_(pr, |
1156 | GNUNET_YES); | 1141 | GNUNET_YES); |
1157 | return GNUNET_NO; | 1142 | return GNUNET_NO; |
1158 | } | 1143 | } |
1159 | 1144 | ||
@@ -1168,8 +1153,8 @@ test_exist_cb (void *cls, | |||
1168 | * @param gm the GET message | 1153 | * @param gm the GET message |
1169 | */ | 1154 | */ |
1170 | void | 1155 | void |
1171 | handle_p2p_get (void *cls, | 1156 | handle_p2p_get(void *cls, |
1172 | const struct GetMessage *gm) | 1157 | const struct GetMessage *gm) |
1173 | { | 1158 | { |
1174 | struct GSF_ConnectedPeer *cps = cls; | 1159 | struct GSF_ConnectedPeer *cps = cls; |
1175 | struct PeerRequest *peerreq; | 1160 | struct PeerRequest *peerreq; |
@@ -1187,167 +1172,167 @@ handle_p2p_get (void *cls, | |||
1187 | GNUNET_PEER_Id spid; | 1172 | GNUNET_PEER_Id spid; |
1188 | const struct GSF_PendingRequestData *prd; | 1173 | const struct GSF_PendingRequestData *prd; |
1189 | 1174 | ||
1190 | msize = ntohs (gm->header.size); | 1175 | msize = ntohs(gm->header.size); |
1191 | tec.type = ntohl (gm->type); | 1176 | tec.type = ntohl(gm->type); |
1192 | bm = ntohl (gm->hash_bitmap); | 1177 | bm = ntohl(gm->hash_bitmap); |
1193 | bits = 0; | 1178 | bits = 0; |
1194 | while (bm > 0) | 1179 | while (bm > 0) |
1195 | { | 1180 | { |
1196 | if (1 == (bm & 1)) | 1181 | if (1 == (bm & 1)) |
1197 | bits++; | 1182 | bits++; |
1198 | bm >>= 1; | 1183 | bm >>= 1; |
1199 | } | 1184 | } |
1200 | opt = (const struct GNUNET_PeerIdentity *) &gm[1]; | 1185 | opt = (const struct GNUNET_PeerIdentity *)&gm[1]; |
1201 | bfsize = msize - sizeof (struct GetMessage) - bits * sizeof (struct GNUNET_PeerIdentity); | 1186 | bfsize = msize - sizeof(struct GetMessage) - bits * sizeof(struct GNUNET_PeerIdentity); |
1202 | GNUNET_STATISTICS_update (GSF_stats, | 1187 | GNUNET_STATISTICS_update(GSF_stats, |
1203 | gettext_noop | 1188 | gettext_noop |
1204 | ("# GET requests received (from other peers)"), | 1189 | ("# GET requests received (from other peers)"), |
1205 | 1, | 1190 | 1, |
1206 | GNUNET_NO); | 1191 | GNUNET_NO); |
1207 | GSF_cover_query_count++; | 1192 | GSF_cover_query_count++; |
1208 | bm = ntohl (gm->hash_bitmap); | 1193 | bm = ntohl(gm->hash_bitmap); |
1209 | bits = 0; | 1194 | bits = 0; |
1210 | if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) | 1195 | if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) |
1211 | cp = GSF_peer_get_ (&opt[bits++]); | 1196 | cp = GSF_peer_get_(&opt[bits++]); |
1212 | else | 1197 | else |
1213 | cp = cps; | 1198 | cp = cps; |
1214 | if (NULL == cp) | 1199 | if (NULL == cp) |
1215 | { | 1200 | { |
1216 | if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) | 1201 | if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) |
1217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1202 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1218 | "Failed to find RETURN-TO peer `%s' in connection set. Dropping query.\n", | 1203 | "Failed to find RETURN-TO peer `%s' in connection set. Dropping query.\n", |
1219 | GNUNET_i2s (&opt[bits - 1])); | 1204 | GNUNET_i2s(&opt[bits - 1])); |
1220 | 1205 | ||
1221 | else | 1206 | else |
1222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1207 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1223 | "Failed to find peer `%s' in connection set. Dropping query.\n", | 1208 | "Failed to find peer `%s' in connection set. Dropping query.\n", |
1224 | GNUNET_i2s (cps->ppd.peer)); | 1209 | GNUNET_i2s(cps->ppd.peer)); |
1225 | GNUNET_STATISTICS_update (GSF_stats, | 1210 | GNUNET_STATISTICS_update(GSF_stats, |
1226 | gettext_noop | 1211 | gettext_noop |
1227 | ("# requests dropped due to missing reverse route"), | 1212 | ("# requests dropped due to missing reverse route"), |
1228 | 1, | 1213 | 1, |
1229 | GNUNET_NO); | 1214 | GNUNET_NO); |
1230 | return; | 1215 | return; |
1231 | } | 1216 | } |
1232 | unsigned int queue_size = GNUNET_MQ_get_length (cp->mq); | 1217 | unsigned int queue_size = GNUNET_MQ_get_length(cp->mq); |
1233 | queue_size += cp->ppd.pending_replies + cp->delay_queue_size; | 1218 | queue_size += cp->ppd.pending_replies + cp->delay_queue_size; |
1234 | if (queue_size > MAX_QUEUE_PER_PEER) | 1219 | if (queue_size > MAX_QUEUE_PER_PEER) |
1235 | { | 1220 | { |
1236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1221 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1237 | "Peer `%s' has too many replies queued already. Dropping query.\n", | 1222 | "Peer `%s' has too many replies queued already. Dropping query.\n", |
1238 | GNUNET_i2s (cps->ppd.peer)); | 1223 | GNUNET_i2s(cps->ppd.peer)); |
1239 | GNUNET_STATISTICS_update (GSF_stats, | 1224 | GNUNET_STATISTICS_update(GSF_stats, |
1240 | gettext_noop ("# requests dropped due to full reply queue"), | 1225 | gettext_noop("# requests dropped due to full reply queue"), |
1241 | 1, | 1226 | 1, |
1242 | GNUNET_NO); | 1227 | GNUNET_NO); |
1243 | return; | 1228 | return; |
1244 | } | 1229 | } |
1245 | /* note that we can really only check load here since otherwise | 1230 | /* note that we can really only check load here since otherwise |
1246 | * peers could find out that we are overloaded by not being | 1231 | * peers could find out that we are overloaded by not being |
1247 | * disconnected after sending us a malformed query... */ | 1232 | * disconnected after sending us a malformed query... */ |
1248 | tec.priority = bound_priority (ntohl (gm->priority), | 1233 | tec.priority = bound_priority(ntohl(gm->priority), |
1249 | cps); | 1234 | cps); |
1250 | if (tec.priority < 0) | 1235 | if (tec.priority < 0) |
1251 | { | 1236 | { |
1252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1237 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1253 | "Dropping query from `%s', this peer is too busy.\n", | 1238 | "Dropping query from `%s', this peer is too busy.\n", |
1254 | GNUNET_i2s (cps->ppd.peer)); | 1239 | GNUNET_i2s(cps->ppd.peer)); |
1255 | return; | 1240 | return; |
1256 | } | 1241 | } |
1257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1242 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1258 | "Received request for `%s' of type %u from peer `%s' with flags %u\n", | 1243 | "Received request for `%s' of type %u from peer `%s' with flags %u\n", |
1259 | GNUNET_h2s (&gm->query), | 1244 | GNUNET_h2s(&gm->query), |
1260 | (unsigned int) tec.type, | 1245 | (unsigned int)tec.type, |
1261 | GNUNET_i2s (cps->ppd.peer), | 1246 | GNUNET_i2s(cps->ppd.peer), |
1262 | (unsigned int) bm); | 1247 | (unsigned int)bm); |
1263 | target = | 1248 | target = |
1264 | (0 != | 1249 | (0 != |
1265 | (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? (&opt[bits++]) : NULL; | 1250 | (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? (&opt[bits++]) : NULL; |
1266 | options = GSF_PRO_DEFAULTS; | 1251 | options = GSF_PRO_DEFAULTS; |
1267 | spid = 0; | 1252 | spid = 0; |
1268 | if ((GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 + tec.priority)) | 1253 | if ((GNUNET_LOAD_get_load(cp->ppd.transmission_delay) > 3 * (1 + tec.priority)) |
1269 | || (GNUNET_LOAD_get_average (cp->ppd.transmission_delay) > | 1254 | || (GNUNET_LOAD_get_average(cp->ppd.transmission_delay) > |
1270 | GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value_us * 2 + | 1255 | GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value_us * 2 + |
1271 | GNUNET_LOAD_get_average (GSF_rt_entry_lifetime))) | 1256 | GNUNET_LOAD_get_average(GSF_rt_entry_lifetime))) |
1272 | { | 1257 | { |
1273 | /* don't have BW to send to peer, or would likely take longer than we have for it, | 1258 | /* don't have BW to send to peer, or would likely take longer than we have for it, |
1274 | * so at best indirect the query */ | 1259 | * so at best indirect the query */ |
1275 | tec.priority = 0; | 1260 | tec.priority = 0; |
1276 | options |= GSF_PRO_FORWARD_ONLY; | 1261 | options |= GSF_PRO_FORWARD_ONLY; |
1277 | spid = GNUNET_PEER_intern (cps->ppd.peer); | 1262 | spid = GNUNET_PEER_intern(cps->ppd.peer); |
1278 | GNUNET_assert (0 != spid); | 1263 | GNUNET_assert(0 != spid); |
1279 | } | 1264 | } |
1280 | tec.ttl = bound_ttl (ntohl (gm->ttl), | 1265 | tec.ttl = bound_ttl(ntohl(gm->ttl), |
1281 | tec.priority); | 1266 | tec.priority); |
1282 | /* decrement ttl (always) */ | 1267 | /* decrement ttl (always) */ |
1283 | ttl_decrement = | 1268 | ttl_decrement = |
1284 | 2 * TTL_DECREMENT + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1269 | 2 * TTL_DECREMENT + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
1285 | TTL_DECREMENT); | 1270 | TTL_DECREMENT); |
1286 | if ( (tec.ttl < 0) && | 1271 | if ((tec.ttl < 0) && |
1287 | (((int32_t) (tec.ttl - ttl_decrement)) > 0) ) | 1272 | (((int32_t)(tec.ttl - ttl_decrement)) > 0)) |
1288 | { | 1273 | { |
1289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1274 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1290 | "Dropping query from `%s' due to TTL underflow (%d - %u).\n", | 1275 | "Dropping query from `%s' due to TTL underflow (%d - %u).\n", |
1291 | GNUNET_i2s (cps->ppd.peer), | 1276 | GNUNET_i2s(cps->ppd.peer), |
1292 | tec.ttl, | 1277 | tec.ttl, |
1293 | ttl_decrement); | 1278 | ttl_decrement); |
1294 | GNUNET_STATISTICS_update (GSF_stats, | 1279 | GNUNET_STATISTICS_update(GSF_stats, |
1295 | gettext_noop | 1280 | gettext_noop |
1296 | ("# requests dropped due TTL underflow"), 1, | 1281 | ("# requests dropped due TTL underflow"), 1, |
1297 | GNUNET_NO); | 1282 | GNUNET_NO); |
1298 | /* integer underflow => drop (should be very rare)! */ | 1283 | /* integer underflow => drop (should be very rare)! */ |
1299 | return; | 1284 | return; |
1300 | } | 1285 | } |
1301 | tec.ttl -= ttl_decrement; | 1286 | tec.ttl -= ttl_decrement; |
1302 | 1287 | ||
1303 | /* test if the request already exists */ | 1288 | /* test if the request already exists */ |
1304 | tec.finished = GNUNET_NO; | 1289 | tec.finished = GNUNET_NO; |
1305 | GNUNET_CONTAINER_multihashmap_get_multiple (cp->request_map, | 1290 | GNUNET_CONTAINER_multihashmap_get_multiple(cp->request_map, |
1306 | &gm->query, | 1291 | &gm->query, |
1307 | &test_exist_cb, | 1292 | &test_exist_cb, |
1308 | &tec); | 1293 | &tec); |
1309 | if (GNUNET_YES == tec.finished) | 1294 | if (GNUNET_YES == tec.finished) |
1310 | return; /* merged into existing request, we're done */ | 1295 | return; /* merged into existing request, we're done */ |
1311 | 1296 | ||
1312 | peerreq = GNUNET_new (struct PeerRequest); | 1297 | peerreq = GNUNET_new(struct PeerRequest); |
1313 | peerreq->cp = cp; | 1298 | peerreq->cp = cp; |
1314 | pr = GSF_pending_request_create_ (options, | 1299 | pr = GSF_pending_request_create_(options, |
1315 | tec.type, | 1300 | tec.type, |
1316 | &gm->query, | 1301 | &gm->query, |
1317 | target, | 1302 | target, |
1318 | (bfsize > 0) | 1303 | (bfsize > 0) |
1319 | ? (const char *) &opt[bits] | 1304 | ? (const char *)&opt[bits] |
1320 | : NULL, | 1305 | : NULL, |
1321 | bfsize, | 1306 | bfsize, |
1322 | ntohl (gm->filter_mutator), | 1307 | ntohl(gm->filter_mutator), |
1323 | 1 /* anonymity */, | 1308 | 1 /* anonymity */, |
1324 | (uint32_t) tec.priority, | 1309 | (uint32_t)tec.priority, |
1325 | tec.ttl, | 1310 | tec.ttl, |
1326 | spid, | 1311 | spid, |
1327 | GNUNET_PEER_intern (cps->ppd.peer), | 1312 | GNUNET_PEER_intern(cps->ppd.peer), |
1328 | NULL, 0, /* replies_seen */ | 1313 | NULL, 0, /* replies_seen */ |
1329 | &handle_p2p_reply, | 1314 | &handle_p2p_reply, |
1330 | peerreq); | 1315 | peerreq); |
1331 | GNUNET_assert (NULL != pr); | 1316 | GNUNET_assert(NULL != pr); |
1332 | prd = GSF_pending_request_get_data_ (pr); | 1317 | prd = GSF_pending_request_get_data_(pr); |
1333 | peerreq->pr = pr; | 1318 | peerreq->pr = pr; |
1334 | GNUNET_break (GNUNET_OK == | 1319 | GNUNET_break(GNUNET_OK == |
1335 | GNUNET_CONTAINER_multihashmap_put (cp->request_map, | 1320 | GNUNET_CONTAINER_multihashmap_put(cp->request_map, |
1336 | &prd->query, | 1321 | &prd->query, |
1337 | peerreq, | 1322 | peerreq, |
1338 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 1323 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
1339 | GNUNET_STATISTICS_update (GSF_stats, | 1324 | GNUNET_STATISTICS_update(GSF_stats, |
1340 | gettext_noop ("# P2P query messages received and processed"), | 1325 | gettext_noop("# P2P query messages received and processed"), |
1341 | 1, | 1326 | 1, |
1342 | GNUNET_NO); | 1327 | GNUNET_NO); |
1343 | GNUNET_STATISTICS_update (GSF_stats, | 1328 | GNUNET_STATISTICS_update(GSF_stats, |
1344 | gettext_noop ("# P2P searches active"), | 1329 | gettext_noop("# P2P searches active"), |
1345 | 1, | 1330 | 1, |
1346 | GNUNET_NO); | 1331 | GNUNET_NO); |
1347 | GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES; | 1332 | GSF_pending_request_get_data_(pr)->has_started = GNUNET_YES; |
1348 | GSF_local_lookup_ (pr, | 1333 | GSF_local_lookup_(pr, |
1349 | &GSF_consider_forwarding, | 1334 | &GSF_consider_forwarding, |
1350 | NULL); | 1335 | NULL); |
1351 | } | 1336 | } |
1352 | 1337 | ||
1353 | 1338 | ||
@@ -1359,22 +1344,22 @@ handle_p2p_get (void *cls, | |||
1359 | * @param cp target peer | 1344 | * @param cp target peer |
1360 | * @param is_query is this a query (#GNUNET_YES) or content (#GNUNET_NO) or neither (#GNUNET_SYSERR) | 1345 | * @param is_query is this a query (#GNUNET_YES) or content (#GNUNET_NO) or neither (#GNUNET_SYSERR) |
1361 | * @param priority how important is this request? | 1346 | * @param priority how important is this request? |
1362 | * @param timeout when does this request timeout | 1347 | * @param timeout when does this request timeout |
1363 | * @param size number of bytes we would like to send to the peer | 1348 | * @param size number of bytes we would like to send to the peer |
1364 | * @param env message to send | 1349 | * @param env message to send |
1365 | */ | 1350 | */ |
1366 | void | 1351 | void |
1367 | GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, | 1352 | GSF_peer_transmit_(struct GSF_ConnectedPeer *cp, |
1368 | int is_query, | 1353 | int is_query, |
1369 | uint32_t priority, | 1354 | uint32_t priority, |
1370 | struct GNUNET_MQ_Envelope *env) | 1355 | struct GNUNET_MQ_Envelope *env) |
1371 | { | 1356 | { |
1372 | struct GSF_PeerTransmitHandle *pth; | 1357 | struct GSF_PeerTransmitHandle *pth; |
1373 | struct GSF_PeerTransmitHandle *pos; | 1358 | struct GSF_PeerTransmitHandle *pos; |
1374 | struct GSF_PeerTransmitHandle *prev; | 1359 | struct GSF_PeerTransmitHandle *prev; |
1375 | 1360 | ||
1376 | pth = GNUNET_new (struct GSF_PeerTransmitHandle); | 1361 | pth = GNUNET_new(struct GSF_PeerTransmitHandle); |
1377 | pth->transmission_request_start_time = GNUNET_TIME_absolute_get (); | 1362 | pth->transmission_request_start_time = GNUNET_TIME_absolute_get(); |
1378 | pth->env = env; | 1363 | pth->env = env; |
1379 | pth->is_query = is_query; | 1364 | pth->is_query = is_query; |
1380 | pth->priority = priority; | 1365 | pth->priority = priority; |
@@ -1383,19 +1368,19 @@ GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, | |||
1383 | prev = NULL; | 1368 | prev = NULL; |
1384 | pos = cp->pth_head; | 1369 | pos = cp->pth_head; |
1385 | while ((NULL != pos) && (pos->priority > priority)) | 1370 | while ((NULL != pos) && (pos->priority > priority)) |
1386 | { | 1371 | { |
1387 | prev = pos; | 1372 | prev = pos; |
1388 | pos = pos->next; | 1373 | pos = pos->next; |
1389 | } | 1374 | } |
1390 | GNUNET_CONTAINER_DLL_insert_after (cp->pth_head, | 1375 | GNUNET_CONTAINER_DLL_insert_after(cp->pth_head, |
1391 | cp->pth_tail, | 1376 | cp->pth_tail, |
1392 | prev, | 1377 | prev, |
1393 | pth); | 1378 | pth); |
1394 | if (GNUNET_YES == is_query) | 1379 | if (GNUNET_YES == is_query) |
1395 | cp->ppd.pending_queries++; | 1380 | cp->ppd.pending_queries++; |
1396 | else if (GNUNET_NO == is_query) | 1381 | else if (GNUNET_NO == is_query) |
1397 | cp->ppd.pending_replies++; | 1382 | cp->ppd.pending_replies++; |
1398 | schedule_transmission (pth); | 1383 | schedule_transmission(pth); |
1399 | } | 1384 | } |
1400 | 1385 | ||
1401 | 1386 | ||
@@ -1407,19 +1392,19 @@ GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, | |||
1407 | * @param request_priority priority of the original request | 1392 | * @param request_priority priority of the original request |
1408 | */ | 1393 | */ |
1409 | void | 1394 | void |
1410 | GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, | 1395 | GSF_peer_update_performance_(struct GSF_ConnectedPeer *cp, |
1411 | struct GNUNET_TIME_Absolute request_time, | 1396 | struct GNUNET_TIME_Absolute request_time, |
1412 | uint32_t request_priority) | 1397 | uint32_t request_priority) |
1413 | { | 1398 | { |
1414 | struct GNUNET_TIME_Relative delay; | 1399 | struct GNUNET_TIME_Relative delay; |
1415 | 1400 | ||
1416 | delay = GNUNET_TIME_absolute_get_duration (request_time); | 1401 | delay = GNUNET_TIME_absolute_get_duration(request_time); |
1417 | cp->ppd.avg_reply_delay.rel_value_us = | 1402 | cp->ppd.avg_reply_delay.rel_value_us = |
1418 | (cp->ppd.avg_reply_delay.rel_value_us * (RUNAVG_DELAY_N - 1) + | 1403 | (cp->ppd.avg_reply_delay.rel_value_us * (RUNAVG_DELAY_N - 1) + |
1419 | delay.rel_value_us) / RUNAVG_DELAY_N; | 1404 | delay.rel_value_us) / RUNAVG_DELAY_N; |
1420 | cp->ppd.avg_priority = | 1405 | cp->ppd.avg_priority = |
1421 | (cp->ppd.avg_priority * (RUNAVG_DELAY_N - 1) + | 1406 | (cp->ppd.avg_priority * (RUNAVG_DELAY_N - 1) + |
1422 | request_priority) / RUNAVG_DELAY_N; | 1407 | request_priority) / RUNAVG_DELAY_N; |
1423 | } | 1408 | } |
1424 | 1409 | ||
1425 | 1410 | ||
@@ -1431,8 +1416,8 @@ GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, | |||
1431 | * @param initiator_client local client on responsible for query | 1416 | * @param initiator_client local client on responsible for query |
1432 | */ | 1417 | */ |
1433 | void | 1418 | void |
1434 | GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, | 1419 | GSF_peer_update_responder_client_(struct GSF_ConnectedPeer *cp, |
1435 | struct GSF_LocalClient *initiator_client) | 1420 | struct GSF_LocalClient *initiator_client) |
1436 | { | 1421 | { |
1437 | cp->ppd.last_client_replies[cp->last_client_replies_woff++ % | 1422 | cp->ppd.last_client_replies[cp->last_client_replies_woff++ % |
1438 | CS2P_SUCCESS_LIST_SIZE] = initiator_client; | 1423 | CS2P_SUCCESS_LIST_SIZE] = initiator_client; |
@@ -1447,15 +1432,15 @@ GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, | |||
1447 | * @param initiator_peer other peer responsible for query | 1432 | * @param initiator_peer other peer responsible for query |
1448 | */ | 1433 | */ |
1449 | void | 1434 | void |
1450 | GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, | 1435 | GSF_peer_update_responder_peer_(struct GSF_ConnectedPeer *cp, |
1451 | const struct GSF_ConnectedPeer *initiator_peer) | 1436 | const struct GSF_ConnectedPeer *initiator_peer) |
1452 | { | 1437 | { |
1453 | unsigned int woff; | 1438 | unsigned int woff; |
1454 | 1439 | ||
1455 | woff = cp->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE; | 1440 | woff = cp->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE; |
1456 | GNUNET_PEER_change_rc (cp->ppd.last_p2p_replies[woff], -1); | 1441 | GNUNET_PEER_change_rc(cp->ppd.last_p2p_replies[woff], -1); |
1457 | cp->ppd.last_p2p_replies[woff] = initiator_peer->ppd.pid; | 1442 | cp->ppd.last_p2p_replies[woff] = initiator_peer->ppd.pid; |
1458 | GNUNET_PEER_change_rc (initiator_peer->ppd.pid, 1); | 1443 | GNUNET_PEER_change_rc(initiator_peer->ppd.pid, 1); |
1459 | cp->last_p2p_replies_woff = (woff + 1) % P2P_SUCCESS_LIST_SIZE; | 1444 | cp->last_p2p_replies_woff = (woff + 1) % P2P_SUCCESS_LIST_SIZE; |
1460 | } | 1445 | } |
1461 | 1446 | ||
@@ -1469,23 +1454,23 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, | |||
1469 | * @return #GNUNET_OK to continue iteration | 1454 | * @return #GNUNET_OK to continue iteration |
1470 | */ | 1455 | */ |
1471 | static int | 1456 | static int |
1472 | flush_respect (void *cls, | 1457 | flush_respect(void *cls, |
1473 | const struct GNUNET_PeerIdentity *key, | 1458 | const struct GNUNET_PeerIdentity *key, |
1474 | void *value) | 1459 | void *value) |
1475 | { | 1460 | { |
1476 | struct GSF_ConnectedPeer *cp = value; | 1461 | struct GSF_ConnectedPeer *cp = value; |
1477 | struct GNUNET_PeerIdentity pid; | 1462 | struct GNUNET_PeerIdentity pid; |
1478 | 1463 | ||
1479 | if (cp->ppd.respect == cp->disk_respect) | 1464 | if (cp->ppd.respect == cp->disk_respect) |
1480 | return GNUNET_OK; /* unchanged */ | 1465 | return GNUNET_OK; /* unchanged */ |
1481 | GNUNET_assert (0 != cp->ppd.pid); | 1466 | GNUNET_assert(0 != cp->ppd.pid); |
1482 | GNUNET_PEER_resolve (cp->ppd.pid, &pid); | 1467 | GNUNET_PEER_resolve(cp->ppd.pid, &pid); |
1483 | GNUNET_PEERSTORE_store (peerstore, "fs", &pid, "respect", &cp->ppd.respect, | 1468 | GNUNET_PEERSTORE_store(peerstore, "fs", &pid, "respect", &cp->ppd.respect, |
1484 | sizeof (cp->ppd.respect), | 1469 | sizeof(cp->ppd.respect), |
1485 | GNUNET_TIME_UNIT_FOREVER_ABS, | 1470 | GNUNET_TIME_UNIT_FOREVER_ABS, |
1486 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 1471 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, |
1487 | NULL, | 1472 | NULL, |
1488 | NULL); | 1473 | NULL); |
1489 | return GNUNET_OK; | 1474 | return GNUNET_OK; |
1490 | } | 1475 | } |
1491 | 1476 | ||
@@ -1499,9 +1484,9 @@ flush_respect (void *cls, | |||
1499 | * @param internal_cls the corresponding `struct GSF_ConnectedPeer` | 1484 | * @param internal_cls the corresponding `struct GSF_ConnectedPeer` |
1500 | */ | 1485 | */ |
1501 | void | 1486 | void |
1502 | GSF_peer_disconnect_handler (void *cls, | 1487 | GSF_peer_disconnect_handler(void *cls, |
1503 | const struct GNUNET_PeerIdentity *peer, | 1488 | const struct GNUNET_PeerIdentity *peer, |
1504 | void *internal_cls) | 1489 | void *internal_cls) |
1505 | { | 1490 | { |
1506 | struct GSF_ConnectedPeer *cp = internal_cls; | 1491 | struct GSF_ConnectedPeer *cp = internal_cls; |
1507 | struct GSF_PeerTransmitHandle *pth; | 1492 | struct GSF_PeerTransmitHandle *pth; |
@@ -1509,84 +1494,83 @@ GSF_peer_disconnect_handler (void *cls, | |||
1509 | 1494 | ||
1510 | if (NULL == cp) | 1495 | if (NULL == cp) |
1511 | return; /* must have been disconnect from core with | 1496 | return; /* must have been disconnect from core with |
1512 | * 'peer' == my_id, ignore */ | 1497 | * 'peer' == my_id, ignore */ |
1513 | flush_respect (NULL, | 1498 | flush_respect(NULL, |
1514 | peer, | 1499 | peer, |
1515 | cp); | 1500 | cp); |
1516 | GNUNET_assert (GNUNET_YES == | 1501 | GNUNET_assert(GNUNET_YES == |
1517 | GNUNET_CONTAINER_multipeermap_remove (cp_map, | 1502 | GNUNET_CONTAINER_multipeermap_remove(cp_map, |
1518 | peer, | 1503 | peer, |
1519 | cp)); | 1504 | cp)); |
1520 | GNUNET_STATISTICS_set (GSF_stats, | 1505 | GNUNET_STATISTICS_set(GSF_stats, |
1521 | gettext_noop ("# peers connected"), | 1506 | gettext_noop("# peers connected"), |
1522 | GNUNET_CONTAINER_multipeermap_size (cp_map), | 1507 | GNUNET_CONTAINER_multipeermap_size(cp_map), |
1523 | GNUNET_NO); | 1508 | GNUNET_NO); |
1524 | if (NULL != cp->respect_iterate_req) | 1509 | if (NULL != cp->respect_iterate_req) |
1525 | { | 1510 | { |
1526 | GNUNET_PEERSTORE_iterate_cancel (cp->respect_iterate_req); | 1511 | GNUNET_PEERSTORE_iterate_cancel(cp->respect_iterate_req); |
1527 | cp->respect_iterate_req = NULL; | 1512 | cp->respect_iterate_req = NULL; |
1528 | } | 1513 | } |
1529 | if (NULL != cp->rc) | 1514 | if (NULL != cp->rc) |
1530 | { | 1515 | { |
1531 | GNUNET_ATS_reserve_bandwidth_cancel (cp->rc); | 1516 | GNUNET_ATS_reserve_bandwidth_cancel(cp->rc); |
1532 | cp->rc = NULL; | 1517 | cp->rc = NULL; |
1533 | } | 1518 | } |
1534 | if (NULL != cp->rc_delay_task) | 1519 | if (NULL != cp->rc_delay_task) |
1535 | { | 1520 | { |
1536 | GNUNET_SCHEDULER_cancel (cp->rc_delay_task); | 1521 | GNUNET_SCHEDULER_cancel(cp->rc_delay_task); |
1537 | cp->rc_delay_task = NULL; | 1522 | cp->rc_delay_task = NULL; |
1538 | } | 1523 | } |
1539 | GNUNET_CONTAINER_multihashmap_iterate (cp->request_map, | 1524 | GNUNET_CONTAINER_multihashmap_iterate(cp->request_map, |
1540 | &cancel_pending_request, | 1525 | &cancel_pending_request, |
1541 | cp); | 1526 | cp); |
1542 | GNUNET_CONTAINER_multihashmap_destroy (cp->request_map); | 1527 | GNUNET_CONTAINER_multihashmap_destroy(cp->request_map); |
1543 | cp->request_map = NULL; | 1528 | cp->request_map = NULL; |
1544 | GSF_plan_notify_peer_disconnect_ (cp); | 1529 | GSF_plan_notify_peer_disconnect_(cp); |
1545 | GNUNET_LOAD_value_free (cp->ppd.transmission_delay); | 1530 | GNUNET_LOAD_value_free(cp->ppd.transmission_delay); |
1546 | GNUNET_PEER_decrement_rcs (cp->ppd.last_p2p_replies, | 1531 | GNUNET_PEER_decrement_rcs(cp->ppd.last_p2p_replies, |
1547 | P2P_SUCCESS_LIST_SIZE); | 1532 | P2P_SUCCESS_LIST_SIZE); |
1548 | memset (cp->ppd.last_p2p_replies, | 1533 | memset(cp->ppd.last_p2p_replies, |
1549 | 0, | 1534 | 0, |
1550 | sizeof (cp->ppd.last_p2p_replies)); | 1535 | sizeof(cp->ppd.last_p2p_replies)); |
1551 | GSF_push_stop_ (cp); | 1536 | GSF_push_stop_(cp); |
1552 | while (NULL != (pth = cp->pth_head)) | 1537 | while (NULL != (pth = cp->pth_head)) |
1553 | { | 1538 | { |
1554 | GNUNET_CONTAINER_DLL_remove (cp->pth_head, | 1539 | GNUNET_CONTAINER_DLL_remove(cp->pth_head, |
1555 | cp->pth_tail, | 1540 | cp->pth_tail, |
1556 | pth); | 1541 | pth); |
1557 | if (GNUNET_YES == pth->is_query) | 1542 | if (GNUNET_YES == pth->is_query) |
1558 | GNUNET_assert (0 < cp->ppd.pending_queries--); | 1543 | GNUNET_assert(0 < cp->ppd.pending_queries--); |
1559 | else if (GNUNET_NO == pth->is_query) | 1544 | else if (GNUNET_NO == pth->is_query) |
1560 | GNUNET_assert (0 < cp->ppd.pending_replies--); | 1545 | GNUNET_assert(0 < cp->ppd.pending_replies--); |
1561 | GNUNET_free (pth); | 1546 | GNUNET_free(pth); |
1562 | } | 1547 | } |
1563 | while (NULL != (dh = cp->delayed_head)) | 1548 | while (NULL != (dh = cp->delayed_head)) |
1564 | { | 1549 | { |
1565 | GNUNET_CONTAINER_DLL_remove (cp->delayed_head, | 1550 | GNUNET_CONTAINER_DLL_remove(cp->delayed_head, |
1566 | cp->delayed_tail, | 1551 | cp->delayed_tail, |
1567 | dh); | 1552 | dh); |
1568 | GNUNET_MQ_discard (dh->env); | 1553 | GNUNET_MQ_discard(dh->env); |
1569 | cp->delay_queue_size--; | 1554 | cp->delay_queue_size--; |
1570 | GNUNET_SCHEDULER_cancel (dh->delay_task); | 1555 | GNUNET_SCHEDULER_cancel(dh->delay_task); |
1571 | GNUNET_free (dh); | 1556 | GNUNET_free(dh); |
1572 | } | 1557 | } |
1573 | GNUNET_PEER_change_rc (cp->ppd.pid, -1); | 1558 | GNUNET_PEER_change_rc(cp->ppd.pid, -1); |
1574 | if (NULL != cp->mig_revive_task) | 1559 | if (NULL != cp->mig_revive_task) |
1575 | { | 1560 | { |
1576 | GNUNET_SCHEDULER_cancel (cp->mig_revive_task); | 1561 | GNUNET_SCHEDULER_cancel(cp->mig_revive_task); |
1577 | cp->mig_revive_task = NULL; | 1562 | cp->mig_revive_task = NULL; |
1578 | } | 1563 | } |
1579 | GNUNET_break (0 == cp->ppd.pending_queries); | 1564 | GNUNET_break(0 == cp->ppd.pending_queries); |
1580 | GNUNET_break (0 == cp->ppd.pending_replies); | 1565 | GNUNET_break(0 == cp->ppd.pending_replies); |
1581 | GNUNET_free (cp); | 1566 | GNUNET_free(cp); |
1582 | } | 1567 | } |
1583 | 1568 | ||
1584 | 1569 | ||
1585 | /** | 1570 | /** |
1586 | * Closure for #call_iterator(). | 1571 | * Closure for #call_iterator(). |
1587 | */ | 1572 | */ |
1588 | struct IterationContext | 1573 | struct IterationContext { |
1589 | { | ||
1590 | /** | 1574 | /** |
1591 | * Function to call on each entry. | 1575 | * Function to call on each entry. |
1592 | */ | 1576 | */ |
@@ -1608,16 +1592,16 @@ struct IterationContext | |||
1608 | * @return #GNUNET_YES to continue iteration | 1592 | * @return #GNUNET_YES to continue iteration |
1609 | */ | 1593 | */ |
1610 | static int | 1594 | static int |
1611 | call_iterator (void *cls, | 1595 | call_iterator(void *cls, |
1612 | const struct GNUNET_PeerIdentity *key, | 1596 | const struct GNUNET_PeerIdentity *key, |
1613 | void *value) | 1597 | void *value) |
1614 | { | 1598 | { |
1615 | struct IterationContext *ic = cls; | 1599 | struct IterationContext *ic = cls; |
1616 | struct GSF_ConnectedPeer *cp = value; | 1600 | struct GSF_ConnectedPeer *cp = value; |
1617 | 1601 | ||
1618 | ic->it (ic->it_cls, | 1602 | ic->it(ic->it_cls, |
1619 | key, cp, | 1603 | key, cp, |
1620 | &cp->ppd); | 1604 | &cp->ppd); |
1621 | return GNUNET_YES; | 1605 | return GNUNET_YES; |
1622 | } | 1606 | } |
1623 | 1607 | ||
@@ -1629,16 +1613,16 @@ call_iterator (void *cls, | |||
1629 | * @param it_cls closure for @a it | 1613 | * @param it_cls closure for @a it |
1630 | */ | 1614 | */ |
1631 | void | 1615 | void |
1632 | GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, | 1616 | GSF_iterate_connected_peers_(GSF_ConnectedPeerIterator it, |
1633 | void *it_cls) | 1617 | void *it_cls) |
1634 | { | 1618 | { |
1635 | struct IterationContext ic; | 1619 | struct IterationContext ic; |
1636 | 1620 | ||
1637 | ic.it = it; | 1621 | ic.it = it; |
1638 | ic.it_cls = it_cls; | 1622 | ic.it_cls = it_cls; |
1639 | GNUNET_CONTAINER_multipeermap_iterate (cp_map, | 1623 | GNUNET_CONTAINER_multipeermap_iterate(cp_map, |
1640 | &call_iterator, | 1624 | &call_iterator, |
1641 | &ic); | 1625 | &ic); |
1642 | } | 1626 | } |
1643 | 1627 | ||
1644 | 1628 | ||
@@ -1649,11 +1633,11 @@ GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, | |||
1649 | * @param id identity to set (written to) | 1633 | * @param id identity to set (written to) |
1650 | */ | 1634 | */ |
1651 | void | 1635 | void |
1652 | GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, | 1636 | GSF_connected_peer_get_identity_(const struct GSF_ConnectedPeer *cp, |
1653 | struct GNUNET_PeerIdentity *id) | 1637 | struct GNUNET_PeerIdentity *id) |
1654 | { | 1638 | { |
1655 | GNUNET_assert (0 != cp->ppd.pid); | 1639 | GNUNET_assert(0 != cp->ppd.pid); |
1656 | GNUNET_PEER_resolve (cp->ppd.pid, id); | 1640 | GNUNET_PEER_resolve(cp->ppd.pid, id); |
1657 | } | 1641 | } |
1658 | 1642 | ||
1659 | 1643 | ||
@@ -1664,10 +1648,10 @@ GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, | |||
1664 | * @return reference to peer identity, valid until peer disconnects (!) | 1648 | * @return reference to peer identity, valid until peer disconnects (!) |
1665 | */ | 1649 | */ |
1666 | const struct GNUNET_PeerIdentity * | 1650 | const struct GNUNET_PeerIdentity * |
1667 | GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp) | 1651 | GSF_connected_peer_get_identity2_(const struct GSF_ConnectedPeer *cp) |
1668 | { | 1652 | { |
1669 | GNUNET_assert (0 != cp->ppd.pid); | 1653 | GNUNET_assert(0 != cp->ppd.pid); |
1670 | return GNUNET_PEER_resolve2 (cp->ppd.pid); | 1654 | return GNUNET_PEER_resolve2(cp->ppd.pid); |
1671 | } | 1655 | } |
1672 | 1656 | ||
1673 | 1657 | ||
@@ -1679,38 +1663,38 @@ GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp) | |||
1679 | * @param block_time until when to block | 1663 | * @param block_time until when to block |
1680 | */ | 1664 | */ |
1681 | void | 1665 | void |
1682 | GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, | 1666 | GSF_block_peer_migration_(struct GSF_ConnectedPeer *cp, |
1683 | struct GNUNET_TIME_Absolute block_time) | 1667 | struct GNUNET_TIME_Absolute block_time) |
1684 | { | 1668 | { |
1685 | struct GNUNET_MQ_Envelope *env; | 1669 | struct GNUNET_MQ_Envelope *env; |
1686 | struct MigrationStopMessage *msm; | 1670 | struct MigrationStopMessage *msm; |
1687 | 1671 | ||
1688 | if (cp->last_migration_block.abs_value_us > block_time.abs_value_us) | 1672 | if (cp->last_migration_block.abs_value_us > block_time.abs_value_us) |
1689 | { | 1673 | { |
1690 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1674 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1691 | "Migration already blocked for another %s\n", | 1675 | "Migration already blocked for another %s\n", |
1692 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining | 1676 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining |
1693 | (cp->last_migration_block), GNUNET_YES)); | 1677 | (cp->last_migration_block), GNUNET_YES)); |
1694 | return; /* already blocked */ | 1678 | return; /* already blocked */ |
1695 | } | 1679 | } |
1696 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking to stop migration for %s\n", | 1680 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asking to stop migration for %s\n", |
1697 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (block_time), | 1681 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining(block_time), |
1698 | GNUNET_YES)); | 1682 | GNUNET_YES)); |
1699 | cp->last_migration_block = block_time; | 1683 | cp->last_migration_block = block_time; |
1700 | env = GNUNET_MQ_msg (msm, | 1684 | env = GNUNET_MQ_msg(msm, |
1701 | GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP); | 1685 | GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP); |
1702 | msm->reserved = htonl (0); | 1686 | msm->reserved = htonl(0); |
1703 | msm->duration | 1687 | msm->duration |
1704 | = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining | 1688 | = GNUNET_TIME_relative_hton(GNUNET_TIME_absolute_get_remaining |
1705 | (cp->last_migration_block)); | 1689 | (cp->last_migration_block)); |
1706 | GNUNET_STATISTICS_update (GSF_stats, | 1690 | GNUNET_STATISTICS_update(GSF_stats, |
1707 | gettext_noop ("# migration stop messages sent"), | 1691 | gettext_noop("# migration stop messages sent"), |
1708 | 1, | 1692 | 1, |
1709 | GNUNET_NO); | 1693 | GNUNET_NO); |
1710 | GSF_peer_transmit_ (cp, | 1694 | GSF_peer_transmit_(cp, |
1711 | GNUNET_SYSERR, | 1695 | GNUNET_SYSERR, |
1712 | UINT32_MAX, | 1696 | UINT32_MAX, |
1713 | env); | 1697 | env); |
1714 | } | 1698 | } |
1715 | 1699 | ||
1716 | 1700 | ||
@@ -1724,8 +1708,8 @@ GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, | |||
1724 | * @param pref preference change | 1708 | * @param pref preference change |
1725 | */ | 1709 | */ |
1726 | void | 1710 | void |
1727 | GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, | 1711 | GSF_connected_peer_change_preference_(struct GSF_ConnectedPeer *cp, |
1728 | uint64_t pref) | 1712 | uint64_t pref) |
1729 | { | 1713 | { |
1730 | cp->inc_preference += pref; | 1714 | cp->inc_preference += pref; |
1731 | } | 1715 | } |
@@ -1737,15 +1721,15 @@ GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, | |||
1737 | * @param cls closure, not used | 1721 | * @param cls closure, not used |
1738 | */ | 1722 | */ |
1739 | static void | 1723 | static void |
1740 | cron_flush_respect (void *cls) | 1724 | cron_flush_respect(void *cls) |
1741 | { | 1725 | { |
1742 | fr_task = NULL; | 1726 | fr_task = NULL; |
1743 | GNUNET_CONTAINER_multipeermap_iterate (cp_map, | 1727 | GNUNET_CONTAINER_multipeermap_iterate(cp_map, |
1744 | &flush_respect, | 1728 | &flush_respect, |
1745 | NULL); | 1729 | NULL); |
1746 | fr_task = GNUNET_SCHEDULER_add_delayed_with_priority (RESPECT_FLUSH_FREQ, | 1730 | fr_task = GNUNET_SCHEDULER_add_delayed_with_priority(RESPECT_FLUSH_FREQ, |
1747 | GNUNET_SCHEDULER_PRIORITY_HIGH, | 1731 | GNUNET_SCHEDULER_PRIORITY_HIGH, |
1748 | &cron_flush_respect, NULL); | 1732 | &cron_flush_respect, NULL); |
1749 | } | 1733 | } |
1750 | 1734 | ||
1751 | 1735 | ||
@@ -1753,12 +1737,12 @@ cron_flush_respect (void *cls) | |||
1753 | * Initialize peer management subsystem. | 1737 | * Initialize peer management subsystem. |
1754 | */ | 1738 | */ |
1755 | void | 1739 | void |
1756 | GSF_connected_peer_init_ () | 1740 | GSF_connected_peer_init_() |
1757 | { | 1741 | { |
1758 | cp_map = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); | 1742 | cp_map = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES); |
1759 | peerstore = GNUNET_PEERSTORE_connect (GSF_cfg); | 1743 | peerstore = GNUNET_PEERSTORE_connect(GSF_cfg); |
1760 | fr_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH, | 1744 | fr_task = GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_HIGH, |
1761 | &cron_flush_respect, NULL); | 1745 | &cron_flush_respect, NULL); |
1762 | } | 1746 | } |
1763 | 1747 | ||
1764 | 1748 | ||
@@ -1766,18 +1750,17 @@ GSF_connected_peer_init_ () | |||
1766 | * Shutdown peer management subsystem. | 1750 | * Shutdown peer management subsystem. |
1767 | */ | 1751 | */ |
1768 | void | 1752 | void |
1769 | GSF_connected_peer_done_ () | 1753 | GSF_connected_peer_done_() |
1770 | { | 1754 | { |
1771 | GNUNET_CONTAINER_multipeermap_iterate (cp_map, | 1755 | GNUNET_CONTAINER_multipeermap_iterate(cp_map, |
1772 | &flush_respect, | 1756 | &flush_respect, |
1773 | NULL); | 1757 | NULL); |
1774 | GNUNET_SCHEDULER_cancel (fr_task); | 1758 | GNUNET_SCHEDULER_cancel(fr_task); |
1775 | fr_task = NULL; | 1759 | fr_task = NULL; |
1776 | GNUNET_CONTAINER_multipeermap_destroy (cp_map); | 1760 | GNUNET_CONTAINER_multipeermap_destroy(cp_map); |
1777 | cp_map = NULL; | 1761 | cp_map = NULL; |
1778 | GNUNET_PEERSTORE_disconnect (peerstore, | 1762 | GNUNET_PEERSTORE_disconnect(peerstore, |
1779 | GNUNET_YES); | 1763 | GNUNET_YES); |
1780 | |||
1781 | } | 1764 | } |
1782 | 1765 | ||
1783 | 1766 | ||
@@ -1790,9 +1773,9 @@ GSF_connected_peer_done_ () | |||
1790 | * @return #GNUNET_YES (we should continue to iterate) | 1773 | * @return #GNUNET_YES (we should continue to iterate) |
1791 | */ | 1774 | */ |
1792 | static int | 1775 | static int |
1793 | clean_local_client (void *cls, | 1776 | clean_local_client(void *cls, |
1794 | const struct GNUNET_PeerIdentity *key, | 1777 | const struct GNUNET_PeerIdentity *key, |
1795 | void *value) | 1778 | void *value) |
1796 | { | 1779 | { |
1797 | const struct GSF_LocalClient *lc = cls; | 1780 | const struct GSF_LocalClient *lc = cls; |
1798 | struct GSF_ConnectedPeer *cp = value; | 1781 | struct GSF_ConnectedPeer *cp = value; |
@@ -1812,13 +1795,13 @@ clean_local_client (void *cls, | |||
1812 | * @param lc handle to the local client (henceforth invalid) | 1795 | * @param lc handle to the local client (henceforth invalid) |
1813 | */ | 1796 | */ |
1814 | void | 1797 | void |
1815 | GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc) | 1798 | GSF_handle_local_client_disconnect_(const struct GSF_LocalClient *lc) |
1816 | { | 1799 | { |
1817 | if (NULL == cp_map) | 1800 | if (NULL == cp_map) |
1818 | return; /* already cleaned up */ | 1801 | return; /* already cleaned up */ |
1819 | GNUNET_CONTAINER_multipeermap_iterate (cp_map, | 1802 | GNUNET_CONTAINER_multipeermap_iterate(cp_map, |
1820 | &clean_local_client, | 1803 | &clean_local_client, |
1821 | (void *) lc); | 1804 | (void *)lc); |
1822 | } | 1805 | } |
1823 | 1806 | ||
1824 | 1807 | ||
diff --git a/src/fs/gnunet-service-fs_cp.h b/src/fs/gnunet-service-fs_cp.h index 486b696ba..9eab3d9de 100644 --- a/src/fs/gnunet-service-fs_cp.h +++ b/src/fs/gnunet-service-fs_cp.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_cp.h | 22 | * @file fs/gnunet-service-fs_cp.h |
@@ -60,9 +60,7 @@ | |||
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 | { | ||
65 | |||
66 | /** | 64 | /** |
67 | * List of the last clients for which this peer successfully | 65 | * List of the last clients for which this peer successfully |
68 | * answered a query. | 66 | * answered a query. |
@@ -128,7 +126,7 @@ struct GSF_PeerPerformanceData | |||
128 | * The peer's identity (pointer). | 126 | * The peer's identity (pointer). |
129 | */ | 127 | */ |
130 | const struct GNUNET_PeerIdentity *peer; | 128 | const struct GNUNET_PeerIdentity *peer; |
131 | 129 | ||
132 | /** | 130 | /** |
133 | * Respect rating for this peer | 131 | * Respect rating for this peer |
134 | */ | 132 | */ |
@@ -143,7 +141,6 @@ struct GSF_PeerPerformanceData | |||
143 | * Number of pending replies (queries are not counted) | 141 | * Number of pending replies (queries are not counted) |
144 | */ | 142 | */ |
145 | unsigned int pending_replies; | 143 | unsigned int pending_replies; |
146 | |||
147 | }; | 144 | }; |
148 | 145 | ||
149 | 146 | ||
@@ -205,9 +202,9 @@ struct GSF_PeerTransmitHandle; | |||
205 | * @return internal handle for the peer | 202 | * @return internal handle for the peer |
206 | */ | 203 | */ |
207 | void * | 204 | void * |
208 | GSF_peer_connect_handler (void *cls, | 205 | GSF_peer_connect_handler(void *cls, |
209 | const struct GNUNET_PeerIdentity *peer, | 206 | const struct GNUNET_PeerIdentity *peer, |
210 | struct GNUNET_MQ_Handle *mq); | 207 | struct GNUNET_MQ_Handle *mq); |
211 | 208 | ||
212 | 209 | ||
213 | /** | 210 | /** |
@@ -217,7 +214,7 @@ GSF_peer_connect_handler (void *cls, | |||
217 | * @return NULL if this peer is not currently connected | 214 | * @return NULL if this peer is not currently connected |
218 | */ | 215 | */ |
219 | struct GSF_ConnectedPeer * | 216 | struct GSF_ConnectedPeer * |
220 | GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer); | 217 | GSF_peer_get_(const struct GNUNET_PeerIdentity *peer); |
221 | 218 | ||
222 | 219 | ||
223 | /** | 220 | /** |
@@ -227,8 +224,8 @@ GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer); | |||
227 | * @param latency current latency value | 224 | * @param latency current latency value |
228 | */ | 225 | */ |
229 | void | 226 | void |
230 | GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id, | 227 | GSF_update_peer_latency_(const struct GNUNET_PeerIdentity *id, |
231 | struct GNUNET_TIME_Relative latency); | 228 | struct GNUNET_TIME_Relative latency); |
232 | 229 | ||
233 | 230 | ||
234 | /** | 231 | /** |
@@ -242,10 +239,10 @@ GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id, | |||
242 | * @param env envelope of message to send | 239 | * @param env envelope of message to send |
243 | */ | 240 | */ |
244 | void | 241 | void |
245 | GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, | 242 | GSF_peer_transmit_(struct GSF_ConnectedPeer *cp, |
246 | int is_query, | 243 | int is_query, |
247 | uint32_t priority, | 244 | uint32_t priority, |
248 | struct GNUNET_MQ_Envelope *env); | 245 | struct GNUNET_MQ_Envelope *env); |
249 | 246 | ||
250 | 247 | ||
251 | /** | 248 | /** |
@@ -256,9 +253,9 @@ GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, | |||
256 | * @param request_priority priority of the original request | 253 | * @param request_priority priority of the original request |
257 | */ | 254 | */ |
258 | void | 255 | void |
259 | GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, | 256 | GSF_peer_update_performance_(struct GSF_ConnectedPeer *cp, |
260 | struct GNUNET_TIME_Absolute request_time, | 257 | struct GNUNET_TIME_Absolute request_time, |
261 | uint32_t request_priority); | 258 | uint32_t request_priority); |
262 | 259 | ||
263 | 260 | ||
264 | /** | 261 | /** |
@@ -269,8 +266,8 @@ GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, | |||
269 | * @param initiator_client local client on responsible for query | 266 | * @param initiator_client local client on responsible for query |
270 | */ | 267 | */ |
271 | void | 268 | void |
272 | GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, | 269 | GSF_peer_update_responder_client_(struct GSF_ConnectedPeer *cp, |
273 | struct GSF_LocalClient *initiator_client); | 270 | struct GSF_LocalClient *initiator_client); |
274 | 271 | ||
275 | 272 | ||
276 | /** | 273 | /** |
@@ -281,9 +278,9 @@ GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, | |||
281 | * @param initiator_peer other peer responsible for query | 278 | * @param initiator_peer other peer responsible for query |
282 | */ | 279 | */ |
283 | void | 280 | void |
284 | GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, | 281 | GSF_peer_update_responder_peer_(struct GSF_ConnectedPeer *cp, |
285 | const struct GSF_ConnectedPeer | 282 | const struct GSF_ConnectedPeer |
286 | *initiator_peer); | 283 | *initiator_peer); |
287 | 284 | ||
288 | 285 | ||
289 | /** | 286 | /** |
@@ -293,8 +290,8 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, | |||
293 | * @param msm the actual message | 290 | * @param msm the actual message |
294 | */ | 291 | */ |
295 | void | 292 | void |
296 | handle_p2p_migration_stop (void *cls, | 293 | handle_p2p_migration_stop(void *cls, |
297 | const struct MigrationStopMessage *message); | 294 | const struct MigrationStopMessage *message); |
298 | 295 | ||
299 | 296 | ||
300 | /** | 297 | /** |
@@ -304,8 +301,8 @@ handle_p2p_migration_stop (void *cls, | |||
304 | * @param gm the actual message | 301 | * @param gm the actual message |
305 | */ | 302 | */ |
306 | void | 303 | void |
307 | handle_p2p_get (void *cls, | 304 | handle_p2p_get(void *cls, |
308 | const struct GetMessage *gm); | 305 | const struct GetMessage *gm); |
309 | 306 | ||
310 | 307 | ||
311 | /** | 308 | /** |
@@ -315,7 +312,7 @@ handle_p2p_get (void *cls, | |||
315 | * @return performance data record for the peer | 312 | * @return performance data record for the peer |
316 | */ | 313 | */ |
317 | struct GSF_PeerPerformanceData * | 314 | struct GSF_PeerPerformanceData * |
318 | GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp); | 315 | GSF_get_peer_performance_data_(struct GSF_ConnectedPeer *cp); |
319 | 316 | ||
320 | 317 | ||
321 | /** | 318 | /** |
@@ -326,8 +323,8 @@ GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp); | |||
326 | * @param block_time until when to block | 323 | * @param block_time until when to block |
327 | */ | 324 | */ |
328 | void | 325 | void |
329 | GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, | 326 | GSF_block_peer_migration_(struct GSF_ConnectedPeer *cp, |
330 | struct GNUNET_TIME_Absolute block_time); | 327 | struct GNUNET_TIME_Absolute block_time); |
331 | 328 | ||
332 | 329 | ||
333 | /** | 330 | /** |
@@ -339,9 +336,9 @@ GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, | |||
339 | * @param internal_cls our `struct GSF_ConnectedPeer` for @a peer | 336 | * @param internal_cls our `struct GSF_ConnectedPeer` for @a peer |
340 | */ | 337 | */ |
341 | void | 338 | void |
342 | GSF_peer_disconnect_handler (void *cls, | 339 | GSF_peer_disconnect_handler(void *cls, |
343 | const struct GNUNET_PeerIdentity *peer, | 340 | const struct GNUNET_PeerIdentity *peer, |
344 | void *internal_cls); | 341 | void *internal_cls); |
345 | 342 | ||
346 | 343 | ||
347 | /** | 344 | /** |
@@ -351,7 +348,7 @@ GSF_peer_disconnect_handler (void *cls, | |||
351 | * @param lc handle to the local client (henceforth invalid) | 348 | * @param lc handle to the local client (henceforth invalid) |
352 | */ | 349 | */ |
353 | void | 350 | void |
354 | GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc); | 351 | GSF_handle_local_client_disconnect_(const struct GSF_LocalClient *lc); |
355 | 352 | ||
356 | 353 | ||
357 | /** | 354 | /** |
@@ -364,8 +361,8 @@ GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc); | |||
364 | * @param pref preference change | 361 | * @param pref preference change |
365 | */ | 362 | */ |
366 | void | 363 | void |
367 | GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, | 364 | GSF_connected_peer_change_preference_(struct GSF_ConnectedPeer *cp, |
368 | uint64_t pref); | 365 | uint64_t pref); |
369 | 366 | ||
370 | 367 | ||
371 | /** | 368 | /** |
@@ -375,8 +372,8 @@ GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, | |||
375 | * @param id identity to set (written to) | 372 | * @param id identity to set (written to) |
376 | */ | 373 | */ |
377 | void | 374 | void |
378 | GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, | 375 | GSF_connected_peer_get_identity_(const struct GSF_ConnectedPeer *cp, |
379 | struct GNUNET_PeerIdentity *id); | 376 | struct GNUNET_PeerIdentity *id); |
380 | 377 | ||
381 | 378 | ||
382 | /** | 379 | /** |
@@ -386,7 +383,7 @@ GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, | |||
386 | * @return reference to peer identity, valid until peer disconnects (!) | 383 | * @return reference to peer identity, valid until peer disconnects (!) |
387 | */ | 384 | */ |
388 | const struct GNUNET_PeerIdentity * | 385 | const struct GNUNET_PeerIdentity * |
389 | GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp); | 386 | GSF_connected_peer_get_identity2_(const struct GSF_ConnectedPeer *cp); |
390 | 387 | ||
391 | 388 | ||
392 | 389 | ||
@@ -397,21 +394,21 @@ GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp); | |||
397 | * @param it_cls closure for it | 394 | * @param it_cls closure for it |
398 | */ | 395 | */ |
399 | void | 396 | void |
400 | GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, void *it_cls); | 397 | GSF_iterate_connected_peers_(GSF_ConnectedPeerIterator it, void *it_cls); |
401 | 398 | ||
402 | 399 | ||
403 | /** | 400 | /** |
404 | * Initialize peer management subsystem. | 401 | * Initialize peer management subsystem. |
405 | */ | 402 | */ |
406 | void | 403 | void |
407 | GSF_connected_peer_init_ (void); | 404 | GSF_connected_peer_init_(void); |
408 | 405 | ||
409 | 406 | ||
410 | /** | 407 | /** |
411 | * Shutdown peer management subsystem. | 408 | * Shutdown peer management subsystem. |
412 | */ | 409 | */ |
413 | void | 410 | void |
414 | GSF_connected_peer_done_ (void); | 411 | GSF_connected_peer_done_(void); |
415 | 412 | ||
416 | 413 | ||
417 | #endif | 414 | #endif |
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c index df5f70b3d..e21b2ca57 100644 --- a/src/fs/gnunet-service-fs_indexing.c +++ b/src/fs/gnunet-service-fs_indexing.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_indexing.c | 22 | * @file fs/gnunet-service-fs_indexing.c |
@@ -39,9 +39,7 @@ | |||
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 | { | ||
44 | |||
45 | /** | 43 | /** |
46 | * This is a doubly linked list. | 44 | * This is a doubly linked list. |
47 | */ | 45 | */ |
@@ -110,44 +108,44 @@ static struct GNUNET_DATASTORE_Handle *dsh; | |||
110 | * Write the current index information list to disk. | 108 | * Write the current index information list to disk. |
111 | */ | 109 | */ |
112 | static void | 110 | static void |
113 | write_index_list () | 111 | write_index_list() |
114 | { | 112 | { |
115 | struct GNUNET_BIO_WriteHandle *wh; | 113 | struct GNUNET_BIO_WriteHandle *wh; |
116 | char *fn; | 114 | char *fn; |
117 | struct IndexInfo *pos; | 115 | struct IndexInfo *pos; |
118 | 116 | ||
119 | if (GNUNET_OK != | 117 | if (GNUNET_OK != |
120 | GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) | 118 | GNUNET_CONFIGURATION_get_value_filename(cfg, "FS", "INDEXDB", &fn)) |
121 | { | 119 | { |
122 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 120 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
123 | "fs", | 121 | "fs", |
124 | "INDEXDB"); | 122 | "INDEXDB"); |
125 | return; | 123 | return; |
126 | } | 124 | } |
127 | wh = GNUNET_BIO_write_open (fn); | 125 | wh = GNUNET_BIO_write_open(fn); |
128 | if (NULL == wh) | 126 | if (NULL == wh) |
129 | { | 127 | { |
130 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 128 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
131 | _ ("Could not open `%s'.\n"), | 129 | _("Could not open `%s'.\n"), |
132 | fn); | 130 | fn); |
133 | GNUNET_free (fn); | 131 | GNUNET_free(fn); |
134 | return; | 132 | return; |
135 | } | 133 | } |
136 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) | 134 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) |
137 | if ((GNUNET_OK != GNUNET_BIO_write (wh, | 135 | if ((GNUNET_OK != GNUNET_BIO_write(wh, |
138 | &pos->file_id, | 136 | &pos->file_id, |
139 | sizeof (struct GNUNET_HashCode))) || | 137 | sizeof(struct GNUNET_HashCode))) || |
140 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename))) | 138 | (GNUNET_OK != GNUNET_BIO_write_string(wh, pos->filename))) |
141 | break; | 139 | break; |
142 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 140 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
143 | { | 141 | { |
144 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 142 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
145 | _ ("Error writing `%s'.\n"), | 143 | _("Error writing `%s'.\n"), |
146 | fn); | 144 | fn); |
147 | GNUNET_free (fn); | 145 | GNUNET_free(fn); |
148 | return; | 146 | return; |
149 | } | 147 | } |
150 | GNUNET_free (fn); | 148 | GNUNET_free(fn); |
151 | } | 149 | } |
152 | 150 | ||
153 | 151 | ||
@@ -155,7 +153,7 @@ write_index_list () | |||
155 | * Read index information from disk. | 153 | * Read index information from disk. |
156 | */ | 154 | */ |
157 | static void | 155 | static void |
158 | read_index_list () | 156 | read_index_list() |
159 | { | 157 | { |
160 | struct GNUNET_BIO_ReadHandle *rh; | 158 | struct GNUNET_BIO_ReadHandle *rh; |
161 | char *fn; | 159 | char *fn; |
@@ -166,59 +164,59 @@ read_index_list () | |||
166 | char *emsg; | 164 | char *emsg; |
167 | 165 | ||
168 | if (GNUNET_OK != | 166 | if (GNUNET_OK != |
169 | GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) | 167 | GNUNET_CONFIGURATION_get_value_filename(cfg, "FS", "INDEXDB", &fn)) |
170 | { | 168 | { |
171 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 169 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
172 | "fs", | 170 | "fs", |
173 | "INDEXDB"); | 171 | "INDEXDB"); |
174 | return; | 172 | return; |
175 | } | 173 | } |
176 | if (GNUNET_NO == GNUNET_DISK_file_test (fn)) | 174 | if (GNUNET_NO == GNUNET_DISK_file_test(fn)) |
177 | { | 175 | { |
178 | /* no index info yet */ | 176 | /* no index info yet */ |
179 | GNUNET_free (fn); | 177 | GNUNET_free(fn); |
180 | return; | 178 | return; |
181 | } | 179 | } |
182 | rh = GNUNET_BIO_read_open (fn); | 180 | rh = GNUNET_BIO_read_open(fn); |
183 | if (NULL == rh) | 181 | if (NULL == rh) |
184 | { | 182 | { |
185 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 183 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
186 | _ ("Could not open `%s'.\n"), | 184 | _("Could not open `%s'.\n"), |
187 | fn); | 185 | fn); |
188 | GNUNET_free (fn); | 186 | GNUNET_free(fn); |
189 | return; | 187 | return; |
190 | } | 188 | } |
191 | while ( | 189 | while ( |
192 | (GNUNET_OK == GNUNET_BIO_read (rh, | 190 | (GNUNET_OK == GNUNET_BIO_read(rh, |
193 | "Hash of indexed file", | 191 | "Hash of indexed file", |
194 | &hc, | 192 | &hc, |
195 | sizeof (struct GNUNET_HashCode))) && | 193 | sizeof(struct GNUNET_HashCode))) && |
196 | (GNUNET_OK == | 194 | (GNUNET_OK == |
197 | GNUNET_BIO_read_string (rh, "Name of indexed file", &fname, 1024 * 16)) && | 195 | GNUNET_BIO_read_string(rh, "Name of indexed file", &fname, 1024 * 16)) && |
198 | (fname != NULL)) | 196 | (fname != NULL)) |
199 | { | ||
200 | slen = strlen (fname) + 1; | ||
201 | pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen); | ||
202 | pos->file_id = hc; | ||
203 | pos->filename = (const char *) &pos[1]; | ||
204 | GNUNET_memcpy (&pos[1], fname, slen); | ||
205 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( | ||
206 | ifm, | ||
207 | &pos->file_id, | ||
208 | pos, | ||
209 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
210 | { | ||
211 | GNUNET_free (pos); | ||
212 | } | ||
213 | else | ||
214 | { | 197 | { |
215 | GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, pos); | 198 | slen = strlen(fname) + 1; |
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 | } | 216 | } |
217 | GNUNET_free (fname); | 217 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
218 | } | 218 | GNUNET_free(emsg); |
219 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 219 | GNUNET_free(fn); |
220 | GNUNET_free (emsg); | ||
221 | GNUNET_free (fn); | ||
222 | } | 220 | } |
223 | 221 | ||
224 | 222 | ||
@@ -232,15 +230,15 @@ read_index_list () | |||
232 | * @param msg error message | 230 | * @param msg error message |
233 | */ | 231 | */ |
234 | static void | 232 | static void |
235 | remove_cont (void *cls, | 233 | remove_cont(void *cls, |
236 | int success, | 234 | int success, |
237 | struct GNUNET_TIME_Absolute min_expiration, | 235 | struct GNUNET_TIME_Absolute min_expiration, |
238 | const char *msg) | 236 | const char *msg) |
239 | { | 237 | { |
240 | if (GNUNET_OK != success) | 238 | if (GNUNET_OK != success) |
241 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 239 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
242 | _ ("Failed to delete bogus block: %s\n"), | 240 | _("Failed to delete bogus block: %s\n"), |
243 | msg); | 241 | msg); |
244 | } | 242 | } |
245 | 243 | ||
246 | 244 | ||
@@ -265,17 +263,17 @@ remove_cont (void *cls, | |||
265 | * @return GNUNET_OK on success | 263 | * @return GNUNET_OK on success |
266 | */ | 264 | */ |
267 | int | 265 | int |
268 | GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, | 266 | GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, |
269 | uint32_t size, | 267 | uint32_t size, |
270 | const void *data, | 268 | const void *data, |
271 | enum GNUNET_BLOCK_Type type, | 269 | enum GNUNET_BLOCK_Type type, |
272 | uint32_t priority, | 270 | uint32_t priority, |
273 | uint32_t anonymity, | 271 | uint32_t anonymity, |
274 | uint32_t replication, | 272 | uint32_t replication, |
275 | struct GNUNET_TIME_Absolute expiration, | 273 | struct GNUNET_TIME_Absolute expiration, |
276 | uint64_t uid, | 274 | uint64_t uid, |
277 | GNUNET_DATASTORE_DatumProcessor cont, | 275 | GNUNET_DATASTORE_DatumProcessor cont, |
278 | void *cont_cls) | 276 | void *cont_cls) |
279 | { | 277 | { |
280 | const struct OnDemandBlock *odb; | 278 | const struct OnDemandBlock *odb; |
281 | struct GNUNET_HashCode nkey; | 279 | struct GNUNET_HashCode nkey; |
@@ -290,79 +288,79 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, | |||
290 | uint64_t off; | 288 | uint64_t off; |
291 | struct IndexInfo *ii; | 289 | struct IndexInfo *ii; |
292 | 290 | ||
293 | if (size != sizeof (struct OnDemandBlock)) | 291 | if (size != sizeof(struct OnDemandBlock)) |
294 | { | 292 | { |
295 | GNUNET_break (0); | 293 | GNUNET_break(0); |
296 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); | 294 | GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); |
297 | return GNUNET_SYSERR; | 295 | return GNUNET_SYSERR; |
298 | } | 296 | } |
299 | odb = (const struct OnDemandBlock *) data; | 297 | odb = (const struct OnDemandBlock *)data; |
300 | off = GNUNET_ntohll (odb->offset); | 298 | off = GNUNET_ntohll(odb->offset); |
301 | ii = GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id); | 299 | ii = GNUNET_CONTAINER_multihashmap_get(ifm, &odb->file_id); |
302 | if (NULL == ii) | 300 | if (NULL == ii) |
303 | { | 301 | { |
304 | GNUNET_break (0); | 302 | GNUNET_break(0); |
305 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 303 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
306 | "Failed to find index %s\n", | 304 | "Failed to find index %s\n", |
307 | GNUNET_h2s (&odb->file_id)); | 305 | GNUNET_h2s(&odb->file_id)); |
308 | return GNUNET_SYSERR; | 306 | return GNUNET_SYSERR; |
309 | } | 307 | } |
310 | fn = ii->filename; | 308 | fn = ii->filename; |
311 | if ((NULL == fn) || (0 != access (fn, R_OK))) | 309 | if ((NULL == fn) || (0 != access(fn, R_OK))) |
312 | { | 310 | { |
313 | GNUNET_STATISTICS_update ( | 311 | GNUNET_STATISTICS_update( |
314 | GSF_stats, | 312 | GSF_stats, |
315 | gettext_noop ("# index blocks removed: original file inaccessible"), | 313 | gettext_noop("# index blocks removed: original file inaccessible"), |
316 | 1, | 314 | 1, |
317 | GNUNET_YES); | 315 | GNUNET_YES); |
318 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); | 316 | GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); |
319 | return GNUNET_SYSERR; | 317 | return GNUNET_SYSERR; |
320 | } | 318 | } |
321 | if ((NULL == (fh = GNUNET_DISK_file_open (fn, | 319 | if ((NULL == (fh = GNUNET_DISK_file_open(fn, |
322 | GNUNET_DISK_OPEN_READ, | 320 | GNUNET_DISK_OPEN_READ, |
323 | GNUNET_DISK_PERM_NONE))) || | 321 | GNUNET_DISK_PERM_NONE))) || |
324 | (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) || | 322 | (off != GNUNET_DISK_file_seek(fh, off, GNUNET_DISK_SEEK_SET)) || |
325 | (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata))))) | 323 | (-1 == (nsize = GNUNET_DISK_file_read(fh, ndata, sizeof(ndata))))) |
326 | { | 324 | { |
327 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 325 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
328 | _ ( | 326 | _( |
329 | "Could not access indexed file `%s' (%s) at offset %llu: %s\n"), | 327 | "Could not access indexed file `%s' (%s) at offset %llu: %s\n"), |
330 | GNUNET_h2s (&odb->file_id), | 328 | GNUNET_h2s(&odb->file_id), |
331 | fn, | 329 | fn, |
332 | (unsigned long long) off, | 330 | (unsigned long long)off, |
333 | (fn == NULL) ? _ ("not indexed") : strerror (errno)); | 331 | (fn == NULL) ? _("not indexed") : strerror(errno)); |
334 | if (fh != NULL) | 332 | if (fh != NULL) |
335 | GNUNET_DISK_file_close (fh); | 333 | GNUNET_DISK_file_close(fh); |
336 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); | 334 | GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); |
337 | return GNUNET_SYSERR; | 335 | return GNUNET_SYSERR; |
338 | } | 336 | } |
339 | GNUNET_DISK_file_close (fh); | 337 | GNUNET_DISK_file_close(fh); |
340 | GNUNET_CRYPTO_hash (ndata, nsize, &nkey); | 338 | GNUNET_CRYPTO_hash(ndata, nsize, &nkey); |
341 | GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv); | 339 | GNUNET_CRYPTO_hash_to_aes_key(&nkey, &skey, &iv); |
342 | GNUNET_CRYPTO_symmetric_encrypt (ndata, nsize, &skey, &iv, edata); | 340 | GNUNET_CRYPTO_symmetric_encrypt(ndata, nsize, &skey, &iv, edata); |
343 | GNUNET_CRYPTO_hash (edata, nsize, &query); | 341 | GNUNET_CRYPTO_hash(edata, nsize, &query); |
344 | if (0 != memcmp (&query, key, sizeof (struct GNUNET_HashCode))) | 342 | if (0 != memcmp(&query, key, sizeof(struct GNUNET_HashCode))) |
345 | { | 343 | { |
346 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 344 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
347 | _ ("Indexed file `%s' changed at offset %llu\n"), | 345 | _("Indexed file `%s' changed at offset %llu\n"), |
348 | fn, | 346 | fn, |
349 | (unsigned long long) off); | 347 | (unsigned long long)off); |
350 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); | 348 | GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); |
351 | return GNUNET_SYSERR; | 349 | return GNUNET_SYSERR; |
352 | } | 350 | } |
353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 351 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
354 | "On-demand encoded block for query `%s'\n", | 352 | "On-demand encoded block for query `%s'\n", |
355 | GNUNET_h2s (key)); | 353 | GNUNET_h2s(key)); |
356 | cont (cont_cls, | 354 | cont(cont_cls, |
357 | key, | 355 | key, |
358 | nsize, | 356 | nsize, |
359 | edata, | 357 | edata, |
360 | GNUNET_BLOCK_TYPE_FS_DBLOCK, | 358 | GNUNET_BLOCK_TYPE_FS_DBLOCK, |
361 | priority, | 359 | priority, |
362 | anonymity, | 360 | anonymity, |
363 | replication, | 361 | replication, |
364 | expiration, | 362 | expiration, |
365 | uid); | 363 | uid); |
366 | return GNUNET_OK; | 364 | return GNUNET_OK; |
367 | } | 365 | } |
368 | 366 | ||
@@ -373,7 +371,7 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, | |||
373 | * @param mq message queue to send information to | 371 | * @param mq message queue to send information to |
374 | */ | 372 | */ |
375 | void | 373 | void |
376 | GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq) | 374 | GNUNET_FS_indexing_send_list(struct GNUNET_MQ_Handle *mq) |
377 | { | 375 | { |
378 | struct GNUNET_MQ_Envelope *env; | 376 | struct GNUNET_MQ_Envelope *env; |
379 | struct IndexInfoMessage *iim; | 377 | struct IndexInfoMessage *iim; |
@@ -383,23 +381,23 @@ GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq) | |||
383 | struct IndexInfo *pos; | 381 | struct IndexInfo *pos; |
384 | 382 | ||
385 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) | 383 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) |
386 | { | ||
387 | fn = pos->filename; | ||
388 | slen = strlen (fn) + 1; | ||
389 | if (slen + sizeof (struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE) | ||
390 | { | 384 | { |
391 | GNUNET_break (0); | 385 | fn = pos->filename; |
392 | break; | 386 | slen = strlen(fn) + 1; |
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); | ||
393 | } | 398 | } |
394 | env = | 399 | env = GNUNET_MQ_msg(iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); |
395 | GNUNET_MQ_msg_extra (iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); | 400 | GNUNET_MQ_send(mq, env); |
396 | iim->reserved = 0; | ||
397 | iim->file_id = pos->file_id; | ||
398 | GNUNET_memcpy (&iim[1], fn, slen); | ||
399 | GNUNET_MQ_send (mq, env); | ||
400 | } | ||
401 | env = GNUNET_MQ_msg (iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); | ||
402 | GNUNET_MQ_send (mq, env); | ||
403 | } | 401 | } |
404 | 402 | ||
405 | 403 | ||
@@ -410,23 +408,23 @@ GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq) | |||
410 | * @return #GNUNET_YES if the @a fid was found | 408 | * @return #GNUNET_YES if the @a fid was found |
411 | */ | 409 | */ |
412 | int | 410 | int |
413 | GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid) | 411 | GNUNET_FS_indexing_do_unindex(const struct GNUNET_HashCode *fid) |
414 | { | 412 | { |
415 | struct IndexInfo *pos; | 413 | struct IndexInfo *pos; |
416 | 414 | ||
417 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) | 415 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) |
418 | { | ||
419 | if (0 == memcmp (&pos->file_id, fid, sizeof (struct GNUNET_HashCode))) | ||
420 | { | 416 | { |
421 | GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); | 417 | if (0 == memcmp(&pos->file_id, fid, sizeof(struct GNUNET_HashCode))) |
422 | GNUNET_break ( | 418 | { |
423 | GNUNET_OK == | 419 | GNUNET_CONTAINER_DLL_remove(indexed_files_head, indexed_files_tail, pos); |
424 | GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); | 420 | GNUNET_break( |
425 | GNUNET_free (pos); | 421 | GNUNET_OK == |
426 | write_index_list (); | 422 | GNUNET_CONTAINER_multihashmap_remove(ifm, &pos->file_id, pos)); |
427 | return GNUNET_YES; | 423 | GNUNET_free(pos); |
424 | write_index_list(); | ||
425 | return GNUNET_YES; | ||
426 | } | ||
428 | } | 427 | } |
429 | } | ||
430 | return GNUNET_NO; | 428 | return GNUNET_NO; |
431 | } | 429 | } |
432 | 430 | ||
@@ -438,40 +436,40 @@ GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid) | |||
438 | * @param file_id hash identifier for @a filename | 436 | * @param file_id hash identifier for @a filename |
439 | */ | 437 | */ |
440 | void | 438 | void |
441 | GNUNET_FS_add_to_index (const char *filename, | 439 | GNUNET_FS_add_to_index(const char *filename, |
442 | const struct GNUNET_HashCode *file_id) | 440 | const struct GNUNET_HashCode *file_id) |
443 | { | 441 | { |
444 | struct IndexInfo *ii; | 442 | struct IndexInfo *ii; |
445 | size_t slen; | 443 | size_t slen; |
446 | 444 | ||
447 | ii = GNUNET_CONTAINER_multihashmap_get (ifm, file_id); | 445 | ii = GNUNET_CONTAINER_multihashmap_get(ifm, file_id); |
448 | if (NULL != ii) | 446 | if (NULL != ii) |
449 | { | 447 | { |
450 | GNUNET_log ( | 448 | GNUNET_log( |
451 | GNUNET_ERROR_TYPE_INFO, | 449 | GNUNET_ERROR_TYPE_INFO, |
452 | _ ( | 450 | _( |
453 | "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), | 451 | "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), |
454 | filename, | 452 | filename, |
455 | ii->filename); | 453 | ii->filename); |
456 | return; | 454 | return; |
457 | } | 455 | } |
458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 456 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
459 | "Adding file %s to index as %s\n", | 457 | "Adding file %s to index as %s\n", |
460 | filename, | 458 | filename, |
461 | GNUNET_h2s (file_id)); | 459 | GNUNET_h2s(file_id)); |
462 | slen = strlen (filename) + 1; | 460 | slen = strlen(filename) + 1; |
463 | ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen); | 461 | ii = GNUNET_malloc(sizeof(struct IndexInfo) + slen); |
464 | ii->file_id = *file_id; | 462 | ii->file_id = *file_id; |
465 | ii->filename = (const char *) &ii[1]; | 463 | ii->filename = (const char *)&ii[1]; |
466 | GNUNET_memcpy (&ii[1], filename, slen); | 464 | GNUNET_memcpy(&ii[1], filename, slen); |
467 | GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, ii); | 465 | GNUNET_CONTAINER_DLL_insert(indexed_files_head, indexed_files_tail, ii); |
468 | GNUNET_assert (GNUNET_OK == | 466 | GNUNET_assert(GNUNET_OK == |
469 | GNUNET_CONTAINER_multihashmap_put ( | 467 | GNUNET_CONTAINER_multihashmap_put( |
470 | ifm, | 468 | ifm, |
471 | &ii->file_id, | 469 | &ii->file_id, |
472 | ii, | 470 | ii, |
473 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 471 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
474 | write_index_list (); | 472 | write_index_list(); |
475 | } | 473 | } |
476 | 474 | ||
477 | 475 | ||
@@ -479,21 +477,21 @@ GNUNET_FS_add_to_index (const char *filename, | |||
479 | * Shutdown the module. | 477 | * Shutdown the module. |
480 | */ | 478 | */ |
481 | void | 479 | void |
482 | GNUNET_FS_indexing_done () | 480 | GNUNET_FS_indexing_done() |
483 | { | 481 | { |
484 | struct IndexInfo *pos; | 482 | struct IndexInfo *pos; |
485 | 483 | ||
486 | while (NULL != (pos = indexed_files_head)) | 484 | while (NULL != (pos = indexed_files_head)) |
487 | { | 485 | { |
488 | GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); | 486 | GNUNET_CONTAINER_DLL_remove(indexed_files_head, indexed_files_tail, pos); |
489 | if (pos->fhc != NULL) | 487 | if (pos->fhc != NULL) |
490 | GNUNET_CRYPTO_hash_file_cancel (pos->fhc); | 488 | GNUNET_CRYPTO_hash_file_cancel(pos->fhc); |
491 | GNUNET_break ( | 489 | GNUNET_break( |
492 | GNUNET_OK == | 490 | GNUNET_OK == |
493 | GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); | 491 | GNUNET_CONTAINER_multihashmap_remove(ifm, &pos->file_id, pos)); |
494 | GNUNET_free (pos); | 492 | GNUNET_free(pos); |
495 | } | 493 | } |
496 | GNUNET_CONTAINER_multihashmap_destroy (ifm); | 494 | GNUNET_CONTAINER_multihashmap_destroy(ifm); |
497 | ifm = NULL; | 495 | ifm = NULL; |
498 | cfg = NULL; | 496 | cfg = NULL; |
499 | } | 497 | } |
@@ -506,13 +504,13 @@ GNUNET_FS_indexing_done () | |||
506 | * @param d datastore to use | 504 | * @param d datastore to use |
507 | */ | 505 | */ |
508 | int | 506 | int |
509 | GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, | 507 | GNUNET_FS_indexing_init(const struct GNUNET_CONFIGURATION_Handle *c, |
510 | struct GNUNET_DATASTORE_Handle *d) | 508 | struct GNUNET_DATASTORE_Handle *d) |
511 | { | 509 | { |
512 | cfg = c; | 510 | cfg = c; |
513 | dsh = d; | 511 | dsh = d; |
514 | ifm = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES); | 512 | ifm = GNUNET_CONTAINER_multihashmap_create(128, GNUNET_YES); |
515 | read_index_list (); | 513 | read_index_list(); |
516 | return GNUNET_OK; | 514 | return GNUNET_OK; |
517 | } | 515 | } |
518 | 516 | ||
diff --git a/src/fs/gnunet-service-fs_indexing.h b/src/fs/gnunet-service-fs_indexing.h index d6166f0a9..4c137d7a6 100644 --- a/src/fs/gnunet-service-fs_indexing.h +++ b/src/fs/gnunet-service-fs_indexing.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_indexing.h | 22 | * @file 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 5e85bfdb7..3c1112333 100644 --- a/src/fs/gnunet-service-fs_pe.c +++ b/src/fs/gnunet-service-fs_pe.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_pe.c | 22 | * @file fs/gnunet-service-fs_pe.c |
@@ -63,9 +63,7 @@ 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 | { | ||
68 | |||
69 | /** | 67 | /** |
70 | * This is a doubly-linked list. | 68 | * This is a doubly-linked list. |
71 | */ | 69 | */ |
@@ -97,7 +95,6 @@ struct GSF_PendingRequestPlanBijection | |||
97 | * and one of the origins of the request). | 95 | * and one of the origins of the request). |
98 | */ | 96 | */ |
99 | struct GSF_PendingRequest *pr; | 97 | struct GSF_PendingRequest *pr; |
100 | |||
101 | }; | 98 | }; |
102 | 99 | ||
103 | 100 | ||
@@ -107,9 +104,7 @@ struct GSF_PendingRequestPlanBijection | |||
107 | * with one entry in each heap of each `struct PeerPlan`. Each | 104 | * with one entry in each heap of each `struct PeerPlan`. Each |
108 | * entry tracks information relevant for this request and this peer. | 105 | * entry tracks information relevant for this request and this peer. |
109 | */ | 106 | */ |
110 | struct GSF_RequestPlan | 107 | struct GSF_RequestPlan { |
111 | { | ||
112 | |||
113 | /** | 108 | /** |
114 | * This is a doubly-linked list. | 109 | * This is a doubly-linked list. |
115 | */ | 110 | */ |
@@ -161,15 +156,13 @@ struct GSF_RequestPlan | |||
161 | * How often did we transmit this request to this peer? | 156 | * How often did we transmit this request to this peer? |
162 | */ | 157 | */ |
163 | unsigned int transmission_counter; | 158 | unsigned int transmission_counter; |
164 | |||
165 | }; | 159 | }; |
166 | 160 | ||
167 | 161 | ||
168 | /** | 162 | /** |
169 | * Transmission plan for a peer. | 163 | * Transmission plan for a peer. |
170 | */ | 164 | */ |
171 | struct PeerPlan | 165 | struct PeerPlan { |
172 | { | ||
173 | /** | 166 | /** |
174 | * Heap with pending queries (`struct GSF_RequestPlan`), higher weights mean higher priority. | 167 | * Heap with pending queries (`struct GSF_RequestPlan`), higher weights mean higher priority. |
175 | */ | 168 | */ |
@@ -202,7 +195,6 @@ struct PeerPlan | |||
202 | * Current message under transmission for the plan. | 195 | * Current message under transmission for the plan. |
203 | */ | 196 | */ |
204 | struct GNUNET_MQ_Envelope *env; | 197 | struct GNUNET_MQ_Envelope *env; |
205 | |||
206 | }; | 198 | }; |
207 | 199 | ||
208 | 200 | ||
@@ -235,9 +227,9 @@ static unsigned long long plan_count; | |||
235 | * @return the associated query | 227 | * @return the associated query |
236 | */ | 228 | */ |
237 | static const struct GNUNET_HashCode * | 229 | static const struct GNUNET_HashCode * |
238 | get_rp_key (struct GSF_RequestPlan *rp) | 230 | get_rp_key(struct GSF_RequestPlan *rp) |
239 | { | 231 | { |
240 | return &GSF_pending_request_get_data_ (rp->pe_head->pr)->query; | 232 | return &GSF_pending_request_get_data_(rp->pe_head->pr)->query; |
241 | } | 233 | } |
242 | 234 | ||
243 | 235 | ||
@@ -248,8 +240,8 @@ get_rp_key (struct GSF_RequestPlan *rp) | |||
248 | * @param rp request to plan | 240 | * @param rp request to plan |
249 | */ | 241 | */ |
250 | static void | 242 | static void |
251 | plan (struct PeerPlan *pp, | 243 | plan(struct PeerPlan *pp, |
252 | struct GSF_RequestPlan *rp) | 244 | struct GSF_RequestPlan *rp) |
253 | { | 245 | { |
254 | #define N ((double)128.0) | 246 | #define N ((double)128.0) |
255 | /** | 247 | /** |
@@ -260,28 +252,28 @@ plan (struct PeerPlan *pp, | |||
260 | struct GSF_PendingRequestData *prd; | 252 | struct GSF_PendingRequestData *prd; |
261 | struct GNUNET_TIME_Relative delay; | 253 | struct GNUNET_TIME_Relative delay; |
262 | 254 | ||
263 | GNUNET_assert (rp->pp == pp); | 255 | GNUNET_assert(rp->pp == pp); |
264 | GNUNET_STATISTICS_set (GSF_stats, | 256 | GNUNET_STATISTICS_set(GSF_stats, |
265 | gettext_noop ("# average retransmission delay (ms)"), | 257 | gettext_noop("# average retransmission delay (ms)"), |
266 | total_delay * 1000LL / plan_count, GNUNET_NO); | 258 | total_delay * 1000LL / plan_count, GNUNET_NO); |
267 | prd = GSF_pending_request_get_data_ (rp->pe_head->pr); | 259 | prd = GSF_pending_request_get_data_(rp->pe_head->pr); |
268 | 260 | ||
269 | if (rp->transmission_counter < 8) | 261 | if (rp->transmission_counter < 8) |
270 | delay = | 262 | delay = |
271 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 263 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
272 | rp->transmission_counter); | 264 | rp->transmission_counter); |
273 | else if (rp->transmission_counter < 32) | 265 | else if (rp->transmission_counter < 32) |
274 | delay = | 266 | delay = |
275 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 267 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
276 | 8 + | 268 | 8 + |
277 | (1LL << (rp->transmission_counter - 8))); | 269 | (1LL << (rp->transmission_counter - 8))); |
278 | else | 270 | else |
279 | delay = | 271 | delay = |
280 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 272 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
281 | 8 + (1LL << 24)); | 273 | 8 + (1LL << 24)); |
282 | delay.rel_value_us = | 274 | delay.rel_value_us = |
283 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 275 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
284 | delay.rel_value_us + 1); | 276 | delay.rel_value_us + 1); |
285 | /* Add 0.01 to avg_delay to avoid division-by-zero later */ | 277 | /* Add 0.01 to avg_delay to avoid division-by-zero later */ |
286 | avg_delay = (((avg_delay * (N - 1.0)) + delay.rel_value_us) / N) + 0.01; | 278 | avg_delay = (((avg_delay * (N - 1.0)) + delay.rel_value_us) / N) + 0.01; |
287 | 279 | ||
@@ -307,36 +299,36 @@ plan (struct PeerPlan *pp, | |||
307 | * Note: M_PI_4 = PI/4 = arctan(1) | 299 | * Note: M_PI_4 = PI/4 = arctan(1) |
308 | */ | 300 | */ |
309 | rp->priority = | 301 | rp->priority = |
310 | round ((GSF_current_priorities + | 302 | round((GSF_current_priorities + |
311 | 1.0) * atan (delay.rel_value_us / avg_delay)) / M_PI_4; | 303 | 1.0) * atan(delay.rel_value_us / avg_delay)) / M_PI_4; |
312 | /* Note: usage of 'round' and 'atan' requires -lm */ | 304 | /* Note: usage of 'round' and 'atan' requires -lm */ |
313 | 305 | ||
314 | if (rp->transmission_counter != 0) | 306 | if (rp->transmission_counter != 0) |
315 | delay.rel_value_us += TTL_DECREMENT * 1000; | 307 | delay.rel_value_us += TTL_DECREMENT * 1000; |
316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 308 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
317 | "Considering (re)transmission number %u in %s\n", | 309 | "Considering (re)transmission number %u in %s\n", |
318 | (unsigned int) rp->transmission_counter, | 310 | (unsigned int)rp->transmission_counter, |
319 | GNUNET_STRINGS_relative_time_to_string (delay, | 311 | GNUNET_STRINGS_relative_time_to_string(delay, |
320 | GNUNET_YES)); | 312 | GNUNET_YES)); |
321 | rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay); | 313 | rp->earliest_transmission = GNUNET_TIME_relative_to_absolute(delay); |
322 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 314 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
323 | "Earliest (re)transmission for `%s' in %us\n", | 315 | "Earliest (re)transmission for `%s' in %us\n", |
324 | GNUNET_h2s (&prd->query), | 316 | GNUNET_h2s(&prd->query), |
325 | rp->transmission_counter); | 317 | rp->transmission_counter); |
326 | GNUNET_assert (rp->hn == NULL); | 318 | GNUNET_assert(rp->hn == NULL); |
327 | if (0 == GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).rel_value_us) | 319 | if (0 == GNUNET_TIME_absolute_get_remaining(rp->earliest_transmission).rel_value_us) |
328 | rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, | 320 | rp->hn = GNUNET_CONTAINER_heap_insert(pp->priority_heap, |
329 | rp, | 321 | rp, |
330 | rp->priority); | 322 | rp->priority); |
331 | else | 323 | else |
332 | rp->hn = | 324 | rp->hn = |
333 | GNUNET_CONTAINER_heap_insert (pp->delay_heap, | 325 | GNUNET_CONTAINER_heap_insert(pp->delay_heap, |
334 | rp, | 326 | rp, |
335 | rp->earliest_transmission.abs_value_us); | 327 | rp->earliest_transmission.abs_value_us); |
336 | GNUNET_assert (GNUNET_YES == | 328 | GNUNET_assert(GNUNET_YES == |
337 | GNUNET_CONTAINER_multihashmap_contains_value (pp->plan_map, | 329 | GNUNET_CONTAINER_multihashmap_contains_value(pp->plan_map, |
338 | get_rp_key (rp), | 330 | get_rp_key(rp), |
339 | rp)); | 331 | rp)); |
340 | #undef N | 332 | #undef N |
341 | } | 333 | } |
342 | 334 | ||
@@ -348,7 +340,7 @@ plan (struct PeerPlan *pp, | |||
348 | * @return pending request with highest TTL | 340 | * @return pending request with highest TTL |
349 | */ | 341 | */ |
350 | struct GSF_PendingRequest * | 342 | struct GSF_PendingRequest * |
351 | get_latest (const struct GSF_RequestPlan *rp) | 343 | get_latest(const struct GSF_RequestPlan *rp) |
352 | { | 344 | { |
353 | struct GSF_PendingRequest *ret; | 345 | struct GSF_PendingRequest *ret; |
354 | struct GSF_PendingRequestPlanBijection *bi; | 346 | struct GSF_PendingRequestPlanBijection *bi; |
@@ -359,18 +351,18 @@ get_latest (const struct GSF_RequestPlan *rp) | |||
359 | if (NULL == bi) | 351 | if (NULL == bi) |
360 | return NULL; /* should never happen */ | 352 | return NULL; /* should never happen */ |
361 | ret = bi->pr; | 353 | ret = bi->pr; |
362 | rprd = GSF_pending_request_get_data_ (ret); | 354 | rprd = GSF_pending_request_get_data_(ret); |
363 | for (bi = bi->next_PE; NULL != bi; bi = bi->next_PE) | 355 | for (bi = bi->next_PE; NULL != bi; bi = bi->next_PE) |
364 | { | ||
365 | GNUNET_break (GNUNET_YES == | ||
366 | GSF_pending_request_test_active_ (bi->pr)); | ||
367 | prd = GSF_pending_request_get_data_ (bi->pr); | ||
368 | if (prd->ttl.abs_value_us > rprd->ttl.abs_value_us) | ||
369 | { | 356 | { |
370 | ret = bi->pr; | 357 | GNUNET_break(GNUNET_YES == |
371 | rprd = prd; | 358 | GSF_pending_request_test_active_(bi->pr)); |
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 | } | ||
372 | } | 365 | } |
373 | } | ||
374 | return ret; | 366 | return ret; |
375 | } | 367 | } |
376 | 368 | ||
@@ -381,102 +373,100 @@ get_latest (const struct GSF_RequestPlan *rp) | |||
381 | * @param cls the `struct PeerPlan` | 373 | * @param cls the `struct PeerPlan` |
382 | */ | 374 | */ |
383 | static void | 375 | static void |
384 | schedule_peer_transmission (void *cls) | 376 | schedule_peer_transmission(void *cls) |
385 | { | 377 | { |
386 | struct PeerPlan *pp = cls; | 378 | struct PeerPlan *pp = cls; |
387 | struct GSF_RequestPlan *rp; | 379 | struct GSF_RequestPlan *rp; |
388 | struct GNUNET_TIME_Relative delay; | 380 | struct GNUNET_TIME_Relative delay; |
389 | 381 | ||
390 | if (NULL != pp->task) | 382 | if (NULL != pp->task) |
391 | { | 383 | { |
392 | pp->task = NULL; | 384 | pp->task = NULL; |
393 | } | 385 | } |
394 | else | 386 | else |
395 | { | 387 | { |
396 | GNUNET_assert (NULL != pp->env); | 388 | GNUNET_assert(NULL != pp->env); |
397 | pp->env = NULL; | 389 | pp->env = NULL; |
398 | } | 390 | } |
399 | /* move ready requests to priority queue */ | 391 | /* move ready requests to priority queue */ |
400 | while ((NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) && | 392 | while ((NULL != (rp = GNUNET_CONTAINER_heap_peek(pp->delay_heap))) && |
401 | (0 == GNUNET_TIME_absolute_get_remaining | 393 | (0 == GNUNET_TIME_absolute_get_remaining |
402 | (rp->earliest_transmission).rel_value_us)) | 394 | (rp->earliest_transmission).rel_value_us)) |
403 | { | ||
404 | GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->delay_heap)); | ||
405 | rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, | ||
406 | rp, | ||
407 | rp->priority); | ||
408 | } | ||
409 | if (0 == GNUNET_CONTAINER_heap_get_size (pp->priority_heap)) | ||
410 | { | ||
411 | /* priority heap (still) empty, check for delay... */ | ||
412 | rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap); | ||
413 | if (NULL == rp) | ||
414 | { | 395 | { |
415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 396 | GNUNET_assert(rp == GNUNET_CONTAINER_heap_remove_root(pp->delay_heap)); |
416 | "No active requests for plan %p.\n", | 397 | rp->hn = GNUNET_CONTAINER_heap_insert(pp->priority_heap, |
417 | pp); | 398 | rp, |
418 | return; /* both queues empty */ | 399 | rp->priority); |
400 | } | ||
401 | if (0 == GNUNET_CONTAINER_heap_get_size(pp->priority_heap)) | ||
402 | { | ||
403 | /* priority heap (still) empty, check for delay... */ | ||
404 | rp = GNUNET_CONTAINER_heap_peek(pp->delay_heap); | ||
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), | ||
417 | pp); | ||
418 | GNUNET_STATISTICS_set(GSF_stats, | ||
419 | gettext_noop("# delay heap timeout (ms)"), | ||
420 | delay.rel_value_us / 1000LL, GNUNET_NO); | ||
421 | |||
422 | pp->task | ||
423 | = GNUNET_SCHEDULER_add_at(rp->earliest_transmission, | ||
424 | &schedule_peer_transmission, | ||
425 | pp); | ||
426 | return; | ||
419 | } | 427 | } |
420 | delay = GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission); | ||
421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
422 | "Sleeping for %s before retrying requests on plan %p.\n", | ||
423 | GNUNET_STRINGS_relative_time_to_string (delay, | ||
424 | GNUNET_YES), | ||
425 | pp); | ||
426 | GNUNET_STATISTICS_set (GSF_stats, | ||
427 | gettext_noop ("# delay heap timeout (ms)"), | ||
428 | delay.rel_value_us / 1000LL, GNUNET_NO); | ||
429 | |||
430 | pp->task | ||
431 | = GNUNET_SCHEDULER_add_at (rp->earliest_transmission, | ||
432 | &schedule_peer_transmission, | ||
433 | pp); | ||
434 | return; | ||
435 | } | ||
436 | #if INSANE_STATISTICS | 428 | #if INSANE_STATISTICS |
437 | GNUNET_STATISTICS_update (GSF_stats, | 429 | GNUNET_STATISTICS_update(GSF_stats, |
438 | gettext_noop ("# query plans executed"), | 430 | gettext_noop("# query plans executed"), |
439 | 1, | 431 | 1, |
440 | GNUNET_NO); | 432 | GNUNET_NO); |
441 | #endif | 433 | #endif |
442 | /* process from priority heap */ | 434 | /* process from priority heap */ |
443 | rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap); | 435 | rp = GNUNET_CONTAINER_heap_remove_root(pp->priority_heap); |
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 436 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
445 | "Executing query plan %p\n", | 437 | "Executing query plan %p\n", |
446 | rp); | 438 | rp); |
447 | GNUNET_assert (NULL != rp); | 439 | GNUNET_assert(NULL != rp); |
448 | rp->hn = NULL; | 440 | rp->hn = NULL; |
449 | rp->last_transmission = GNUNET_TIME_absolute_get (); | 441 | rp->last_transmission = GNUNET_TIME_absolute_get(); |
450 | rp->transmission_counter++; | 442 | rp->transmission_counter++; |
451 | total_delay++; | 443 | total_delay++; |
452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 444 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
453 | "Executing plan %p executed %u times, planning retransmission\n", | 445 | "Executing plan %p executed %u times, planning retransmission\n", |
454 | rp, | 446 | rp, |
455 | rp->transmission_counter); | 447 | rp->transmission_counter); |
456 | GNUNET_assert (NULL == pp->env); | 448 | GNUNET_assert(NULL == pp->env); |
457 | pp->env = GSF_pending_request_get_message_ (get_latest (rp)); | 449 | pp->env = GSF_pending_request_get_message_(get_latest(rp)); |
458 | GNUNET_MQ_notify_sent (pp->env, | 450 | GNUNET_MQ_notify_sent(pp->env, |
459 | &schedule_peer_transmission, | 451 | &schedule_peer_transmission, |
460 | pp); | 452 | pp); |
461 | GSF_peer_transmit_ (pp->cp, | 453 | GSF_peer_transmit_(pp->cp, |
462 | GNUNET_YES, | 454 | GNUNET_YES, |
463 | rp->priority, | 455 | rp->priority, |
464 | pp->env); | 456 | pp->env); |
465 | GNUNET_STATISTICS_update (GSF_stats, | 457 | GNUNET_STATISTICS_update(GSF_stats, |
466 | gettext_noop ("# query messages sent to other peers"), | 458 | gettext_noop("# query messages sent to other peers"), |
467 | 1, | 459 | 1, |
468 | GNUNET_NO); | 460 | GNUNET_NO); |
469 | plan (pp, | 461 | plan(pp, |
470 | rp); | 462 | rp); |
471 | } | 463 | } |
472 | 464 | ||
473 | 465 | ||
474 | /** | 466 | /** |
475 | * Closure for merge_pr(). | 467 | * Closure for merge_pr(). |
476 | */ | 468 | */ |
477 | struct MergeContext | 469 | struct MergeContext { |
478 | { | ||
479 | |||
480 | /** | 470 | /** |
481 | * Request we are trying to merge. | 471 | * Request we are trying to merge. |
482 | */ | 472 | */ |
@@ -486,7 +476,6 @@ struct MergeContext | |||
486 | * Set to #GNUNET_YES if we succeeded to merge. | 476 | * Set to #GNUNET_YES if we succeeded to merge. |
487 | */ | 477 | */ |
488 | int merged; | 478 | int merged; |
489 | |||
490 | }; | 479 | }; |
491 | 480 | ||
492 | 481 | ||
@@ -501,9 +490,9 @@ struct MergeContext | |||
501 | * #GNUNET_NO if not (merge success) | 490 | * #GNUNET_NO if not (merge success) |
502 | */ | 491 | */ |
503 | static int | 492 | static int |
504 | merge_pr (void *cls, | 493 | merge_pr(void *cls, |
505 | const struct GNUNET_HashCode *query, | 494 | const struct GNUNET_HashCode *query, |
506 | void *element) | 495 | void *element) |
507 | { | 496 | { |
508 | struct MergeContext *mpr = cls; | 497 | struct MergeContext *mpr = cls; |
509 | struct GSF_RequestPlan *rp = element; | 498 | struct GSF_RequestPlan *rp = element; |
@@ -511,44 +500,44 @@ merge_pr (void *cls, | |||
511 | struct GSF_PendingRequestPlanBijection *bi; | 500 | struct GSF_PendingRequestPlanBijection *bi; |
512 | struct GSF_PendingRequest *latest; | 501 | struct GSF_PendingRequest *latest; |
513 | 502 | ||
514 | GNUNET_break (GNUNET_YES == | 503 | GNUNET_break(GNUNET_YES == |
515 | GSF_pending_request_test_active_ (mpr->pr)); | 504 | GSF_pending_request_test_active_(mpr->pr)); |
516 | if (GNUNET_OK != | 505 | if (GNUNET_OK != |
517 | GSF_pending_request_is_compatible_ (mpr->pr, | 506 | GSF_pending_request_is_compatible_(mpr->pr, |
518 | rp->pe_head->pr)) | 507 | rp->pe_head->pr)) |
519 | return GNUNET_YES; | 508 | return GNUNET_YES; |
520 | /* merge new request with existing request plan */ | 509 | /* merge new request with existing request plan */ |
521 | bi = GNUNET_new (struct GSF_PendingRequestPlanBijection); | 510 | bi = GNUNET_new(struct GSF_PendingRequestPlanBijection); |
522 | bi->rp = rp; | 511 | bi->rp = rp; |
523 | bi->pr = mpr->pr; | 512 | bi->pr = mpr->pr; |
524 | prd = GSF_pending_request_get_data_ (mpr->pr); | 513 | prd = GSF_pending_request_get_data_(mpr->pr); |
525 | GNUNET_CONTAINER_MDLL_insert (PR, | 514 | GNUNET_CONTAINER_MDLL_insert(PR, |
526 | prd->pr_head, | 515 | prd->pr_head, |
527 | prd->pr_tail, | 516 | prd->pr_tail, |
528 | bi); | 517 | bi); |
529 | GNUNET_CONTAINER_MDLL_insert (PE, | 518 | GNUNET_CONTAINER_MDLL_insert(PE, |
530 | rp->pe_head, | 519 | rp->pe_head, |
531 | rp->pe_tail, | 520 | rp->pe_tail, |
532 | bi); | 521 | bi); |
533 | mpr->merged = GNUNET_YES; | 522 | mpr->merged = GNUNET_YES; |
534 | #if INSANE_STATISTICS | 523 | #if INSANE_STATISTICS |
535 | GNUNET_STATISTICS_update (GSF_stats, | 524 | GNUNET_STATISTICS_update(GSF_stats, |
536 | gettext_noop ("# requests merged"), | 525 | gettext_noop("# requests merged"), |
537 | 1, | 526 | 1, |
538 | GNUNET_NO); | 527 | GNUNET_NO); |
539 | #endif | 528 | #endif |
540 | latest = get_latest (rp); | 529 | latest = get_latest(rp); |
541 | if (GSF_pending_request_get_data_ (latest)->ttl.abs_value_us < | 530 | if (GSF_pending_request_get_data_(latest)->ttl.abs_value_us < |
542 | prd->ttl.abs_value_us) | 531 | prd->ttl.abs_value_us) |
543 | { | 532 | { |
544 | #if INSANE_STATISTICS | 533 | #if INSANE_STATISTICS |
545 | GNUNET_STATISTICS_update (GSF_stats, | 534 | GNUNET_STATISTICS_update(GSF_stats, |
546 | gettext_noop ("# requests refreshed"), | 535 | gettext_noop("# requests refreshed"), |
547 | 1, | 536 | 1, |
548 | GNUNET_NO); | 537 | GNUNET_NO); |
549 | #endif | 538 | #endif |
550 | rp->transmission_counter = 0; /* reset */ | 539 | rp->transmission_counter = 0; /* reset */ |
551 | } | 540 | } |
552 | return GNUNET_NO; | 541 | return GNUNET_NO; |
553 | } | 542 | } |
554 | 543 | ||
@@ -560,8 +549,8 @@ merge_pr (void *cls, | |||
560 | * @param pr request with the entry | 549 | * @param pr request with the entry |
561 | */ | 550 | */ |
562 | void | 551 | void |
563 | GSF_plan_add_ (struct GSF_ConnectedPeer *cp, | 552 | GSF_plan_add_(struct GSF_ConnectedPeer *cp, |
564 | struct GSF_PendingRequest *pr) | 553 | struct GSF_PendingRequest *pr) |
565 | { | 554 | { |
566 | const struct GNUNET_PeerIdentity *id; | 555 | const struct GNUNET_PeerIdentity *id; |
567 | struct PeerPlan *pp; | 556 | struct PeerPlan *pp; |
@@ -570,66 +559,66 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, | |||
570 | struct GSF_PendingRequestPlanBijection *bi; | 559 | struct GSF_PendingRequestPlanBijection *bi; |
571 | struct MergeContext mpc; | 560 | struct MergeContext mpc; |
572 | 561 | ||
573 | GNUNET_assert (GNUNET_YES == | 562 | GNUNET_assert(GNUNET_YES == |
574 | GSF_pending_request_test_active_ (pr)); | 563 | GSF_pending_request_test_active_(pr)); |
575 | GNUNET_assert (NULL != cp); | 564 | GNUNET_assert(NULL != cp); |
576 | id = GSF_connected_peer_get_identity2_ (cp); | 565 | id = GSF_connected_peer_get_identity2_(cp); |
577 | pp = GNUNET_CONTAINER_multipeermap_get (plans, id); | 566 | pp = GNUNET_CONTAINER_multipeermap_get(plans, id); |
578 | if (NULL == pp) | 567 | if (NULL == pp) |
579 | { | 568 | { |
580 | pp = GNUNET_new (struct PeerPlan); | 569 | pp = GNUNET_new(struct PeerPlan); |
581 | pp->plan_map = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); | 570 | pp->plan_map = GNUNET_CONTAINER_multihashmap_create(128, GNUNET_NO); |
582 | pp->priority_heap = | 571 | pp->priority_heap = |
583 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); | 572 | GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MAX); |
584 | pp->delay_heap = | 573 | pp->delay_heap = |
585 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 574 | GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); |
586 | pp->cp = cp; | 575 | pp->cp = cp; |
587 | GNUNET_assert (GNUNET_OK == | 576 | GNUNET_assert(GNUNET_OK == |
588 | GNUNET_CONTAINER_multipeermap_put (plans, | 577 | GNUNET_CONTAINER_multipeermap_put(plans, |
589 | id, | 578 | id, |
590 | pp, | 579 | pp, |
591 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 580 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
592 | pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, | 581 | pp->task = GNUNET_SCHEDULER_add_now(&schedule_peer_transmission, |
593 | pp); | 582 | pp); |
594 | } | 583 | } |
595 | mpc.merged = GNUNET_NO; | 584 | mpc.merged = GNUNET_NO; |
596 | mpc.pr = pr; | 585 | mpc.pr = pr; |
597 | prd = GSF_pending_request_get_data_ (pr); | 586 | prd = GSF_pending_request_get_data_(pr); |
598 | GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map, | 587 | GNUNET_CONTAINER_multihashmap_get_multiple(pp->plan_map, |
599 | &prd->query, | 588 | &prd->query, |
600 | &merge_pr, | 589 | &merge_pr, |
601 | &mpc); | 590 | &mpc); |
602 | if (GNUNET_NO != mpc.merged) | 591 | if (GNUNET_NO != mpc.merged) |
603 | return; | 592 | return; |
604 | plan_count++; | 593 | plan_count++; |
605 | GNUNET_STATISTICS_update (GSF_stats, | 594 | GNUNET_STATISTICS_update(GSF_stats, |
606 | gettext_noop ("# query plan entries"), | 595 | gettext_noop("# query plan entries"), |
607 | 1, | 596 | 1, |
608 | GNUNET_NO); | 597 | GNUNET_NO); |
609 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 598 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
610 | "Planning transmission of query `%s' to peer `%s'\n", | 599 | "Planning transmission of query `%s' to peer `%s'\n", |
611 | GNUNET_h2s (&prd->query), | 600 | GNUNET_h2s(&prd->query), |
612 | GNUNET_i2s (id)); | 601 | GNUNET_i2s(id)); |
613 | rp = GNUNET_new (struct GSF_RequestPlan); | 602 | rp = GNUNET_new(struct GSF_RequestPlan); |
614 | bi = GNUNET_new (struct GSF_PendingRequestPlanBijection); | 603 | bi = GNUNET_new(struct GSF_PendingRequestPlanBijection); |
615 | bi->rp = rp; | 604 | bi->rp = rp; |
616 | bi->pr = pr; | 605 | bi->pr = pr; |
617 | GNUNET_CONTAINER_MDLL_insert (PR, | 606 | GNUNET_CONTAINER_MDLL_insert(PR, |
618 | prd->pr_head, | 607 | prd->pr_head, |
619 | prd->pr_tail, | 608 | prd->pr_tail, |
620 | bi); | 609 | bi); |
621 | GNUNET_CONTAINER_MDLL_insert (PE, | 610 | GNUNET_CONTAINER_MDLL_insert(PE, |
622 | rp->pe_head, | 611 | rp->pe_head, |
623 | rp->pe_tail, | 612 | rp->pe_tail, |
624 | bi); | 613 | bi); |
625 | rp->pp = pp; | 614 | rp->pp = pp; |
626 | GNUNET_assert (GNUNET_YES == | 615 | GNUNET_assert(GNUNET_YES == |
627 | GNUNET_CONTAINER_multihashmap_put (pp->plan_map, | 616 | GNUNET_CONTAINER_multihashmap_put(pp->plan_map, |
628 | get_rp_key (rp), | 617 | get_rp_key(rp), |
629 | rp, | 618 | rp, |
630 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 619 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
631 | plan (pp, | 620 | plan(pp, |
632 | rp); | 621 | rp); |
633 | } | 622 | } |
634 | 623 | ||
635 | 624 | ||
@@ -640,7 +629,7 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, | |||
640 | * @param cp connected peer | 629 | * @param cp connected peer |
641 | */ | 630 | */ |
642 | void | 631 | void |
643 | GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp) | 632 | GSF_plan_notify_peer_disconnect_(const struct GSF_ConnectedPeer *cp) |
644 | { | 633 | { |
645 | const struct GNUNET_PeerIdentity *id; | 634 | const struct GNUNET_PeerIdentity *id; |
646 | struct PeerPlan *pp; | 635 | struct PeerPlan *pp; |
@@ -648,70 +637,70 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp) | |||
648 | struct GSF_PendingRequestData *prd; | 637 | struct GSF_PendingRequestData *prd; |
649 | struct GSF_PendingRequestPlanBijection *bi; | 638 | struct GSF_PendingRequestPlanBijection *bi; |
650 | 639 | ||
651 | id = GSF_connected_peer_get_identity2_ (cp); | 640 | id = GSF_connected_peer_get_identity2_(cp); |
652 | pp = GNUNET_CONTAINER_multipeermap_get (plans, id); | 641 | pp = GNUNET_CONTAINER_multipeermap_get(plans, id); |
653 | if (NULL == pp) | 642 | if (NULL == pp) |
654 | return; /* nothing was ever planned for this peer */ | 643 | return; /* nothing was ever planned for this peer */ |
655 | GNUNET_assert (GNUNET_YES == | 644 | GNUNET_assert(GNUNET_YES == |
656 | GNUNET_CONTAINER_multipeermap_remove (plans, id, | 645 | GNUNET_CONTAINER_multipeermap_remove(plans, id, |
657 | pp)); | 646 | pp)); |
658 | if (NULL != pp->task) | 647 | if (NULL != pp->task) |
659 | { | ||
660 | GNUNET_SCHEDULER_cancel (pp->task); | ||
661 | pp->task = NULL; | ||
662 | } | ||
663 | while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap))) | ||
664 | { | ||
665 | GNUNET_break (GNUNET_YES == | ||
666 | GNUNET_CONTAINER_multihashmap_remove (pp->plan_map, | ||
667 | get_rp_key (rp), | ||
668 | rp)); | ||
669 | while (NULL != (bi = rp->pe_head)) | ||
670 | { | 648 | { |
671 | GNUNET_CONTAINER_MDLL_remove (PE, | 649 | GNUNET_SCHEDULER_cancel(pp->task); |
672 | rp->pe_head, | 650 | pp->task = NULL; |
673 | rp->pe_tail, | ||
674 | bi); | ||
675 | prd = GSF_pending_request_get_data_ (bi->pr); | ||
676 | GNUNET_CONTAINER_MDLL_remove (PR, | ||
677 | prd->pr_head, | ||
678 | prd->pr_tail, | ||
679 | bi); | ||
680 | GNUNET_free (bi); | ||
681 | } | 651 | } |
682 | plan_count--; | 652 | while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root(pp->priority_heap))) |
683 | GNUNET_free (rp); | 653 | { |
684 | } | 654 | GNUNET_break(GNUNET_YES == |
685 | GNUNET_CONTAINER_heap_destroy (pp->priority_heap); | 655 | GNUNET_CONTAINER_multihashmap_remove(pp->plan_map, |
686 | while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->delay_heap))) | 656 | get_rp_key(rp), |
687 | { | ||
688 | GNUNET_break (GNUNET_YES == | ||
689 | GNUNET_CONTAINER_multihashmap_remove (pp->plan_map, | ||
690 | get_rp_key (rp), | ||
691 | rp)); | 657 | rp)); |
692 | while (NULL != (bi = rp->pe_head)) | 658 | 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))) | ||
693 | { | 676 | { |
694 | prd = GSF_pending_request_get_data_ (bi->pr); | 677 | GNUNET_break(GNUNET_YES == |
695 | GNUNET_CONTAINER_MDLL_remove (PE, | 678 | GNUNET_CONTAINER_multihashmap_remove(pp->plan_map, |
696 | rp->pe_head, | 679 | get_rp_key(rp), |
697 | rp->pe_tail, | 680 | rp)); |
698 | bi); | 681 | while (NULL != (bi = rp->pe_head)) |
699 | GNUNET_CONTAINER_MDLL_remove (PR, | 682 | { |
700 | prd->pr_head, | 683 | prd = GSF_pending_request_get_data_(bi->pr); |
701 | prd->pr_tail, | 684 | GNUNET_CONTAINER_MDLL_remove(PE, |
702 | bi); | 685 | rp->pe_head, |
703 | GNUNET_free (bi); | 686 | rp->pe_tail, |
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); | ||
704 | } | 696 | } |
705 | plan_count--; | 697 | GNUNET_STATISTICS_set(GSF_stats, |
706 | GNUNET_free (rp); | 698 | gettext_noop("# query plan entries"), |
707 | } | 699 | plan_count, |
708 | GNUNET_STATISTICS_set (GSF_stats, | 700 | GNUNET_NO); |
709 | gettext_noop ("# query plan entries"), | 701 | GNUNET_CONTAINER_heap_destroy(pp->delay_heap); |
710 | plan_count, | 702 | GNUNET_CONTAINER_multihashmap_destroy(pp->plan_map); |
711 | GNUNET_NO); | 703 | GNUNET_free(pp); |
712 | GNUNET_CONTAINER_heap_destroy (pp->delay_heap); | ||
713 | GNUNET_CONTAINER_multihashmap_destroy (pp->plan_map); | ||
714 | GNUNET_free (pp); | ||
715 | } | 704 | } |
716 | 705 | ||
717 | 706 | ||
@@ -725,23 +714,23 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp) | |||
725 | * @return #GNUNET_YES if @a result was changed, #GNUNET_NO otherwise. | 714 | * @return #GNUNET_YES if @a result was changed, #GNUNET_NO otherwise. |
726 | */ | 715 | */ |
727 | int | 716 | int |
728 | GSF_request_plan_reference_get_last_transmission_ (struct GSF_PendingRequestPlanBijection *pr_head, | 717 | GSF_request_plan_reference_get_last_transmission_(struct GSF_PendingRequestPlanBijection *pr_head, |
729 | struct GSF_ConnectedPeer *sender, | 718 | struct GSF_ConnectedPeer *sender, |
730 | struct GNUNET_TIME_Absolute *result) | 719 | struct GNUNET_TIME_Absolute *result) |
731 | { | 720 | { |
732 | struct GSF_PendingRequestPlanBijection *bi; | 721 | struct GSF_PendingRequestPlanBijection *bi; |
733 | 722 | ||
734 | for (bi = pr_head; NULL != bi; bi = bi->next_PR) | 723 | for (bi = pr_head; NULL != bi; bi = bi->next_PR) |
735 | { | ||
736 | if (bi->rp->pp->cp == sender) | ||
737 | { | 724 | { |
738 | if (0 == bi->rp->last_transmission.abs_value_us) | 725 | if (bi->rp->pp->cp == sender) |
739 | *result = GNUNET_TIME_UNIT_FOREVER_ABS; | 726 | { |
740 | else | 727 | if (0 == bi->rp->last_transmission.abs_value_us) |
741 | *result = bi->rp->last_transmission; | 728 | *result = GNUNET_TIME_UNIT_FOREVER_ABS; |
742 | return GNUNET_YES; | 729 | else |
730 | *result = bi->rp->last_transmission; | ||
731 | return GNUNET_YES; | ||
732 | } | ||
743 | } | 733 | } |
744 | } | ||
745 | return GNUNET_NO; | 734 | return GNUNET_NO; |
746 | } | 735 | } |
747 | 736 | ||
@@ -753,41 +742,41 @@ GSF_request_plan_reference_get_last_transmission_ (struct GSF_PendingRequestPlan | |||
753 | * @param pr request that is done | 742 | * @param pr request that is done |
754 | */ | 743 | */ |
755 | void | 744 | void |
756 | GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr) | 745 | GSF_plan_notify_request_done_(struct GSF_PendingRequest *pr) |
757 | { | 746 | { |
758 | struct GSF_RequestPlan *rp; | 747 | struct GSF_RequestPlan *rp; |
759 | struct GSF_PendingRequestData *prd; | 748 | struct GSF_PendingRequestData *prd; |
760 | struct GSF_PendingRequestPlanBijection *bi; | 749 | struct GSF_PendingRequestPlanBijection *bi; |
761 | 750 | ||
762 | prd = GSF_pending_request_get_data_ (pr); | 751 | prd = GSF_pending_request_get_data_(pr); |
763 | while (NULL != (bi = prd->pr_head)) | 752 | while (NULL != (bi = prd->pr_head)) |
764 | { | ||
765 | rp = bi->rp; | ||
766 | GNUNET_CONTAINER_MDLL_remove (PR, | ||
767 | prd->pr_head, | ||
768 | prd->pr_tail, | ||
769 | bi); | ||
770 | GNUNET_CONTAINER_MDLL_remove (PE, | ||
771 | rp->pe_head, | ||
772 | rp->pe_tail, | ||
773 | bi); | ||
774 | GNUNET_assert (bi->pr == pr); | ||
775 | if (NULL == rp->pe_head) | ||
776 | { | 753 | { |
777 | GNUNET_CONTAINER_heap_remove_node (rp->hn); | 754 | rp = bi->rp; |
778 | plan_count--; | 755 | GNUNET_CONTAINER_MDLL_remove(PR, |
779 | GNUNET_break (GNUNET_YES == | 756 | prd->pr_head, |
780 | GNUNET_CONTAINER_multihashmap_remove (rp->pp->plan_map, | 757 | prd->pr_tail, |
781 | &prd->query, | 758 | bi); |
782 | rp)); | 759 | GNUNET_CONTAINER_MDLL_remove(PE, |
783 | GNUNET_free (rp); | 760 | rp->pe_head, |
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); | ||
784 | } | 775 | } |
785 | GNUNET_free (bi); | 776 | GNUNET_STATISTICS_set(GSF_stats, |
786 | } | 777 | gettext_noop("# query plan entries"), |
787 | GNUNET_STATISTICS_set (GSF_stats, | 778 | plan_count, |
788 | gettext_noop ("# query plan entries"), | 779 | GNUNET_NO); |
789 | plan_count, | ||
790 | GNUNET_NO); | ||
791 | } | 780 | } |
792 | 781 | ||
793 | 782 | ||
@@ -795,10 +784,10 @@ GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr) | |||
795 | * Initialize plan subsystem. | 784 | * Initialize plan subsystem. |
796 | */ | 785 | */ |
797 | void | 786 | void |
798 | GSF_plan_init () | 787 | GSF_plan_init() |
799 | { | 788 | { |
800 | plans = GNUNET_CONTAINER_multipeermap_create (256, | 789 | plans = GNUNET_CONTAINER_multipeermap_create(256, |
801 | GNUNET_YES); | 790 | GNUNET_YES); |
802 | } | 791 | } |
803 | 792 | ||
804 | 793 | ||
@@ -806,10 +795,10 @@ GSF_plan_init () | |||
806 | * Shutdown plan subsystem. | 795 | * Shutdown plan subsystem. |
807 | */ | 796 | */ |
808 | void | 797 | void |
809 | GSF_plan_done () | 798 | GSF_plan_done() |
810 | { | 799 | { |
811 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (plans)); | 800 | GNUNET_assert(0 == GNUNET_CONTAINER_multipeermap_size(plans)); |
812 | GNUNET_CONTAINER_multipeermap_destroy (plans); | 801 | GNUNET_CONTAINER_multipeermap_destroy(plans); |
813 | } | 802 | } |
814 | 803 | ||
815 | 804 | ||
diff --git a/src/fs/gnunet-service-fs_pe.h b/src/fs/gnunet-service-fs_pe.h index 10f7daea5..dfad71be9 100644 --- a/src/fs/gnunet-service-fs_pe.h +++ b/src/fs/gnunet-service-fs_pe.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_pe.h | 22 | * @file 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,22 @@ 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 GSF_PendingRequestPlanBijection *pr_head, |
73 | struct GSF_ConnectedPeer *sender, | 73 | struct GSF_ConnectedPeer *sender, |
74 | struct GNUNET_TIME_Absolute *result); | 74 | struct GNUNET_TIME_Absolute *result); |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * Initialize plan subsystem. | 77 | * Initialize plan subsystem. |
78 | */ | 78 | */ |
79 | void | 79 | void |
80 | GSF_plan_init (void); | 80 | GSF_plan_init(void); |
81 | 81 | ||
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Shutdown plan subsystem. | 84 | * Shutdown plan subsystem. |
85 | */ | 85 | */ |
86 | void | 86 | void |
87 | GSF_plan_done (void); | 87 | GSF_plan_done(void); |
88 | 88 | ||
89 | 89 | ||
90 | #endif | 90 | #endif |
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index f9702486a..90587cfa0 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_pr.c | 22 | * @file fs/gnunet-service-fs_pr.c |
@@ -74,8 +74,7 @@ | |||
74 | /** | 74 | /** |
75 | * An active request. | 75 | * An active request. |
76 | */ | 76 | */ |
77 | struct GSF_PendingRequest | 77 | struct GSF_PendingRequest { |
78 | { | ||
79 | /** | 78 | /** |
80 | * Public data for the request. | 79 | * Public data for the request. |
81 | */ | 80 | */ |
@@ -247,31 +246,31 @@ static unsigned long long max_pending_requests = (32 * 1024); | |||
247 | * @param pr request for which the BF is to be recomputed | 246 | * @param pr request for which the BF is to be recomputed |
248 | */ | 247 | */ |
249 | static void | 248 | static void |
250 | refresh_bloomfilter (enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr) | 249 | refresh_bloomfilter(enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr) |
251 | { | 250 | { |
252 | if (NULL != pr->bg) | 251 | if (NULL != pr->bg) |
253 | { | 252 | { |
254 | GNUNET_BLOCK_group_destroy (pr->bg); | 253 | GNUNET_BLOCK_group_destroy(pr->bg); |
255 | pr->bg = NULL; | 254 | pr->bg = NULL; |
256 | } | 255 | } |
257 | if (GNUNET_BLOCK_TYPE_FS_UBLOCK != type) | 256 | if (GNUNET_BLOCK_TYPE_FS_UBLOCK != type) |
258 | return; /* no need */ | 257 | return; /* no need */ |
259 | pr->bg = | 258 | pr->bg = |
260 | GNUNET_BLOCK_group_create (GSF_block_ctx, | 259 | GNUNET_BLOCK_group_create(GSF_block_ctx, |
261 | type, | 260 | type, |
262 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 261 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
263 | UINT32_MAX), | 262 | UINT32_MAX), |
264 | NULL, | 263 | NULL, |
265 | 0, | 264 | 0, |
266 | "seen-set-size", | 265 | "seen-set-size", |
267 | pr->replies_seen_count, | 266 | pr->replies_seen_count, |
268 | NULL); | 267 | NULL); |
269 | if (NULL == pr->bg) | 268 | if (NULL == pr->bg) |
270 | return; | 269 | return; |
271 | GNUNET_break (GNUNET_OK == | 270 | GNUNET_break(GNUNET_OK == |
272 | GNUNET_BLOCK_group_set_seen (pr->bg, | 271 | GNUNET_BLOCK_group_set_seen(pr->bg, |
273 | pr->replies_seen, | 272 | pr->replies_seen, |
274 | pr->replies_seen_count)); | 273 | pr->replies_seen_count)); |
275 | } | 274 | } |
276 | 275 | ||
277 | 276 | ||
@@ -297,129 +296,129 @@ refresh_bloomfilter (enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr) | |||
297 | * @return handle for the new pending request | 296 | * @return handle for the new pending request |
298 | */ | 297 | */ |
299 | struct GSF_PendingRequest * | 298 | struct GSF_PendingRequest * |
300 | GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, | 299 | GSF_pending_request_create_(enum GSF_PendingRequestOptions options, |
301 | enum GNUNET_BLOCK_Type type, | 300 | enum GNUNET_BLOCK_Type type, |
302 | const struct GNUNET_HashCode *query, | 301 | const struct GNUNET_HashCode *query, |
303 | const struct GNUNET_PeerIdentity *target, | 302 | const struct GNUNET_PeerIdentity *target, |
304 | const char *bf_data, | 303 | const char *bf_data, |
305 | size_t bf_size, | 304 | size_t bf_size, |
306 | uint32_t mingle, | 305 | uint32_t mingle, |
307 | uint32_t anonymity_level, | 306 | uint32_t anonymity_level, |
308 | uint32_t priority, | 307 | uint32_t priority, |
309 | int32_t ttl, | 308 | int32_t ttl, |
310 | GNUNET_PEER_Id sender_pid, | 309 | GNUNET_PEER_Id sender_pid, |
311 | GNUNET_PEER_Id origin_pid, | 310 | GNUNET_PEER_Id origin_pid, |
312 | const struct GNUNET_HashCode *replies_seen, | 311 | const struct GNUNET_HashCode *replies_seen, |
313 | unsigned int replies_seen_count, | 312 | unsigned int replies_seen_count, |
314 | GSF_PendingRequestReplyHandler rh, | 313 | GSF_PendingRequestReplyHandler rh, |
315 | void *rh_cls) | 314 | void *rh_cls) |
316 | { | 315 | { |
317 | struct GSF_PendingRequest *pr; | 316 | struct GSF_PendingRequest *pr; |
318 | struct GSF_PendingRequest *dpr; | 317 | struct GSF_PendingRequest *dpr; |
319 | size_t extra; | 318 | size_t extra; |
320 | struct GNUNET_HashCode *eptr; | 319 | struct GNUNET_HashCode *eptr; |
321 | 320 | ||
322 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 321 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
323 | "Creating request handle for `%s' of type %d\n", | 322 | "Creating request handle for `%s' of type %d\n", |
324 | GNUNET_h2s (query), | 323 | GNUNET_h2s(query), |
325 | type); | 324 | type); |
326 | #if INSANE_STATISTICS | 325 | #if INSANE_STATISTICS |
327 | GNUNET_STATISTICS_update (GSF_stats, | 326 | GNUNET_STATISTICS_update(GSF_stats, |
328 | gettext_noop ("# Pending requests created"), | 327 | gettext_noop("# Pending requests created"), |
329 | 1, | 328 | 1, |
330 | GNUNET_NO); | 329 | GNUNET_NO); |
331 | #endif | 330 | #endif |
332 | extra = 0; | 331 | extra = 0; |
333 | if (NULL != target) | 332 | if (NULL != target) |
334 | extra += sizeof (struct GNUNET_PeerIdentity); | 333 | extra += sizeof(struct GNUNET_PeerIdentity); |
335 | pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest) + extra); | 334 | pr = GNUNET_malloc(sizeof(struct GSF_PendingRequest) + extra); |
336 | pr->public_data.query = *query; | 335 | pr->public_data.query = *query; |
337 | eptr = (struct GNUNET_HashCode *) &pr[1]; | 336 | eptr = (struct GNUNET_HashCode *)&pr[1]; |
338 | if (NULL != target) | 337 | if (NULL != target) |
339 | { | 338 | { |
340 | pr->public_data.target = (struct GNUNET_PeerIdentity *) eptr; | 339 | pr->public_data.target = (struct GNUNET_PeerIdentity *)eptr; |
341 | GNUNET_memcpy (eptr, target, sizeof (struct GNUNET_PeerIdentity)); | 340 | GNUNET_memcpy(eptr, target, sizeof(struct GNUNET_PeerIdentity)); |
342 | } | 341 | } |
343 | pr->public_data.anonymity_level = anonymity_level; | 342 | pr->public_data.anonymity_level = anonymity_level; |
344 | pr->public_data.priority = priority; | 343 | pr->public_data.priority = priority; |
345 | pr->public_data.original_priority = priority; | 344 | pr->public_data.original_priority = priority; |
346 | pr->public_data.options = options; | 345 | pr->public_data.options = options; |
347 | pr->public_data.type = type; | 346 | pr->public_data.type = type; |
348 | pr->public_data.start_time = GNUNET_TIME_absolute_get (); | 347 | pr->public_data.start_time = GNUNET_TIME_absolute_get(); |
349 | pr->sender_pid = sender_pid; | 348 | pr->sender_pid = sender_pid; |
350 | pr->origin_pid = origin_pid; | 349 | pr->origin_pid = origin_pid; |
351 | pr->rh = rh; | 350 | pr->rh = rh; |
352 | pr->rh_cls = rh_cls; | 351 | pr->rh_cls = rh_cls; |
353 | GNUNET_assert ((sender_pid != 0) || (0 == (options & GSF_PRO_FORWARD_ONLY))); | 352 | GNUNET_assert((sender_pid != 0) || (0 == (options & GSF_PRO_FORWARD_ONLY))); |
354 | if (ttl >= 0) | 353 | if (ttl >= 0) |
355 | pr->public_data.ttl = GNUNET_TIME_relative_to_absolute ( | 354 | pr->public_data.ttl = GNUNET_TIME_relative_to_absolute( |
356 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, (uint32_t) ttl)); | 355 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, (uint32_t)ttl)); |
357 | else | 356 | else |
358 | pr->public_data.ttl = GNUNET_TIME_absolute_subtract ( | 357 | pr->public_data.ttl = GNUNET_TIME_absolute_subtract( |
359 | pr->public_data.start_time, | 358 | pr->public_data.start_time, |
360 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 359 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
361 | (uint32_t) (-ttl))); | 360 | (uint32_t)(-ttl))); |
362 | if (replies_seen_count > 0) | 361 | if (replies_seen_count > 0) |
363 | { | 362 | { |
364 | pr->replies_seen_size = replies_seen_count; | 363 | pr->replies_seen_size = replies_seen_count; |
365 | pr->replies_seen = | 364 | pr->replies_seen = |
366 | GNUNET_new_array (pr->replies_seen_size, struct GNUNET_HashCode); | 365 | GNUNET_new_array(pr->replies_seen_size, struct GNUNET_HashCode); |
367 | GNUNET_memcpy (pr->replies_seen, | 366 | GNUNET_memcpy(pr->replies_seen, |
368 | replies_seen, | 367 | replies_seen, |
369 | replies_seen_count * sizeof (struct GNUNET_HashCode)); | 368 | replies_seen_count * sizeof(struct GNUNET_HashCode)); |
370 | pr->replies_seen_count = replies_seen_count; | 369 | pr->replies_seen_count = replies_seen_count; |
371 | } | 370 | } |
372 | if ((NULL != bf_data) && | 371 | if ((NULL != bf_data) && |
373 | (GNUNET_BLOCK_TYPE_FS_UBLOCK == pr->public_data.type)) | 372 | (GNUNET_BLOCK_TYPE_FS_UBLOCK == pr->public_data.type)) |
374 | { | 373 | { |
375 | pr->bg = GNUNET_BLOCK_group_create (GSF_block_ctx, | 374 | pr->bg = GNUNET_BLOCK_group_create(GSF_block_ctx, |
376 | pr->public_data.type, | 375 | pr->public_data.type, |
377 | mingle, | 376 | mingle, |
378 | bf_data, | 377 | bf_data, |
379 | bf_size, | 378 | bf_size, |
380 | "seen-set-size", | 379 | "seen-set-size", |
381 | 0, | 380 | 0, |
382 | NULL); | 381 | NULL); |
383 | } | 382 | } |
384 | else if ((replies_seen_count > 0) && | 383 | else if ((replies_seen_count > 0) && |
385 | (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))) | 384 | (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))) |
386 | { | 385 | { |
387 | refresh_bloomfilter (pr->public_data.type, pr); | 386 | refresh_bloomfilter(pr->public_data.type, pr); |
388 | } | 387 | } |
389 | GNUNET_CONTAINER_multihashmap_put (pr_map, | 388 | GNUNET_CONTAINER_multihashmap_put(pr_map, |
390 | &pr->public_data.query, | 389 | &pr->public_data.query, |
391 | pr, | 390 | pr, |
392 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 391 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
393 | if (0 == (options & GSF_PRO_REQUEST_NEVER_EXPIRES)) | 392 | if (0 == (options & GSF_PRO_REQUEST_NEVER_EXPIRES)) |
394 | { | ||
395 | pr->hnode = GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap, | ||
396 | pr, | ||
397 | pr->public_data.ttl.abs_value_us); | ||
398 | /* make sure we don't track too many requests */ | ||
399 | while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) > | ||
400 | max_pending_requests) | ||
401 | { | 393 | { |
402 | dpr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap); | 394 | pr->hnode = GNUNET_CONTAINER_heap_insert(requests_by_expiration_heap, |
403 | GNUNET_assert (NULL != dpr); | 395 | pr, |
404 | if (pr == dpr) | 396 | pr->public_data.ttl.abs_value_us); |
405 | break; /* let the request live briefly... */ | 397 | /* make sure we don't track too many requests */ |
406 | if (NULL != dpr->rh) | 398 | while (GNUNET_CONTAINER_heap_get_size(requests_by_expiration_heap) > |
407 | dpr->rh (dpr->rh_cls, | 399 | max_pending_requests) |
408 | GNUNET_BLOCK_EVALUATION_REQUEST_VALID, | 400 | { |
409 | dpr, | 401 | dpr = GNUNET_CONTAINER_heap_peek(requests_by_expiration_heap); |
410 | UINT32_MAX, | 402 | GNUNET_assert(NULL != dpr); |
411 | GNUNET_TIME_UNIT_FOREVER_ABS, | 403 | if (pr == dpr) |
412 | GNUNET_TIME_UNIT_FOREVER_ABS, | 404 | break; /* let the request live briefly... */ |
413 | GNUNET_BLOCK_TYPE_ANY, | 405 | if (NULL != dpr->rh) |
414 | NULL, | 406 | dpr->rh(dpr->rh_cls, |
415 | 0); | 407 | GNUNET_BLOCK_EVALUATION_REQUEST_VALID, |
416 | GSF_pending_request_cancel_ (dpr, GNUNET_YES); | 408 | dpr, |
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 | } | 417 | } |
418 | } | 418 | GNUNET_STATISTICS_update(GSF_stats, |
419 | GNUNET_STATISTICS_update (GSF_stats, | 419 | gettext_noop("# Pending requests active"), |
420 | gettext_noop ("# Pending requests active"), | 420 | 1, |
421 | 1, | 421 | GNUNET_NO); |
422 | GNUNET_NO); | ||
423 | return pr; | 422 | return pr; |
424 | } | 423 | } |
425 | 424 | ||
@@ -430,7 +429,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, | |||
430 | * @return associated public data | 429 | * @return associated public data |
431 | */ | 430 | */ |
432 | struct GSF_PendingRequestData * | 431 | struct GSF_PendingRequestData * |
433 | GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr) | 432 | GSF_pending_request_get_data_(struct GSF_PendingRequest *pr) |
434 | { | 433 | { |
435 | return &pr->public_data; | 434 | return &pr->public_data; |
436 | } | 435 | } |
@@ -446,13 +445,13 @@ GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr) | |||
446 | * @return #GNUNET_OK if the requests are compatible | 445 | * @return #GNUNET_OK if the requests are compatible |
447 | */ | 446 | */ |
448 | int | 447 | int |
449 | GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, | 448 | GSF_pending_request_is_compatible_(struct GSF_PendingRequest *pra, |
450 | struct GSF_PendingRequest *prb) | 449 | struct GSF_PendingRequest *prb) |
451 | { | 450 | { |
452 | if ((pra->public_data.type != prb->public_data.type) || | 451 | if ((pra->public_data.type != prb->public_data.type) || |
453 | (0 != memcmp (&pra->public_data.query, | 452 | (0 != memcmp(&pra->public_data.query, |
454 | &prb->public_data.query, | 453 | &prb->public_data.query, |
455 | sizeof (struct GNUNET_HashCode)))) | 454 | sizeof(struct GNUNET_HashCode)))) |
456 | return GNUNET_NO; | 455 | return GNUNET_NO; |
457 | return GNUNET_OK; | 456 | return GNUNET_OK; |
458 | } | 457 | } |
@@ -467,45 +466,45 @@ GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, | |||
467 | * @param replies_seen_count size of the replies_seen array | 466 | * @param replies_seen_count size of the replies_seen array |
468 | */ | 467 | */ |
469 | void | 468 | void |
470 | GSF_pending_request_update_ (struct GSF_PendingRequest *pr, | 469 | GSF_pending_request_update_(struct GSF_PendingRequest *pr, |
471 | const struct GNUNET_HashCode *replies_seen, | 470 | const struct GNUNET_HashCode *replies_seen, |
472 | unsigned int replies_seen_count) | 471 | unsigned int replies_seen_count) |
473 | { | 472 | { |
474 | if (replies_seen_count + pr->replies_seen_count < pr->replies_seen_count) | 473 | if (replies_seen_count + pr->replies_seen_count < pr->replies_seen_count) |
475 | return; /* integer overflow */ | 474 | return; /* integer overflow */ |
476 | if (0 != (pr->public_data.options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)) | 475 | if (0 != (pr->public_data.options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)) |
477 | { | ||
478 | /* we're responsible for the BF, full refresh */ | ||
479 | if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size) | ||
480 | GNUNET_array_grow (pr->replies_seen, | ||
481 | pr->replies_seen_size, | ||
482 | replies_seen_count + pr->replies_seen_count); | ||
483 | GNUNET_memcpy (&pr->replies_seen[pr->replies_seen_count], | ||
484 | replies_seen, | ||
485 | sizeof (struct GNUNET_HashCode) * replies_seen_count); | ||
486 | pr->replies_seen_count += replies_seen_count; | ||
487 | refresh_bloomfilter (pr->public_data.type, pr); | ||
488 | } | ||
489 | else | ||
490 | { | ||
491 | if (NULL == pr->bg) | ||
492 | { | 476 | { |
493 | /* we're not the initiator, but the initiator did not give us | 477 | /* we're responsible for the BF, full refresh */ |
494 | * any bloom-filter, so we need to create one on-the-fly */ | 478 | if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size) |
495 | refresh_bloomfilter (pr->public_data.type, pr); | 479 | GNUNET_array_grow(pr->replies_seen, |
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); | ||
496 | } | 487 | } |
497 | else | 488 | else |
498 | { | 489 | { |
499 | GNUNET_break (GNUNET_OK == | 490 | if (NULL == pr->bg) |
500 | GNUNET_BLOCK_group_set_seen (pr->bg, | 491 | { |
501 | replies_seen, | 492 | /* we're not the initiator, but the initiator did not give us |
502 | pr->replies_seen_count)); | 493 | * any bloom-filter, so we need to create one on-the-fly */ |
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 | } | 503 | } |
504 | } | ||
505 | if (NULL != pr->gh) | 504 | if (NULL != pr->gh) |
506 | GNUNET_DHT_get_filter_known_results (pr->gh, | 505 | GNUNET_DHT_get_filter_known_results(pr->gh, |
507 | replies_seen_count, | 506 | replies_seen_count, |
508 | replies_seen); | 507 | replies_seen); |
509 | } | 508 | } |
510 | 509 | ||
511 | 510 | ||
@@ -517,7 +516,7 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr, | |||
517 | * @return envelope with the request message | 516 | * @return envelope with the request message |
518 | */ | 517 | */ |
519 | struct GNUNET_MQ_Envelope * | 518 | struct GNUNET_MQ_Envelope * |
520 | GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) | 519 | GSF_pending_request_get_message_(struct GSF_PendingRequest *pr) |
521 | { | 520 | { |
522 | struct GNUNET_MQ_Envelope *env; | 521 | struct GNUNET_MQ_Envelope *env; |
523 | struct GetMessage *gm; | 522 | struct GetMessage *gm; |
@@ -532,61 +531,61 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) | |||
532 | void *bf_data; | 531 | void *bf_data; |
533 | uint32_t bf_nonce; | 532 | uint32_t bf_nonce; |
534 | 533 | ||
535 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 534 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
536 | "Building request message for `%s' of type %d\n", | 535 | "Building request message for `%s' of type %d\n", |
537 | GNUNET_h2s (&pr->public_data.query), | 536 | GNUNET_h2s(&pr->public_data.query), |
538 | pr->public_data.type); | 537 | pr->public_data.type); |
539 | k = 0; | 538 | k = 0; |
540 | bm = 0; | 539 | bm = 0; |
541 | do_route = (0 == (pr->public_data.options & GSF_PRO_FORWARD_ONLY)); | 540 | do_route = (0 == (pr->public_data.options & GSF_PRO_FORWARD_ONLY)); |
542 | if ((! do_route) && (pr->sender_pid == 0)) | 541 | if ((!do_route) && (pr->sender_pid == 0)) |
543 | { | 542 | { |
544 | GNUNET_break (0); | 543 | GNUNET_break(0); |
545 | do_route = GNUNET_YES; | 544 | do_route = GNUNET_YES; |
546 | } | 545 | } |
547 | if (! do_route) | 546 | if (!do_route) |
548 | { | 547 | { |
549 | bm |= GET_MESSAGE_BIT_RETURN_TO; | 548 | bm |= GET_MESSAGE_BIT_RETURN_TO; |
550 | k++; | 549 | k++; |
551 | } | 550 | } |
552 | if (NULL != pr->public_data.target) | 551 | if (NULL != pr->public_data.target) |
553 | { | 552 | { |
554 | bm |= GET_MESSAGE_BIT_TRANSMIT_TO; | 553 | bm |= GET_MESSAGE_BIT_TRANSMIT_TO; |
555 | k++; | 554 | k++; |
556 | } | 555 | } |
557 | if (GNUNET_OK != | 556 | if (GNUNET_OK != |
558 | GNUNET_BLOCK_group_serialize (pr->bg, &bf_nonce, &bf_data, &bf_size)) | 557 | GNUNET_BLOCK_group_serialize(pr->bg, &bf_nonce, &bf_data, &bf_size)) |
559 | { | 558 | { |
560 | bf_size = 0; | 559 | bf_size = 0; |
561 | bf_data = NULL; | 560 | bf_data = NULL; |
562 | } | 561 | } |
563 | env = GNUNET_MQ_msg_extra (gm, | 562 | env = GNUNET_MQ_msg_extra(gm, |
564 | bf_size + k * sizeof (struct GNUNET_PeerIdentity), | 563 | bf_size + k * sizeof(struct GNUNET_PeerIdentity), |
565 | GNUNET_MESSAGE_TYPE_FS_GET); | 564 | GNUNET_MESSAGE_TYPE_FS_GET); |
566 | gm->type = htonl (pr->public_data.type); | 565 | gm->type = htonl(pr->public_data.type); |
567 | if (do_route) | 566 | if (do_route) |
568 | prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 567 | prio = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
569 | pr->public_data.priority + 1); | 568 | pr->public_data.priority + 1); |
570 | else | 569 | else |
571 | prio = 0; | 570 | prio = 0; |
572 | pr->public_data.priority -= prio; | 571 | pr->public_data.priority -= prio; |
573 | pr->public_data.num_transmissions++; | 572 | pr->public_data.num_transmissions++; |
574 | pr->public_data.respect_offered += prio; | 573 | pr->public_data.respect_offered += prio; |
575 | gm->priority = htonl (prio); | 574 | gm->priority = htonl(prio); |
576 | now = GNUNET_TIME_absolute_get (); | 575 | now = GNUNET_TIME_absolute_get(); |
577 | ttl = (int64_t) (pr->public_data.ttl.abs_value_us - now.abs_value_us); | 576 | ttl = (int64_t)(pr->public_data.ttl.abs_value_us - now.abs_value_us); |
578 | gm->ttl = htonl (ttl / 1000LL / 1000LL); | 577 | gm->ttl = htonl(ttl / 1000LL / 1000LL); |
579 | gm->filter_mutator = htonl (bf_nonce); | 578 | gm->filter_mutator = htonl(bf_nonce); |
580 | gm->hash_bitmap = htonl (bm); | 579 | gm->hash_bitmap = htonl(bm); |
581 | gm->query = pr->public_data.query; | 580 | gm->query = pr->public_data.query; |
582 | ext = (struct GNUNET_PeerIdentity *) &gm[1]; | 581 | ext = (struct GNUNET_PeerIdentity *)&gm[1]; |
583 | k = 0; | 582 | k = 0; |
584 | if (! do_route) | 583 | if (!do_route) |
585 | GNUNET_PEER_resolve (pr->sender_pid, &ext[k++]); | 584 | GNUNET_PEER_resolve(pr->sender_pid, &ext[k++]); |
586 | if (NULL != pr->public_data.target) | 585 | if (NULL != pr->public_data.target) |
587 | ext[k++] = *pr->public_data.target; | 586 | ext[k++] = *pr->public_data.target; |
588 | GNUNET_memcpy (&ext[k], bf_data, bf_size); | 587 | GNUNET_memcpy(&ext[k], bf_data, bf_size); |
589 | GNUNET_free_non_null (bf_data); | 588 | GNUNET_free_non_null(bf_data); |
590 | return env; | 589 | return env; |
591 | } | 590 | } |
592 | 591 | ||
@@ -600,61 +599,61 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) | |||
600 | * @return #GNUNET_YES (we should continue to iterate) | 599 | * @return #GNUNET_YES (we should continue to iterate) |
601 | */ | 600 | */ |
602 | static int | 601 | static int |
603 | clean_request (void *cls, const struct GNUNET_HashCode *key, void *value) | 602 | clean_request(void *cls, const struct GNUNET_HashCode *key, void *value) |
604 | { | 603 | { |
605 | struct GSF_PendingRequest *pr = value; | 604 | struct GSF_PendingRequest *pr = value; |
606 | GSF_LocalLookupContinuation cont; | 605 | GSF_LocalLookupContinuation cont; |
607 | 606 | ||
608 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 607 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
609 | "Cleaning up pending request for `%s'.\n", | 608 | "Cleaning up pending request for `%s'.\n", |
610 | GNUNET_h2s (key)); | 609 | GNUNET_h2s(key)); |
611 | if (NULL != pr->cadet_request) | 610 | if (NULL != pr->cadet_request) |
612 | { | 611 | { |
613 | pr->cadet_retry_count = CADET_RETRY_MAX; | 612 | pr->cadet_retry_count = CADET_RETRY_MAX; |
614 | GSF_cadet_query_cancel (pr->cadet_request); | 613 | GSF_cadet_query_cancel(pr->cadet_request); |
615 | pr->cadet_request = NULL; | 614 | pr->cadet_request = NULL; |
616 | } | 615 | } |
617 | if (NULL != (cont = pr->llc_cont)) | 616 | if (NULL != (cont = pr->llc_cont)) |
618 | { | 617 | { |
619 | pr->llc_cont = NULL; | 618 | pr->llc_cont = NULL; |
620 | cont (pr->llc_cont_cls, pr, pr->local_result); | 619 | cont(pr->llc_cont_cls, pr, pr->local_result); |
621 | } | 620 | } |
622 | GSF_plan_notify_request_done_ (pr); | 621 | GSF_plan_notify_request_done_(pr); |
623 | GNUNET_free_non_null (pr->replies_seen); | 622 | GNUNET_free_non_null(pr->replies_seen); |
624 | GNUNET_BLOCK_group_destroy (pr->bg); | 623 | GNUNET_BLOCK_group_destroy(pr->bg); |
625 | pr->bg = NULL; | 624 | pr->bg = NULL; |
626 | GNUNET_PEER_change_rc (pr->sender_pid, -1); | 625 | GNUNET_PEER_change_rc(pr->sender_pid, -1); |
627 | pr->sender_pid = 0; | 626 | pr->sender_pid = 0; |
628 | GNUNET_PEER_change_rc (pr->origin_pid, -1); | 627 | GNUNET_PEER_change_rc(pr->origin_pid, -1); |
629 | pr->origin_pid = 0; | 628 | pr->origin_pid = 0; |
630 | if (NULL != pr->hnode) | 629 | if (NULL != pr->hnode) |
631 | { | 630 | { |
632 | GNUNET_CONTAINER_heap_remove_node (pr->hnode); | 631 | GNUNET_CONTAINER_heap_remove_node(pr->hnode); |
633 | pr->hnode = NULL; | 632 | pr->hnode = NULL; |
634 | } | 633 | } |
635 | if (NULL != pr->qe) | 634 | if (NULL != pr->qe) |
636 | { | 635 | { |
637 | GNUNET_DATASTORE_cancel (pr->qe); | 636 | GNUNET_DATASTORE_cancel(pr->qe); |
638 | pr->qe = NULL; | 637 | pr->qe = NULL; |
639 | } | 638 | } |
640 | if (NULL != pr->gh) | 639 | if (NULL != pr->gh) |
641 | { | 640 | { |
642 | GNUNET_DHT_get_stop (pr->gh); | 641 | GNUNET_DHT_get_stop(pr->gh); |
643 | pr->gh = NULL; | 642 | pr->gh = NULL; |
644 | } | 643 | } |
645 | if (NULL != pr->warn_task) | 644 | if (NULL != pr->warn_task) |
646 | { | 645 | { |
647 | GNUNET_SCHEDULER_cancel (pr->warn_task); | 646 | GNUNET_SCHEDULER_cancel(pr->warn_task); |
648 | pr->warn_task = NULL; | 647 | pr->warn_task = NULL; |
649 | } | 648 | } |
650 | GNUNET_assert ( | 649 | GNUNET_assert( |
651 | GNUNET_OK == | 650 | GNUNET_OK == |
652 | GNUNET_CONTAINER_multihashmap_remove (pr_map, &pr->public_data.query, pr)); | 651 | GNUNET_CONTAINER_multihashmap_remove(pr_map, &pr->public_data.query, pr)); |
653 | GNUNET_STATISTICS_update (GSF_stats, | 652 | GNUNET_STATISTICS_update(GSF_stats, |
654 | gettext_noop ("# Pending requests active"), | 653 | gettext_noop("# Pending requests active"), |
655 | -1, | 654 | -1, |
656 | GNUNET_NO); | 655 | GNUNET_NO); |
657 | GNUNET_free (pr); | 656 | GNUNET_free(pr); |
658 | return GNUNET_YES; | 657 | return GNUNET_YES; |
659 | } | 658 | } |
660 | 659 | ||
@@ -666,49 +665,49 @@ clean_request (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
666 | * @param full_cleanup fully purge the request | 665 | * @param full_cleanup fully purge the request |
667 | */ | 666 | */ |
668 | void | 667 | void |
669 | GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup) | 668 | GSF_pending_request_cancel_(struct GSF_PendingRequest *pr, int full_cleanup) |
670 | { | 669 | { |
671 | GSF_LocalLookupContinuation cont; | 670 | GSF_LocalLookupContinuation cont; |
672 | 671 | ||
673 | if (NULL == pr_map) | 672 | if (NULL == pr_map) |
674 | return; /* already cleaned up! */ | 673 | return; /* already cleaned up! */ |
675 | if (GNUNET_NO == full_cleanup) | 674 | if (GNUNET_NO == full_cleanup) |
676 | { | ||
677 | /* make request inactive (we're no longer interested in more results), | ||
678 | * but do NOT remove from our data-structures, we still need it there | ||
679 | * to prevent the request from looping */ | ||
680 | pr->rh = NULL; | ||
681 | if (NULL != pr->cadet_request) | ||
682 | { | 675 | { |
683 | pr->cadet_retry_count = CADET_RETRY_MAX; | 676 | /* make request inactive (we're no longer interested in more results), |
684 | GSF_cadet_query_cancel (pr->cadet_request); | 677 | * but do NOT remove from our data-structures, we still need it there |
685 | pr->cadet_request = NULL; | 678 | * to prevent the request from looping */ |
679 | pr->rh = NULL; | ||
680 | if (NULL != pr->cadet_request) | ||
681 | { | ||
682 | pr->cadet_retry_count = CADET_RETRY_MAX; | ||
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; | ||
686 | } | 708 | } |
687 | if (NULL != (cont = pr->llc_cont)) | 709 | GNUNET_assert(GNUNET_YES == |
688 | { | 710 | clean_request(NULL, &pr->public_data.query, pr)); |
689 | pr->llc_cont = NULL; | ||
690 | cont (pr->llc_cont_cls, pr, pr->local_result); | ||
691 | } | ||
692 | GSF_plan_notify_request_done_ (pr); | ||
693 | if (NULL != pr->qe) | ||
694 | { | ||
695 | GNUNET_DATASTORE_cancel (pr->qe); | ||
696 | pr->qe = NULL; | ||
697 | } | ||
698 | if (NULL != pr->gh) | ||
699 | { | ||
700 | GNUNET_DHT_get_stop (pr->gh); | ||
701 | pr->gh = NULL; | ||
702 | } | ||
703 | if (NULL != pr->warn_task) | ||
704 | { | ||
705 | GNUNET_SCHEDULER_cancel (pr->warn_task); | ||
706 | pr->warn_task = NULL; | ||
707 | } | ||
708 | return; | ||
709 | } | ||
710 | GNUNET_assert (GNUNET_YES == | ||
711 | clean_request (NULL, &pr->public_data.query, pr)); | ||
712 | } | 711 | } |
713 | 712 | ||
714 | 713 | ||
@@ -719,11 +718,11 @@ GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup) | |||
719 | * @param cls closure for @a it | 718 | * @param cls closure for @a it |
720 | */ | 719 | */ |
721 | void | 720 | void |
722 | GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls) | 721 | GSF_iterate_pending_requests_(GSF_PendingRequestIterator it, void *cls) |
723 | { | 722 | { |
724 | GNUNET_CONTAINER_multihashmap_iterate ( | 723 | GNUNET_CONTAINER_multihashmap_iterate( |
725 | pr_map, | 724 | pr_map, |
726 | (GNUNET_CONTAINER_MulitHashMapIteratorCallback) it, | 725 | (GNUNET_CONTAINER_MulitHashMapIteratorCallback)it, |
727 | cls); | 726 | cls); |
728 | } | 727 | } |
729 | 728 | ||
@@ -731,8 +730,7 @@ GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls) | |||
731 | /** | 730 | /** |
732 | * Closure for process_reply() function. | 731 | * Closure for process_reply() function. |
733 | */ | 732 | */ |
734 | struct ProcessReplyClosure | 733 | struct ProcessReplyClosure { |
735 | { | ||
736 | /** | 734 | /** |
737 | * The data for the reply. | 735 | * The data for the reply. |
738 | */ | 736 | */ |
@@ -793,14 +791,14 @@ struct ProcessReplyClosure | |||
793 | * @param pr request that was satisfied | 791 | * @param pr request that was satisfied |
794 | */ | 792 | */ |
795 | static void | 793 | static void |
796 | update_request_performance_data (struct ProcessReplyClosure *prq, | 794 | update_request_performance_data(struct ProcessReplyClosure *prq, |
797 | struct GSF_PendingRequest *pr) | 795 | struct GSF_PendingRequest *pr) |
798 | { | 796 | { |
799 | if (prq->sender == NULL) | 797 | if (prq->sender == NULL) |
800 | return; | 798 | return; |
801 | GSF_peer_update_performance_ (prq->sender, | 799 | GSF_peer_update_performance_(prq->sender, |
802 | pr->public_data.start_time, | 800 | pr->public_data.start_time, |
803 | prq->priority); | 801 | prq->priority); |
804 | } | 802 | } |
805 | 803 | ||
806 | 804 | ||
@@ -813,7 +811,7 @@ update_request_performance_data (struct ProcessReplyClosure *prq, | |||
813 | * @return #GNUNET_YES (we should continue to iterate) | 811 | * @return #GNUNET_YES (we should continue to iterate) |
814 | */ | 812 | */ |
815 | static int | 813 | static int |
816 | process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) | 814 | process_reply(void *cls, const struct GNUNET_HashCode *key, void *value) |
817 | { | 815 | { |
818 | struct ProcessReplyClosure *prq = cls; | 816 | struct ProcessReplyClosure *prq = cls; |
819 | struct GSF_PendingRequest *pr = value; | 817 | struct GSF_PendingRequest *pr = value; |
@@ -822,121 +820,128 @@ process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
822 | 820 | ||
823 | if (NULL == pr->rh) | 821 | if (NULL == pr->rh) |
824 | return GNUNET_YES; | 822 | return GNUNET_YES; |
825 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 823 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
826 | "Matched result (type %u) for query `%s' with pending request\n", | 824 | "Matched result (type %u) for query `%s' with pending request\n", |
827 | (unsigned int) prq->type, | 825 | (unsigned int)prq->type, |
828 | GNUNET_h2s (key)); | 826 | GNUNET_h2s(key)); |
829 | GNUNET_STATISTICS_update (GSF_stats, | 827 | GNUNET_STATISTICS_update(GSF_stats, |
830 | gettext_noop ("# replies received and matched"), | 828 | gettext_noop("# replies received and matched"), |
831 | 1, | 829 | 1, |
832 | GNUNET_NO); | 830 | GNUNET_NO); |
833 | prq->eval = GNUNET_BLOCK_evaluate (GSF_block_ctx, | 831 | prq->eval = GNUNET_BLOCK_evaluate(GSF_block_ctx, |
834 | prq->type, | 832 | prq->type, |
835 | pr->bg, | 833 | pr->bg, |
836 | prq->eo, | 834 | prq->eo, |
837 | key, | 835 | key, |
838 | NULL, | 836 | NULL, |
839 | 0, | 837 | 0, |
840 | prq->data, | 838 | prq->data, |
841 | prq->size); | 839 | prq->size); |
842 | switch (prq->eval) | 840 | switch (prq->eval) |
843 | { | 841 | { |
844 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 842 | case GNUNET_BLOCK_EVALUATION_OK_MORE: |
845 | update_request_performance_data (prq, pr); | 843 | update_request_performance_data(prq, pr); |
846 | break; | 844 | break; |
847 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | 845 | |
848 | /* short cut: stop processing early, no BF-update, etc. */ | 846 | case GNUNET_BLOCK_EVALUATION_OK_LAST: |
849 | update_request_performance_data (prq, pr); | 847 | /* short cut: stop processing early, no BF-update, etc. */ |
850 | GNUNET_LOAD_update (GSF_rt_entry_lifetime, | 848 | update_request_performance_data(prq, pr); |
851 | GNUNET_TIME_absolute_get_duration ( | 849 | GNUNET_LOAD_update(GSF_rt_entry_lifetime, |
852 | pr->public_data.start_time) | 850 | GNUNET_TIME_absolute_get_duration( |
853 | .rel_value_us); | 851 | pr->public_data.start_time) |
854 | if (GNUNET_YES != | 852 | .rel_value_us); |
855 | GSF_request_plan_reference_get_last_transmission_ (pr->public_data | 853 | if (GNUNET_YES != |
856 | .pr_head, | 854 | GSF_request_plan_reference_get_last_transmission_(pr->public_data |
857 | prq->sender, | 855 | .pr_head, |
858 | &last_transmission)) | 856 | prq->sender, |
859 | last_transmission.abs_value_us = | 857 | &last_transmission)) |
860 | GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 858 | last_transmission.abs_value_us = |
861 | /* pass on to other peers / local clients */ | 859 | GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
862 | pr->rh (pr->rh_cls, | 860 | /* pass on to other peers / local clients */ |
863 | prq->eval, | 861 | pr->rh(pr->rh_cls, |
864 | pr, | 862 | prq->eval, |
865 | prq->anonymity_level, | 863 | pr, |
866 | prq->expiration, | 864 | prq->anonymity_level, |
867 | last_transmission, | 865 | prq->expiration, |
868 | prq->type, | 866 | last_transmission, |
869 | prq->data, | 867 | prq->type, |
870 | prq->size); | 868 | prq->data, |
871 | return GNUNET_YES; | 869 | prq->size); |
872 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | 870 | return GNUNET_YES; |
871 | |||
872 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | ||
873 | #if INSANE_STATISTICS | 873 | #if INSANE_STATISTICS |
874 | GNUNET_STATISTICS_update (GSF_stats, | 874 | GNUNET_STATISTICS_update(GSF_stats, |
875 | gettext_noop ( | 875 | gettext_noop( |
876 | "# duplicate replies discarded (bloomfilter)"), | 876 | "# duplicate replies discarded (bloomfilter)"), |
877 | 1, | 877 | 1, |
878 | GNUNET_NO); | 878 | GNUNET_NO); |
879 | #endif | 879 | #endif |
880 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Duplicate response, discarding.\n"); | 880 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Duplicate response, discarding.\n"); |
881 | return GNUNET_YES; /* duplicate */ | 881 | return GNUNET_YES; /* duplicate */ |
882 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: | 882 | |
883 | GNUNET_STATISTICS_update (GSF_stats, | 883 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: |
884 | gettext_noop ("# irrelevant replies discarded"), | 884 | GNUNET_STATISTICS_update(GSF_stats, |
885 | 1, | 885 | gettext_noop("# irrelevant replies discarded"), |
886 | GNUNET_NO); | 886 | 1, |
887 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Irrelevant response, ignoring.\n"); | 887 | GNUNET_NO); |
888 | return GNUNET_YES; | 888 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Irrelevant response, ignoring.\n"); |
889 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: | 889 | return GNUNET_YES; |
890 | return GNUNET_YES; /* wrong namespace */ | 890 | |
891 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | 891 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: |
892 | GNUNET_break (0); | 892 | return GNUNET_YES; /* wrong namespace */ |
893 | return GNUNET_YES; | 893 | |
894 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: | 894 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: |
895 | GNUNET_break (0); | 895 | GNUNET_break(0); |
896 | return GNUNET_YES; | 896 | return GNUNET_YES; |
897 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | 897 | |
898 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 898 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: |
899 | _ ("Unsupported block type %u\n"), | 899 | GNUNET_break(0); |
900 | prq->type); | 900 | return GNUNET_YES; |
901 | return GNUNET_NO; | 901 | |
902 | } | 902 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
903 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
904 | _("Unsupported block type %u\n"), | ||
905 | prq->type); | ||
906 | return GNUNET_NO; | ||
907 | } | ||
903 | /* update bloomfilter */ | 908 | /* update bloomfilter */ |
904 | GNUNET_CRYPTO_hash (prq->data, prq->size, &chash); | 909 | GNUNET_CRYPTO_hash(prq->data, prq->size, &chash); |
905 | GSF_pending_request_update_ (pr, &chash, 1); | 910 | GSF_pending_request_update_(pr, &chash, 1); |
906 | if (NULL == prq->sender) | 911 | if (NULL == prq->sender) |
907 | { | 912 | { |
908 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 913 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
909 | "Found result for query `%s' in local datastore\n", | 914 | "Found result for query `%s' in local datastore\n", |
910 | GNUNET_h2s (key)); | 915 | GNUNET_h2s(key)); |
911 | GNUNET_STATISTICS_update (GSF_stats, | 916 | GNUNET_STATISTICS_update(GSF_stats, |
912 | gettext_noop ("# results found locally"), | 917 | gettext_noop("# results found locally"), |
913 | 1, | 918 | 1, |
914 | GNUNET_NO); | 919 | GNUNET_NO); |
915 | } | 920 | } |
916 | else | 921 | else |
917 | { | 922 | { |
918 | GSF_dht_lookup_ (pr); | 923 | GSF_dht_lookup_(pr); |
919 | } | 924 | } |
920 | prq->priority += pr->public_data.original_priority; | 925 | prq->priority += pr->public_data.original_priority; |
921 | pr->public_data.priority = 0; | 926 | pr->public_data.priority = 0; |
922 | pr->public_data.original_priority = 0; | 927 | pr->public_data.original_priority = 0; |
923 | pr->public_data.results_found++; | 928 | pr->public_data.results_found++; |
924 | prq->request_found = GNUNET_YES; | 929 | prq->request_found = GNUNET_YES; |
925 | /* finally, pass on to other peer / local client */ | 930 | /* finally, pass on to other peer / local client */ |
926 | if (! GSF_request_plan_reference_get_last_transmission_ (pr->public_data | 931 | if (!GSF_request_plan_reference_get_last_transmission_(pr->public_data |
927 | .pr_head, | 932 | .pr_head, |
928 | prq->sender, | 933 | prq->sender, |
929 | &last_transmission)) | 934 | &last_transmission)) |
930 | last_transmission.abs_value_us = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 935 | last_transmission.abs_value_us = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
931 | pr->rh (pr->rh_cls, | 936 | pr->rh(pr->rh_cls, |
932 | prq->eval, | 937 | prq->eval, |
933 | pr, | 938 | pr, |
934 | prq->anonymity_level, | 939 | prq->anonymity_level, |
935 | prq->expiration, | 940 | prq->expiration, |
936 | last_transmission, | 941 | last_transmission, |
937 | prq->type, | 942 | prq->type, |
938 | prq->data, | 943 | prq->data, |
939 | prq->size); | 944 | prq->size); |
940 | return GNUNET_YES; | 945 | return GNUNET_YES; |
941 | } | 946 | } |
942 | 947 | ||
@@ -944,9 +949,7 @@ process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
944 | /** | 949 | /** |
945 | * Context for put_migration_continuation(). | 950 | * Context for put_migration_continuation(). |
946 | */ | 951 | */ |
947 | struct PutMigrationContext | 952 | struct PutMigrationContext { |
948 | { | ||
949 | |||
950 | /** | 953 | /** |
951 | * Start time for the operation. | 954 | * Start time for the operation. |
952 | */ | 955 | */ |
@@ -975,10 +978,10 @@ struct PutMigrationContext | |||
975 | * @param msg NULL on success, otherwise an error message | 978 | * @param msg NULL on success, otherwise an error message |
976 | */ | 979 | */ |
977 | static void | 980 | static void |
978 | put_migration_continuation (void *cls, | 981 | put_migration_continuation(void *cls, |
979 | int success, | 982 | int success, |
980 | struct GNUNET_TIME_Absolute min_expiration, | 983 | struct GNUNET_TIME_Absolute min_expiration, |
981 | const char *msg) | 984 | const char *msg) |
982 | { | 985 | { |
983 | struct PutMigrationContext *pmc = cls; | 986 | struct PutMigrationContext *pmc = cls; |
984 | struct GSF_ConnectedPeer *cp; | 987 | struct GSF_ConnectedPeer *cp; |
@@ -986,67 +989,67 @@ put_migration_continuation (void *cls, | |||
986 | struct GSF_PeerPerformanceData *ppd; | 989 | struct GSF_PeerPerformanceData *ppd; |
987 | 990 | ||
988 | if (NULL != datastore_put_load) | 991 | if (NULL != datastore_put_load) |
989 | { | ||
990 | if (GNUNET_SYSERR != success) | ||
991 | { | 992 | { |
992 | GNUNET_LOAD_update (datastore_put_load, | 993 | if (GNUNET_SYSERR != success) |
993 | GNUNET_TIME_absolute_get_duration (pmc->start) | 994 | { |
994 | .rel_value_us); | 995 | GNUNET_LOAD_update(datastore_put_load, |
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 | } | ||
995 | } | 1005 | } |
996 | else | 1006 | cp = GSF_peer_get_(&pmc->origin); |
997 | { | ||
998 | /* on queue failure / timeout, increase the put load dramatically */ | ||
999 | GNUNET_LOAD_update (datastore_put_load, | ||
1000 | GNUNET_TIME_UNIT_MINUTES.rel_value_us); | ||
1001 | } | ||
1002 | } | ||
1003 | cp = GSF_peer_get_ (&pmc->origin); | ||
1004 | if (GNUNET_OK == success) | 1007 | if (GNUNET_OK == success) |
1005 | { | ||
1006 | if (NULL != cp) | ||
1007 | { | 1008 | { |
1008 | ppd = GSF_get_peer_performance_data_ (cp); | 1009 | if (NULL != cp) |
1009 | ppd->migration_delay.rel_value_us /= 2; | 1010 | { |
1011 | ppd = GSF_get_peer_performance_data_(cp); | ||
1012 | ppd->migration_delay.rel_value_us /= 2; | ||
1013 | } | ||
1014 | GNUNET_free(pmc); | ||
1015 | return; | ||
1010 | } | 1016 | } |
1011 | GNUNET_free (pmc); | ||
1012 | return; | ||
1013 | } | ||
1014 | if ((GNUNET_NO == success) && (GNUNET_NO == pmc->requested) && (NULL != cp)) | 1017 | if ((GNUNET_NO == success) && (GNUNET_NO == pmc->requested) && (NULL != cp)) |
1015 | { | ||
1016 | ppd = GSF_get_peer_performance_data_ (cp); | ||
1017 | if (min_expiration.abs_value_us > 0) | ||
1018 | { | ||
1019 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1020 | "Asking to stop migration for %s because datastore is full\n", | ||
1021 | GNUNET_STRINGS_relative_time_to_string ( | ||
1022 | GNUNET_TIME_absolute_get_remaining (min_expiration), | ||
1023 | GNUNET_YES)); | ||
1024 | GSF_block_peer_migration_ (cp, min_expiration); | ||
1025 | } | ||
1026 | else | ||
1027 | { | 1018 | { |
1028 | ppd->migration_delay = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_SECONDS, | 1019 | ppd = GSF_get_peer_performance_data_(cp); |
1029 | ppd->migration_delay); | 1020 | if (min_expiration.abs_value_us > 0) |
1030 | ppd->migration_delay = | 1021 | { |
1031 | GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, ppd->migration_delay); | 1022 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1032 | mig_pause.rel_value_us = | 1023 | "Asking to stop migration for %s because datastore is full\n", |
1033 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1024 | GNUNET_STRINGS_relative_time_to_string( |
1034 | ppd->migration_delay.rel_value_us); | 1025 | GNUNET_TIME_absolute_get_remaining(min_expiration), |
1035 | ppd->migration_delay = | 1026 | GNUNET_YES)); |
1036 | GNUNET_TIME_relative_saturating_multiply (ppd->migration_delay, 2); | 1027 | GSF_block_peer_migration_(cp, min_expiration); |
1037 | GNUNET_log ( | 1028 | } |
1038 | GNUNET_ERROR_TYPE_DEBUG, | 1029 | else |
1039 | "Replicated content already exists locally, asking to stop migration for %s\n", | 1030 | { |
1040 | GNUNET_STRINGS_relative_time_to_string (mig_pause, GNUNET_YES)); | 1031 | ppd->migration_delay = GNUNET_TIME_relative_max(GNUNET_TIME_UNIT_SECONDS, |
1041 | GSF_block_peer_migration_ (cp, | 1032 | ppd->migration_delay); |
1042 | GNUNET_TIME_relative_to_absolute (mig_pause)); | 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 | } | ||
1043 | } | 1047 | } |
1044 | } | 1048 | GNUNET_free(pmc); |
1045 | GNUNET_free (pmc); | 1049 | GNUNET_STATISTICS_update(GSF_stats, |
1046 | GNUNET_STATISTICS_update (GSF_stats, | 1050 | gettext_noop("# Datastore `PUT' failures"), |
1047 | gettext_noop ("# Datastore `PUT' failures"), | 1051 | 1, |
1048 | 1, | 1052 | GNUNET_NO); |
1049 | GNUNET_NO); | ||
1050 | } | 1053 | } |
1051 | 1054 | ||
1052 | 1055 | ||
@@ -1060,22 +1063,22 @@ put_migration_continuation (void *cls, | |||
1060 | * #GNUNET_NO to process normally (load normal or low) | 1063 | * #GNUNET_NO to process normally (load normal or low) |
1061 | */ | 1064 | */ |
1062 | static int | 1065 | static int |
1063 | test_put_load_too_high (uint32_t priority) | 1066 | test_put_load_too_high(uint32_t priority) |
1064 | { | 1067 | { |
1065 | double ld; | 1068 | double ld; |
1066 | 1069 | ||
1067 | if (NULL == datastore_put_load) | 1070 | if (NULL == datastore_put_load) |
1068 | return GNUNET_NO; | 1071 | return GNUNET_NO; |
1069 | if (GNUNET_LOAD_get_average (datastore_put_load) < 50) | 1072 | if (GNUNET_LOAD_get_average(datastore_put_load) < 50) |
1070 | return GNUNET_NO; /* very fast */ | 1073 | return GNUNET_NO; /* very fast */ |
1071 | ld = GNUNET_LOAD_get_load (datastore_put_load); | 1074 | ld = GNUNET_LOAD_get_load(datastore_put_load); |
1072 | if (ld < 2.0 * (1 + priority)) | 1075 | if (ld < 2.0 * (1 + priority)) |
1073 | return GNUNET_NO; | 1076 | return GNUNET_NO; |
1074 | GNUNET_STATISTICS_update (GSF_stats, | 1077 | GNUNET_STATISTICS_update(GSF_stats, |
1075 | gettext_noop ( | 1078 | gettext_noop( |
1076 | "# storage requests dropped due to high load"), | 1079 | "# storage requests dropped due to high load"), |
1077 | 1, | 1080 | 1, |
1078 | GNUNET_NO); | 1081 | GNUNET_NO); |
1079 | return GNUNET_YES; | 1082 | return GNUNET_YES; |
1080 | } | 1083 | } |
1081 | 1084 | ||
@@ -1096,67 +1099,67 @@ test_put_load_too_high (uint32_t priority) | |||
1096 | * @param data pointer to the result data | 1099 | * @param data pointer to the result data |
1097 | */ | 1100 | */ |
1098 | static void | 1101 | static void |
1099 | handle_dht_reply (void *cls, | 1102 | handle_dht_reply(void *cls, |
1100 | struct GNUNET_TIME_Absolute exp, | 1103 | struct GNUNET_TIME_Absolute exp, |
1101 | const struct GNUNET_HashCode *key, | 1104 | const struct GNUNET_HashCode *key, |
1102 | const struct GNUNET_PeerIdentity *get_path, | 1105 | const struct GNUNET_PeerIdentity *get_path, |
1103 | unsigned int get_path_length, | 1106 | unsigned int get_path_length, |
1104 | const struct GNUNET_PeerIdentity *put_path, | 1107 | const struct GNUNET_PeerIdentity *put_path, |
1105 | unsigned int put_path_length, | 1108 | unsigned int put_path_length, |
1106 | enum GNUNET_BLOCK_Type type, | 1109 | enum GNUNET_BLOCK_Type type, |
1107 | size_t size, | 1110 | size_t size, |
1108 | const void *data) | 1111 | const void *data) |
1109 | { | 1112 | { |
1110 | struct GSF_PendingRequest *pr = cls; | 1113 | struct GSF_PendingRequest *pr = cls; |
1111 | struct ProcessReplyClosure prq; | 1114 | struct ProcessReplyClosure prq; |
1112 | struct PutMigrationContext *pmc; | 1115 | struct PutMigrationContext *pmc; |
1113 | 1116 | ||
1114 | GNUNET_STATISTICS_update (GSF_stats, | 1117 | GNUNET_STATISTICS_update(GSF_stats, |
1115 | gettext_noop ("# Replies received from DHT"), | 1118 | gettext_noop("# Replies received from DHT"), |
1116 | 1, | 1119 | 1, |
1117 | GNUNET_NO); | 1120 | GNUNET_NO); |
1118 | memset (&prq, 0, sizeof (prq)); | 1121 | memset(&prq, 0, sizeof(prq)); |
1119 | prq.data = data; | 1122 | prq.data = data; |
1120 | prq.expiration = exp; | 1123 | prq.expiration = exp; |
1121 | /* do not allow migrated content to live longer than 1 year */ | 1124 | /* do not allow migrated content to live longer than 1 year */ |
1122 | prq.expiration = GNUNET_TIME_absolute_min (GNUNET_TIME_relative_to_absolute ( | 1125 | prq.expiration = GNUNET_TIME_absolute_min(GNUNET_TIME_relative_to_absolute( |
1123 | GNUNET_TIME_UNIT_YEARS), | 1126 | GNUNET_TIME_UNIT_YEARS), |
1124 | prq.expiration); | 1127 | prq.expiration); |
1125 | prq.size = size; | 1128 | prq.size = size; |
1126 | prq.type = type; | 1129 | prq.type = type; |
1127 | prq.eo = GNUNET_BLOCK_EO_NONE; | 1130 | prq.eo = GNUNET_BLOCK_EO_NONE; |
1128 | process_reply (&prq, key, pr); | 1131 | process_reply(&prq, key, pr); |
1129 | if ((GNUNET_YES == active_to_migration) && | 1132 | if ((GNUNET_YES == active_to_migration) && |
1130 | (GNUNET_NO == test_put_load_too_high (prq.priority))) | 1133 | (GNUNET_NO == test_put_load_too_high(prq.priority))) |
1131 | { | ||
1132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1133 | "Replicating result for query `%s' with priority %u\n", | ||
1134 | GNUNET_h2s (key), | ||
1135 | prq.priority); | ||
1136 | pmc = GNUNET_new (struct PutMigrationContext); | ||
1137 | pmc->start = GNUNET_TIME_absolute_get (); | ||
1138 | pmc->requested = GNUNET_YES; | ||
1139 | if (NULL == GNUNET_DATASTORE_put (GSF_dsh, | ||
1140 | 0, | ||
1141 | key, | ||
1142 | size, | ||
1143 | data, | ||
1144 | type, | ||
1145 | prq.priority, | ||
1146 | 1 /* anonymity */, | ||
1147 | 0 /* replication */, | ||
1148 | exp, | ||
1149 | 1 + prq.priority, | ||
1150 | MAX_DATASTORE_QUEUE, | ||
1151 | &put_migration_continuation, | ||
1152 | pmc)) | ||
1153 | { | 1134 | { |
1154 | put_migration_continuation (pmc, | 1135 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1155 | GNUNET_SYSERR, | 1136 | "Replicating result for query `%s' with priority %u\n", |
1156 | GNUNET_TIME_UNIT_ZERO_ABS, | 1137 | GNUNET_h2s(key), |
1157 | NULL); | 1138 | prq.priority); |
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 | } | ||
1158 | } | 1162 | } |
1159 | } | ||
1160 | } | 1163 | } |
1161 | 1164 | ||
1162 | 1165 | ||
@@ -1166,42 +1169,42 @@ handle_dht_reply (void *cls, | |||
1166 | * @param pr the pending request to process | 1169 | * @param pr the pending request to process |
1167 | */ | 1170 | */ |
1168 | void | 1171 | void |
1169 | GSF_dht_lookup_ (struct GSF_PendingRequest *pr) | 1172 | GSF_dht_lookup_(struct GSF_PendingRequest *pr) |
1170 | { | 1173 | { |
1171 | const void *xquery; | 1174 | const void *xquery; |
1172 | size_t xquery_size; | 1175 | size_t xquery_size; |
1173 | struct GNUNET_PeerIdentity pi; | 1176 | struct GNUNET_PeerIdentity pi; |
1174 | char buf[sizeof (struct GNUNET_HashCode) * 2] GNUNET_ALIGN; | 1177 | char buf[sizeof(struct GNUNET_HashCode) * 2] GNUNET_ALIGN; |
1175 | 1178 | ||
1176 | if (0 != pr->public_data.anonymity_level) | 1179 | if (0 != pr->public_data.anonymity_level) |
1177 | return; | 1180 | return; |
1178 | if (NULL != pr->gh) | 1181 | if (NULL != pr->gh) |
1179 | { | 1182 | { |
1180 | GNUNET_DHT_get_stop (pr->gh); | 1183 | GNUNET_DHT_get_stop(pr->gh); |
1181 | pr->gh = NULL; | 1184 | pr->gh = NULL; |
1182 | } | 1185 | } |
1183 | xquery = NULL; | 1186 | xquery = NULL; |
1184 | xquery_size = 0; | 1187 | xquery_size = 0; |
1185 | if (0 != (pr->public_data.options & GSF_PRO_FORWARD_ONLY)) | 1188 | if (0 != (pr->public_data.options & GSF_PRO_FORWARD_ONLY)) |
1186 | { | 1189 | { |
1187 | GNUNET_assert (0 != pr->sender_pid); | 1190 | GNUNET_assert(0 != pr->sender_pid); |
1188 | GNUNET_PEER_resolve (pr->sender_pid, &pi); | 1191 | GNUNET_PEER_resolve(pr->sender_pid, &pi); |
1189 | GNUNET_memcpy (&buf[xquery_size], &pi, sizeof (struct GNUNET_PeerIdentity)); | 1192 | GNUNET_memcpy(&buf[xquery_size], &pi, sizeof(struct GNUNET_PeerIdentity)); |
1190 | xquery_size += sizeof (struct GNUNET_PeerIdentity); | 1193 | xquery_size += sizeof(struct GNUNET_PeerIdentity); |
1191 | } | 1194 | } |
1192 | pr->gh = GNUNET_DHT_get_start (GSF_dht, | 1195 | pr->gh = GNUNET_DHT_get_start(GSF_dht, |
1193 | pr->public_data.type, | 1196 | pr->public_data.type, |
1194 | &pr->public_data.query, | 1197 | &pr->public_data.query, |
1195 | DHT_GET_REPLICATION, | 1198 | DHT_GET_REPLICATION, |
1196 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 1199 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
1197 | xquery, | 1200 | xquery, |
1198 | xquery_size, | 1201 | xquery_size, |
1199 | &handle_dht_reply, | 1202 | &handle_dht_reply, |
1200 | pr); | 1203 | pr); |
1201 | if ((NULL != pr->gh) && (0 != pr->replies_seen_count)) | 1204 | if ((NULL != pr->gh) && (0 != pr->replies_seen_count)) |
1202 | GNUNET_DHT_get_filter_known_results (pr->gh, | 1205 | GNUNET_DHT_get_filter_known_results(pr->gh, |
1203 | pr->replies_seen_count, | 1206 | pr->replies_seen_count, |
1204 | pr->replies_seen); | 1207 | pr->replies_seen); |
1205 | } | 1208 | } |
1206 | 1209 | ||
1207 | 1210 | ||
@@ -1215,11 +1218,11 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr) | |||
1215 | * @param data reply block data, NULL on error | 1218 | * @param data reply block data, NULL on error |
1216 | */ | 1219 | */ |
1217 | static void | 1220 | static void |
1218 | cadet_reply_proc (void *cls, | 1221 | cadet_reply_proc(void *cls, |
1219 | enum GNUNET_BLOCK_Type type, | 1222 | enum GNUNET_BLOCK_Type type, |
1220 | struct GNUNET_TIME_Absolute expiration, | 1223 | struct GNUNET_TIME_Absolute expiration, |
1221 | size_t data_size, | 1224 | size_t data_size, |
1222 | const void *data) | 1225 | const void *data) |
1223 | { | 1226 | { |
1224 | struct GSF_PendingRequest *pr = cls; | 1227 | struct GSF_PendingRequest *pr = cls; |
1225 | struct ProcessReplyClosure prq; | 1228 | struct ProcessReplyClosure prq; |
@@ -1227,46 +1230,46 @@ cadet_reply_proc (void *cls, | |||
1227 | 1230 | ||
1228 | pr->cadet_request = NULL; | 1231 | pr->cadet_request = NULL; |
1229 | if (GNUNET_BLOCK_TYPE_ANY == type) | 1232 | if (GNUNET_BLOCK_TYPE_ANY == type) |
1230 | { | 1233 | { |
1231 | GNUNET_break (NULL == data); | 1234 | GNUNET_break(NULL == data); |
1232 | GNUNET_break (0 == data_size); | 1235 | GNUNET_break(0 == data_size); |
1233 | pr->cadet_retry_count++; | 1236 | pr->cadet_retry_count++; |
1234 | if (pr->cadet_retry_count >= CADET_RETRY_MAX) | 1237 | if (pr->cadet_retry_count >= CADET_RETRY_MAX) |
1235 | return; /* give up on cadet */ | 1238 | return; /* give up on cadet */ |
1236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error retrieiving block via cadet\n"); | 1239 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Error retrieiving block via cadet\n"); |
1237 | /* retry -- without delay, as this is non-anonymous | 1240 | /* retry -- without delay, as this is non-anonymous |
1238 | and cadet/cadet connect will take some time anyway */ | 1241 | and cadet/cadet connect will take some time anyway */ |
1239 | pr->cadet_request = GSF_cadet_query (pr->public_data.target, | 1242 | pr->cadet_request = GSF_cadet_query(pr->public_data.target, |
1240 | &pr->public_data.query, | 1243 | &pr->public_data.query, |
1241 | pr->public_data.type, | 1244 | pr->public_data.type, |
1242 | &cadet_reply_proc, | 1245 | &cadet_reply_proc, |
1243 | pr); | 1246 | pr); |
1244 | return; | 1247 | return; |
1245 | } | 1248 | } |
1246 | if (GNUNET_YES != | 1249 | if (GNUNET_YES != |
1247 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, data_size, &query)) | 1250 | GNUNET_BLOCK_get_key(GSF_block_ctx, type, data, data_size, &query)) |
1248 | { | 1251 | { |
1249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1252 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1250 | "Failed to derive key for block of type %d\n", | 1253 | "Failed to derive key for block of type %d\n", |
1251 | (int) type); | 1254 | (int)type); |
1252 | GNUNET_break_op (0); | 1255 | GNUNET_break_op(0); |
1253 | return; | 1256 | return; |
1254 | } | 1257 | } |
1255 | GNUNET_STATISTICS_update (GSF_stats, | 1258 | GNUNET_STATISTICS_update(GSF_stats, |
1256 | gettext_noop ("# Replies received from CADET"), | 1259 | gettext_noop("# Replies received from CADET"), |
1257 | 1, | 1260 | 1, |
1258 | GNUNET_NO); | 1261 | GNUNET_NO); |
1259 | memset (&prq, 0, sizeof (prq)); | 1262 | memset(&prq, 0, sizeof(prq)); |
1260 | prq.data = data; | 1263 | prq.data = data; |
1261 | prq.expiration = expiration; | 1264 | prq.expiration = expiration; |
1262 | /* do not allow migrated content to live longer than 1 year */ | 1265 | /* do not allow migrated content to live longer than 1 year */ |
1263 | prq.expiration = GNUNET_TIME_absolute_min (GNUNET_TIME_relative_to_absolute ( | 1266 | prq.expiration = GNUNET_TIME_absolute_min(GNUNET_TIME_relative_to_absolute( |
1264 | GNUNET_TIME_UNIT_YEARS), | 1267 | GNUNET_TIME_UNIT_YEARS), |
1265 | prq.expiration); | 1268 | prq.expiration); |
1266 | prq.size = data_size; | 1269 | prq.size = data_size; |
1267 | prq.type = type; | 1270 | prq.type = type; |
1268 | prq.eo = GNUNET_BLOCK_EO_NONE; | 1271 | prq.eo = GNUNET_BLOCK_EO_NONE; |
1269 | process_reply (&prq, &query, pr); | 1272 | process_reply(&prq, &query, pr); |
1270 | } | 1273 | } |
1271 | 1274 | ||
1272 | 1275 | ||
@@ -1276,23 +1279,23 @@ cadet_reply_proc (void *cls, | |||
1276 | * @param pr the pending request to process | 1279 | * @param pr the pending request to process |
1277 | */ | 1280 | */ |
1278 | void | 1281 | void |
1279 | GSF_cadet_lookup_ (struct GSF_PendingRequest *pr) | 1282 | GSF_cadet_lookup_(struct GSF_PendingRequest *pr) |
1280 | { | 1283 | { |
1281 | if (0 != pr->public_data.anonymity_level) | 1284 | if (0 != pr->public_data.anonymity_level) |
1282 | return; | 1285 | return; |
1283 | if (0 == pr->public_data.target) | 1286 | if (0 == pr->public_data.target) |
1284 | { | 1287 | { |
1285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1288 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1286 | "Cannot do cadet-based download, target peer not known\n"); | 1289 | "Cannot do cadet-based download, target peer not known\n"); |
1287 | return; | 1290 | return; |
1288 | } | 1291 | } |
1289 | if (NULL != pr->cadet_request) | 1292 | if (NULL != pr->cadet_request) |
1290 | return; | 1293 | return; |
1291 | pr->cadet_request = GSF_cadet_query (pr->public_data.target, | 1294 | pr->cadet_request = GSF_cadet_query(pr->public_data.target, |
1292 | &pr->public_data.query, | 1295 | &pr->public_data.query, |
1293 | pr->public_data.type, | 1296 | pr->public_data.type, |
1294 | &cadet_reply_proc, | 1297 | &cadet_reply_proc, |
1295 | pr); | 1298 | pr); |
1296 | } | 1299 | } |
1297 | 1300 | ||
1298 | 1301 | ||
@@ -1302,18 +1305,18 @@ GSF_cadet_lookup_ (struct GSF_PendingRequest *pr) | |||
1302 | * @param cls the `struct GSF_PendingRequest` | 1305 | * @param cls the `struct GSF_PendingRequest` |
1303 | */ | 1306 | */ |
1304 | static void | 1307 | static void |
1305 | warn_delay_task (void *cls) | 1308 | warn_delay_task(void *cls) |
1306 | { | 1309 | { |
1307 | struct GSF_PendingRequest *pr = cls; | 1310 | struct GSF_PendingRequest *pr = cls; |
1308 | 1311 | ||
1309 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 1312 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
1310 | _ ("Datastore lookup already took %s!\n"), | 1313 | _("Datastore lookup already took %s!\n"), |
1311 | GNUNET_STRINGS_relative_time_to_string ( | 1314 | GNUNET_STRINGS_relative_time_to_string( |
1312 | GNUNET_TIME_absolute_get_duration (pr->qe_start), | 1315 | GNUNET_TIME_absolute_get_duration(pr->qe_start), |
1313 | GNUNET_YES)); | 1316 | GNUNET_YES)); |
1314 | pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 1317 | pr->warn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, |
1315 | &warn_delay_task, | 1318 | &warn_delay_task, |
1316 | pr); | 1319 | pr); |
1317 | } | 1320 | } |
1318 | 1321 | ||
1319 | 1322 | ||
@@ -1323,140 +1326,140 @@ warn_delay_task (void *cls) | |||
1323 | * @param cls the `struct GSF_PendingRequest` | 1326 | * @param cls the `struct GSF_PendingRequest` |
1324 | */ | 1327 | */ |
1325 | static void | 1328 | static void |
1326 | odc_warn_delay_task (void *cls) | 1329 | odc_warn_delay_task(void *cls) |
1327 | { | 1330 | { |
1328 | struct GSF_PendingRequest *pr = cls; | 1331 | struct GSF_PendingRequest *pr = cls; |
1329 | 1332 | ||
1330 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1333 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1331 | _ ("On-demand lookup already took %s!\n"), | 1334 | _("On-demand lookup already took %s!\n"), |
1332 | GNUNET_STRINGS_relative_time_to_string ( | 1335 | GNUNET_STRINGS_relative_time_to_string( |
1333 | GNUNET_TIME_absolute_get_duration (pr->qe_start), | 1336 | GNUNET_TIME_absolute_get_duration(pr->qe_start), |
1334 | GNUNET_YES)); | 1337 | GNUNET_YES)); |
1335 | pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 1338 | pr->warn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, |
1336 | &odc_warn_delay_task, | 1339 | &odc_warn_delay_task, |
1337 | pr); | 1340 | pr); |
1338 | } | 1341 | } |
1339 | 1342 | ||
1340 | 1343 | ||
1341 | /* Call our continuation (if we have any) */ | 1344 | /* Call our continuation (if we have any) */ |
1342 | static void | 1345 | static void |
1343 | call_continuation (struct GSF_PendingRequest *pr) | 1346 | call_continuation(struct GSF_PendingRequest *pr) |
1344 | { | 1347 | { |
1345 | GSF_LocalLookupContinuation cont = pr->llc_cont; | 1348 | GSF_LocalLookupContinuation cont = pr->llc_cont; |
1346 | 1349 | ||
1347 | GNUNET_assert (NULL == pr->qe); | 1350 | GNUNET_assert(NULL == pr->qe); |
1348 | if (NULL != pr->warn_task) | 1351 | if (NULL != pr->warn_task) |
1349 | { | 1352 | { |
1350 | GNUNET_SCHEDULER_cancel (pr->warn_task); | 1353 | GNUNET_SCHEDULER_cancel(pr->warn_task); |
1351 | pr->warn_task = NULL; | 1354 | pr->warn_task = NULL; |
1352 | } | 1355 | } |
1353 | if (NULL == cont) | 1356 | if (NULL == cont) |
1354 | return; /* no continuation */ | 1357 | return; /* no continuation */ |
1355 | pr->llc_cont = NULL; | 1358 | pr->llc_cont = NULL; |
1356 | if (0 != (GSF_PRO_LOCAL_ONLY & pr->public_data.options)) | 1359 | if (0 != (GSF_PRO_LOCAL_ONLY & pr->public_data.options)) |
1357 | { | ||
1358 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != pr->local_result) | ||
1359 | { | 1360 | { |
1360 | /* Signal that we are done and that there won't be any | 1361 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != pr->local_result) |
1361 | additional results to allow client to clean up state. */ | 1362 | { |
1362 | pr->rh (pr->rh_cls, | 1363 | /* Signal that we are done and that there won't be any |
1363 | GNUNET_BLOCK_EVALUATION_OK_LAST, | 1364 | additional results to allow client to clean up state. */ |
1364 | pr, | 1365 | pr->rh(pr->rh_cls, |
1365 | UINT32_MAX, | 1366 | GNUNET_BLOCK_EVALUATION_OK_LAST, |
1366 | GNUNET_TIME_UNIT_ZERO_ABS, | 1367 | pr, |
1367 | GNUNET_TIME_UNIT_FOREVER_ABS, | 1368 | UINT32_MAX, |
1368 | GNUNET_BLOCK_TYPE_ANY, | 1369 | GNUNET_TIME_UNIT_ZERO_ABS, |
1369 | NULL, | 1370 | GNUNET_TIME_UNIT_FOREVER_ABS, |
1370 | 0); | 1371 | GNUNET_BLOCK_TYPE_ANY, |
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; | ||
1371 | } | 1380 | } |
1372 | /* Finally, call our continuation to signal that we are | ||
1373 | done with local processing of this request; i.e. to | ||
1374 | start reading again from the client. */ | ||
1375 | cont (pr->llc_cont_cls, NULL, GNUNET_BLOCK_EVALUATION_OK_LAST); | ||
1376 | return; | ||
1377 | } | ||
1378 | 1381 | ||
1379 | cont (pr->llc_cont_cls, pr, pr->local_result); | 1382 | cont(pr->llc_cont_cls, pr, pr->local_result); |
1380 | } | 1383 | } |
1381 | 1384 | ||
1382 | 1385 | ||
1383 | /* Update stats and call continuation */ | 1386 | /* Update stats and call continuation */ |
1384 | static void | 1387 | static void |
1385 | no_more_local_results (struct GSF_PendingRequest *pr) | 1388 | no_more_local_results(struct GSF_PendingRequest *pr) |
1386 | { | 1389 | { |
1387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1390 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1388 | "No further local responses available.\n"); | 1391 | "No further local responses available.\n"); |
1389 | #if INSANE_STATISTICS | 1392 | #if INSANE_STATISTICS |
1390 | if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == pr->public_data.type) || | 1393 | if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == pr->public_data.type) || |
1391 | (GNUNET_BLOCK_TYPE_FS_IBLOCK == pr->public_data.type)) | 1394 | (GNUNET_BLOCK_TYPE_FS_IBLOCK == pr->public_data.type)) |
1392 | GNUNET_STATISTICS_update (GSF_stats, | 1395 | GNUNET_STATISTICS_update(GSF_stats, |
1393 | gettext_noop ( | 1396 | gettext_noop( |
1394 | "# requested DBLOCK or IBLOCK not found"), | 1397 | "# requested DBLOCK or IBLOCK not found"), |
1395 | 1, | 1398 | 1, |
1396 | GNUNET_NO); | 1399 | GNUNET_NO); |
1397 | #endif | 1400 | #endif |
1398 | call_continuation (pr); | 1401 | call_continuation(pr); |
1399 | } | 1402 | } |
1400 | 1403 | ||
1401 | 1404 | ||
1402 | /* forward declaration */ | 1405 | /* forward declaration */ |
1403 | static void | 1406 | static void |
1404 | process_local_reply (void *cls, | 1407 | process_local_reply(void *cls, |
1405 | const struct GNUNET_HashCode *key, | 1408 | const struct GNUNET_HashCode *key, |
1406 | size_t size, | 1409 | size_t size, |
1407 | const void *data, | 1410 | const void *data, |
1408 | enum GNUNET_BLOCK_Type type, | 1411 | enum GNUNET_BLOCK_Type type, |
1409 | uint32_t priority, | 1412 | uint32_t priority, |
1410 | uint32_t anonymity, | 1413 | uint32_t anonymity, |
1411 | uint32_t replication, | 1414 | uint32_t replication, |
1412 | struct GNUNET_TIME_Absolute expiration, | 1415 | struct GNUNET_TIME_Absolute expiration, |
1413 | uint64_t uid); | 1416 | uint64_t uid); |
1414 | 1417 | ||
1415 | 1418 | ||
1416 | /* Start a local query */ | 1419 | /* Start a local query */ |
1417 | static void | 1420 | static void |
1418 | start_local_query (struct GSF_PendingRequest *pr, | 1421 | start_local_query(struct GSF_PendingRequest *pr, |
1419 | uint64_t next_uid, | 1422 | uint64_t next_uid, |
1420 | bool random) | 1423 | bool random) |
1421 | { | 1424 | { |
1422 | pr->qe_start = GNUNET_TIME_absolute_get (); | 1425 | pr->qe_start = GNUNET_TIME_absolute_get(); |
1423 | pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 1426 | pr->warn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, |
1424 | &warn_delay_task, | 1427 | &warn_delay_task, |
1425 | pr); | 1428 | pr); |
1426 | pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh, | 1429 | pr->qe = GNUNET_DATASTORE_get_key(GSF_dsh, |
1427 | next_uid, | 1430 | next_uid, |
1428 | random, | 1431 | random, |
1429 | &pr->public_data.query, | 1432 | &pr->public_data.query, |
1430 | pr->public_data.type == | 1433 | pr->public_data.type == |
1431 | GNUNET_BLOCK_TYPE_FS_DBLOCK | 1434 | GNUNET_BLOCK_TYPE_FS_DBLOCK |
1432 | ? GNUNET_BLOCK_TYPE_ANY | 1435 | ? GNUNET_BLOCK_TYPE_ANY |
1433 | : pr->public_data.type, | 1436 | : pr->public_data.type, |
1434 | (0 != (GSF_PRO_PRIORITY_UNLIMITED & | 1437 | (0 != (GSF_PRO_PRIORITY_UNLIMITED & |
1435 | pr->public_data.options)) | 1438 | pr->public_data.options)) |
1436 | ? UINT_MAX | 1439 | ? UINT_MAX |
1437 | : 1 | 1440 | : 1 |
1438 | /* queue priority */, | 1441 | /* queue priority */, |
1439 | (0 != (GSF_PRO_PRIORITY_UNLIMITED & | 1442 | (0 != (GSF_PRO_PRIORITY_UNLIMITED & |
1440 | pr->public_data.options)) | 1443 | pr->public_data.options)) |
1441 | ? UINT_MAX | 1444 | ? UINT_MAX |
1442 | : GSF_datastore_queue_size | 1445 | : GSF_datastore_queue_size |
1443 | /* max queue size */, | 1446 | /* max queue size */, |
1444 | &process_local_reply, | 1447 | &process_local_reply, |
1445 | pr); | 1448 | pr); |
1446 | if (NULL != pr->qe) | 1449 | if (NULL != pr->qe) |
1447 | return; | 1450 | return; |
1448 | GNUNET_log ( | 1451 | GNUNET_log( |
1449 | GNUNET_ERROR_TYPE_DEBUG, | 1452 | GNUNET_ERROR_TYPE_DEBUG, |
1450 | "ERROR Requesting `%s' of type %d with next_uid %llu from datastore.\n", | 1453 | "ERROR Requesting `%s' of type %d with next_uid %llu from datastore.\n", |
1451 | GNUNET_h2s (&pr->public_data.query), | 1454 | GNUNET_h2s(&pr->public_data.query), |
1452 | pr->public_data.type, | 1455 | pr->public_data.type, |
1453 | (unsigned long long) next_uid); | 1456 | (unsigned long long)next_uid); |
1454 | GNUNET_STATISTICS_update (GSF_stats, | 1457 | GNUNET_STATISTICS_update(GSF_stats, |
1455 | gettext_noop ( | 1458 | gettext_noop( |
1456 | "# Datastore lookups concluded (error queueing)"), | 1459 | "# Datastore lookups concluded (error queueing)"), |
1457 | 1, | 1460 | 1, |
1458 | GNUNET_NO); | 1461 | GNUNET_NO); |
1459 | call_continuation (pr); | 1462 | call_continuation(pr); |
1460 | } | 1463 | } |
1461 | 1464 | ||
1462 | 1465 | ||
@@ -1479,178 +1482,178 @@ start_local_query (struct GSF_PendingRequest *pr, | |||
1479 | * maybe 0 if no unique identifier is available | 1482 | * maybe 0 if no unique identifier is available |
1480 | */ | 1483 | */ |
1481 | static void | 1484 | static void |
1482 | process_local_reply (void *cls, | 1485 | process_local_reply(void *cls, |
1483 | const struct GNUNET_HashCode *key, | 1486 | const struct GNUNET_HashCode *key, |
1484 | size_t size, | 1487 | size_t size, |
1485 | const void *data, | 1488 | const void *data, |
1486 | enum GNUNET_BLOCK_Type type, | 1489 | enum GNUNET_BLOCK_Type type, |
1487 | uint32_t priority, | 1490 | uint32_t priority, |
1488 | uint32_t anonymity, | 1491 | uint32_t anonymity, |
1489 | uint32_t replication, | 1492 | uint32_t replication, |
1490 | struct GNUNET_TIME_Absolute expiration, | 1493 | struct GNUNET_TIME_Absolute expiration, |
1491 | uint64_t uid) | 1494 | uint64_t uid) |
1492 | { | 1495 | { |
1493 | struct GSF_PendingRequest *pr = cls; | 1496 | struct GSF_PendingRequest *pr = cls; |
1494 | struct ProcessReplyClosure prq; | 1497 | struct ProcessReplyClosure prq; |
1495 | struct GNUNET_HashCode query; | 1498 | struct GNUNET_HashCode query; |
1496 | unsigned int old_rf; | 1499 | unsigned int old_rf; |
1497 | 1500 | ||
1498 | GNUNET_SCHEDULER_cancel (pr->warn_task); | 1501 | GNUNET_SCHEDULER_cancel(pr->warn_task); |
1499 | pr->warn_task = NULL; | 1502 | pr->warn_task = NULL; |
1500 | if (NULL == pr->qe) | 1503 | if (NULL == pr->qe) |
1501 | goto called_from_on_demand; | 1504 | goto called_from_on_demand; |
1502 | pr->qe = NULL; | 1505 | pr->qe = NULL; |
1503 | if ( | 1506 | if ( |
1504 | (NULL == key) && pr->seen_null && | 1507 | (NULL == key) && pr->seen_null && |
1505 | ! pr->have_first_uid) /* We have hit the end for the 2nd time with no results */ | 1508 | !pr->have_first_uid) /* We have hit the end for the 2nd time with no results */ |
1506 | { | 1509 | { |
1507 | /* No results */ | 1510 | /* No results */ |
1508 | #if INSANE_STATISTICS | 1511 | #if INSANE_STATISTICS |
1509 | GNUNET_STATISTICS_update (GSF_stats, | 1512 | GNUNET_STATISTICS_update(GSF_stats, |
1510 | gettext_noop ( | 1513 | gettext_noop( |
1511 | "# Datastore lookups concluded (no results)"), | 1514 | "# Datastore lookups concluded (no results)"), |
1512 | 1, | 1515 | 1, |
1513 | GNUNET_NO); | 1516 | GNUNET_NO); |
1514 | #endif | 1517 | #endif |
1515 | no_more_local_results (pr); | 1518 | no_more_local_results(pr); |
1516 | return; | 1519 | return; |
1517 | } | 1520 | } |
1518 | if (((NULL == key) && | 1521 | if (((NULL == key) && |
1519 | pr->seen_null) || /* We have hit the end for the 2nd time OR */ | 1522 | pr->seen_null) || /* We have hit the end for the 2nd time OR */ |
1520 | (pr->seen_null && pr->have_first_uid && | 1523 | (pr->seen_null && pr->have_first_uid && |
1521 | (uid >= pr->first_uid))) /* We have hit the end and past first UID */ | 1524 | (uid >= pr->first_uid))) /* We have hit the end and past first UID */ |
1522 | { | 1525 | { |
1523 | /* Seen all results */ | 1526 | /* Seen all results */ |
1524 | GNUNET_STATISTICS_update (GSF_stats, | 1527 | GNUNET_STATISTICS_update(GSF_stats, |
1525 | gettext_noop ( | 1528 | gettext_noop( |
1526 | "# Datastore lookups concluded (seen all)"), | 1529 | "# Datastore lookups concluded (seen all)"), |
1527 | 1, | 1530 | 1, |
1528 | GNUNET_NO); | 1531 | GNUNET_NO); |
1529 | no_more_local_results (pr); | 1532 | no_more_local_results(pr); |
1530 | return; | 1533 | return; |
1531 | } | 1534 | } |
1532 | if (NULL == key) | 1535 | if (NULL == key) |
1533 | { | 1536 | { |
1534 | GNUNET_assert (! pr->seen_null); | 1537 | GNUNET_assert(!pr->seen_null); |
1535 | pr->seen_null = true; | 1538 | pr->seen_null = true; |
1536 | start_local_query (pr, 0 /* next_uid */, false /* random */); | 1539 | start_local_query(pr, 0 /* next_uid */, false /* random */); |
1537 | return; | 1540 | return; |
1538 | } | 1541 | } |
1539 | if (! pr->have_first_uid) | 1542 | if (!pr->have_first_uid) |
1540 | { | 1543 | { |
1541 | pr->first_uid = uid; | 1544 | pr->first_uid = uid; |
1542 | pr->have_first_uid = true; | 1545 | pr->have_first_uid = true; |
1543 | } | 1546 | } |
1544 | pr->result_count++; | 1547 | pr->result_count++; |
1545 | if (pr->result_count > MAX_RESULTS) | 1548 | if (pr->result_count > MAX_RESULTS) |
1546 | { | 1549 | { |
1547 | GNUNET_STATISTICS_update ( | 1550 | GNUNET_STATISTICS_update( |
1548 | GSF_stats, | 1551 | GSF_stats, |
1549 | gettext_noop ("# Datastore lookups aborted (more than MAX_RESULTS)"), | 1552 | gettext_noop("# Datastore lookups aborted (more than MAX_RESULTS)"), |
1550 | 1, | 1553 | 1, |
1551 | GNUNET_NO); | 1554 | GNUNET_NO); |
1552 | no_more_local_results (pr); | 1555 | no_more_local_results(pr); |
1553 | return; | 1556 | return; |
1554 | } | 1557 | } |
1555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1558 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1556 | "Received reply for `%s' of type %d with UID %llu from datastore.\n", | 1559 | "Received reply for `%s' of type %d with UID %llu from datastore.\n", |
1557 | GNUNET_h2s (key), | 1560 | GNUNET_h2s(key), |
1558 | type, | 1561 | type, |
1559 | (unsigned long long) uid); | 1562 | (unsigned long long)uid); |
1560 | if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) | 1563 | if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) |
1561 | { | ||
1562 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1563 | "Found ONDEMAND block, performing on-demand encoding\n"); | ||
1564 | GNUNET_STATISTICS_update (GSF_stats, | ||
1565 | gettext_noop ( | ||
1566 | "# on-demand blocks matched requests"), | ||
1567 | 1, | ||
1568 | GNUNET_NO); | ||
1569 | pr->qe_start = GNUNET_TIME_absolute_get (); | ||
1570 | pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | ||
1571 | &odc_warn_delay_task, | ||
1572 | pr); | ||
1573 | if (GNUNET_OK == GNUNET_FS_handle_on_demand_block (key, | ||
1574 | size, | ||
1575 | data, | ||
1576 | type, | ||
1577 | priority, | ||
1578 | anonymity, | ||
1579 | replication, | ||
1580 | expiration, | ||
1581 | uid, | ||
1582 | &process_local_reply, | ||
1583 | pr)) | ||
1584 | { | 1564 | { |
1585 | GNUNET_STATISTICS_update (GSF_stats, | 1565 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1586 | gettext_noop ( | 1566 | "Found ONDEMAND block, performing on-demand encoding\n"); |
1587 | "# on-demand lookups performed successfully"), | 1567 | GNUNET_STATISTICS_update(GSF_stats, |
1588 | 1, | 1568 | gettext_noop( |
1589 | GNUNET_NO); | 1569 | "# on-demand blocks matched requests"), |
1590 | return; /* we're done */ | 1570 | 1, |
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; | ||
1591 | } | 1602 | } |
1592 | GNUNET_STATISTICS_update (GSF_stats, | ||
1593 | gettext_noop ("# on-demand lookups failed"), | ||
1594 | 1, | ||
1595 | GNUNET_NO); | ||
1596 | GNUNET_SCHEDULER_cancel (pr->warn_task); | ||
1597 | start_local_query (pr, uid + 1 /* next_uid */, false /* random */); | ||
1598 | return; | ||
1599 | } | ||
1600 | called_from_on_demand: | 1603 | called_from_on_demand: |
1601 | old_rf = pr->public_data.results_found; | 1604 | old_rf = pr->public_data.results_found; |
1602 | memset (&prq, 0, sizeof (prq)); | 1605 | memset(&prq, 0, sizeof(prq)); |
1603 | prq.data = data; | 1606 | prq.data = data; |
1604 | prq.expiration = expiration; | 1607 | prq.expiration = expiration; |
1605 | prq.size = size; | 1608 | prq.size = size; |
1606 | if (GNUNET_OK != | 1609 | if (GNUNET_OK != |
1607 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, size, &query)) | 1610 | GNUNET_BLOCK_get_key(GSF_block_ctx, type, data, size, &query)) |
1608 | { | 1611 | { |
1609 | GNUNET_break (0); | 1612 | GNUNET_break(0); |
1610 | GNUNET_DATASTORE_remove (GSF_dsh, | 1613 | GNUNET_DATASTORE_remove(GSF_dsh, |
1611 | key, | 1614 | key, |
1612 | size, | 1615 | size, |
1613 | data, | 1616 | data, |
1614 | UINT_MAX, | 1617 | UINT_MAX, |
1615 | UINT_MAX, | 1618 | UINT_MAX, |
1616 | NULL, | 1619 | NULL, |
1617 | NULL); | 1620 | NULL); |
1618 | start_local_query (pr, uid + 1 /* next_uid */, false /* random */); | 1621 | start_local_query(pr, uid + 1 /* next_uid */, false /* random */); |
1619 | return; | 1622 | return; |
1620 | } | 1623 | } |
1621 | prq.type = type; | 1624 | prq.type = type; |
1622 | prq.priority = priority; | 1625 | prq.priority = priority; |
1623 | prq.request_found = GNUNET_NO; | 1626 | prq.request_found = GNUNET_NO; |
1624 | prq.anonymity_level = anonymity; | 1627 | prq.anonymity_level = anonymity; |
1625 | if ((0 == old_rf) && (0 == pr->public_data.results_found)) | 1628 | if ((0 == old_rf) && (0 == pr->public_data.results_found)) |
1626 | GSF_update_datastore_delay_ (pr->public_data.start_time); | 1629 | GSF_update_datastore_delay_(pr->public_data.start_time); |
1627 | prq.eo = GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO; | 1630 | prq.eo = GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO; |
1628 | process_reply (&prq, key, pr); | 1631 | process_reply(&prq, key, pr); |
1629 | pr->local_result = prq.eval; | 1632 | pr->local_result = prq.eval; |
1630 | if (GNUNET_BLOCK_EVALUATION_OK_LAST == prq.eval) | 1633 | if (GNUNET_BLOCK_EVALUATION_OK_LAST == prq.eval) |
1631 | { | 1634 | { |
1632 | GNUNET_STATISTICS_update ( | 1635 | GNUNET_STATISTICS_update( |
1633 | GSF_stats, | 1636 | GSF_stats, |
1634 | gettext_noop ("# Datastore lookups concluded (found last result)"), | 1637 | gettext_noop("# Datastore lookups concluded (found last result)"), |
1635 | 1, | 1638 | 1, |
1636 | GNUNET_NO); | 1639 | GNUNET_NO); |
1637 | call_continuation (pr); | 1640 | call_continuation(pr); |
1638 | return; | 1641 | return; |
1639 | } | 1642 | } |
1640 | if ((0 == (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) && | 1643 | if ((0 == (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) && |
1641 | ((GNUNET_YES == GSF_test_get_load_too_high_ (0)) || | 1644 | ((GNUNET_YES == GSF_test_get_load_too_high_(0)) || |
1642 | (pr->public_data.results_found > 5 + 2 * pr->public_data.priority))) | 1645 | (pr->public_data.results_found > 5 + 2 * pr->public_data.priority))) |
1643 | { | 1646 | { |
1644 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Load too high, done with request\n"); | 1647 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Load too high, done with request\n"); |
1645 | GNUNET_STATISTICS_update (GSF_stats, | 1648 | GNUNET_STATISTICS_update(GSF_stats, |
1646 | gettext_noop ( | 1649 | gettext_noop( |
1647 | "# Datastore lookups concluded (load too high)"), | 1650 | "# Datastore lookups concluded (load too high)"), |
1648 | 1, | 1651 | 1, |
1649 | GNUNET_NO); | 1652 | GNUNET_NO); |
1650 | call_continuation (pr); | 1653 | call_continuation(pr); |
1651 | return; | 1654 | return; |
1652 | } | 1655 | } |
1653 | start_local_query (pr, uid + 1 /* next_uid */, false /* random */); | 1656 | start_local_query(pr, uid + 1 /* next_uid */, false /* random */); |
1654 | } | 1657 | } |
1655 | 1658 | ||
1656 | 1659 | ||
@@ -1662,17 +1665,17 @@ called_from_on_demand: | |||
1662 | * @return #GNUNET_YES if this request could be forwarded to the given peer | 1665 | * @return #GNUNET_YES if this request could be forwarded to the given peer |
1663 | */ | 1666 | */ |
1664 | int | 1667 | int |
1665 | GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, | 1668 | GSF_pending_request_test_target_(struct GSF_PendingRequest *pr, |
1666 | const struct GNUNET_PeerIdentity *target) | 1669 | const struct GNUNET_PeerIdentity *target) |
1667 | { | 1670 | { |
1668 | struct GNUNET_PeerIdentity pi; | 1671 | struct GNUNET_PeerIdentity pi; |
1669 | 1672 | ||
1670 | if (0 == pr->origin_pid) | 1673 | if (0 == pr->origin_pid) |
1671 | return GNUNET_YES; | 1674 | return GNUNET_YES; |
1672 | GNUNET_PEER_resolve (pr->origin_pid, &pi); | 1675 | GNUNET_PEER_resolve(pr->origin_pid, &pi); |
1673 | return (0 == memcmp (&pi, target, sizeof (struct GNUNET_PeerIdentity))) | 1676 | return (0 == memcmp(&pi, target, sizeof(struct GNUNET_PeerIdentity))) |
1674 | ? GNUNET_NO | 1677 | ? GNUNET_NO |
1675 | : GNUNET_YES; | 1678 | : GNUNET_YES; |
1676 | } | 1679 | } |
1677 | 1680 | ||
1678 | 1681 | ||
@@ -1684,22 +1687,22 @@ GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, | |||
1684 | * @param cont_cls closure for @a cont | 1687 | * @param cont_cls closure for @a cont |
1685 | */ | 1688 | */ |
1686 | void | 1689 | void |
1687 | GSF_local_lookup_ (struct GSF_PendingRequest *pr, | 1690 | GSF_local_lookup_(struct GSF_PendingRequest *pr, |
1688 | GSF_LocalLookupContinuation cont, | 1691 | GSF_LocalLookupContinuation cont, |
1689 | void *cont_cls) | 1692 | void *cont_cls) |
1690 | { | 1693 | { |
1691 | GNUNET_assert (NULL == pr->gh); | 1694 | GNUNET_assert(NULL == pr->gh); |
1692 | GNUNET_assert (NULL == pr->cadet_request); | 1695 | GNUNET_assert(NULL == pr->cadet_request); |
1693 | GNUNET_assert (NULL == pr->llc_cont); | 1696 | GNUNET_assert(NULL == pr->llc_cont); |
1694 | pr->llc_cont = cont; | 1697 | pr->llc_cont = cont; |
1695 | pr->llc_cont_cls = cont_cls; | 1698 | pr->llc_cont_cls = cont_cls; |
1696 | #if INSANE_STATISTICS | 1699 | #if INSANE_STATISTICS |
1697 | GNUNET_STATISTICS_update (GSF_stats, | 1700 | GNUNET_STATISTICS_update(GSF_stats, |
1698 | gettext_noop ("# Datastore lookups initiated"), | 1701 | gettext_noop("# Datastore lookups initiated"), |
1699 | 1, | 1702 | 1, |
1700 | GNUNET_NO); | 1703 | GNUNET_NO); |
1701 | #endif | 1704 | #endif |
1702 | start_local_query (pr, 0 /* next_uid */, true /* random */); | 1705 | start_local_query(pr, 0 /* next_uid */, true /* random */); |
1703 | } | 1706 | } |
1704 | 1707 | ||
1705 | 1708 | ||
@@ -1713,7 +1716,7 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr, | |||
1713 | * @param put the actual message | 1716 | * @param put the actual message |
1714 | */ | 1717 | */ |
1715 | void | 1718 | void |
1716 | handle_p2p_put (void *cls, const struct PutMessage *put) | 1719 | handle_p2p_put(void *cls, const struct PutMessage *put) |
1717 | { | 1720 | { |
1718 | struct GSF_ConnectedPeer *cp = cls; | 1721 | struct GSF_ConnectedPeer *cp = cls; |
1719 | uint16_t msize; | 1722 | uint16_t msize; |
@@ -1726,30 +1729,30 @@ handle_p2p_put (void *cls, const struct PutMessage *put) | |||
1726 | double putl; | 1729 | double putl; |
1727 | struct PutMigrationContext *pmc; | 1730 | struct PutMigrationContext *pmc; |
1728 | 1731 | ||
1729 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1732 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1730 | "Received P2P PUT from %s\n", | 1733 | "Received P2P PUT from %s\n", |
1731 | GNUNET_i2s (GSF_get_peer_performance_data_ (cp)->peer)); | 1734 | GNUNET_i2s(GSF_get_peer_performance_data_(cp)->peer)); |
1732 | GSF_cover_content_count++; | 1735 | GSF_cover_content_count++; |
1733 | msize = ntohs (put->header.size); | 1736 | msize = ntohs(put->header.size); |
1734 | dsize = msize - sizeof (struct PutMessage); | 1737 | dsize = msize - sizeof(struct PutMessage); |
1735 | type = ntohl (put->type); | 1738 | type = ntohl(put->type); |
1736 | expiration = GNUNET_TIME_absolute_ntoh (put->expiration); | 1739 | expiration = GNUNET_TIME_absolute_ntoh(put->expiration); |
1737 | /* do not allow migrated content to live longer than 1 year */ | 1740 | /* do not allow migrated content to live longer than 1 year */ |
1738 | expiration = GNUNET_TIME_absolute_min (GNUNET_TIME_relative_to_absolute ( | 1741 | expiration = GNUNET_TIME_absolute_min(GNUNET_TIME_relative_to_absolute( |
1739 | GNUNET_TIME_UNIT_YEARS), | 1742 | GNUNET_TIME_UNIT_YEARS), |
1740 | expiration); | 1743 | expiration); |
1741 | if (GNUNET_OK != | 1744 | if (GNUNET_OK != |
1742 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, &put[1], dsize, &query)) | 1745 | GNUNET_BLOCK_get_key(GSF_block_ctx, type, &put[1], dsize, &query)) |
1743 | { | 1746 | { |
1744 | GNUNET_break_op (0); | 1747 | GNUNET_break_op(0); |
1745 | return; | 1748 | return; |
1746 | } | 1749 | } |
1747 | GNUNET_STATISTICS_update (GSF_stats, | 1750 | GNUNET_STATISTICS_update(GSF_stats, |
1748 | gettext_noop ("# GAP PUT messages received"), | 1751 | gettext_noop("# GAP PUT messages received"), |
1749 | 1, | 1752 | 1, |
1750 | GNUNET_NO); | 1753 | GNUNET_NO); |
1751 | /* now, lookup 'query' */ | 1754 | /* now, lookup 'query' */ |
1752 | prq.data = (const void *) &put[1]; | 1755 | prq.data = (const void *)&put[1]; |
1753 | prq.sender = cp; | 1756 | prq.sender = cp; |
1754 | prq.size = dsize; | 1757 | prq.size = dsize; |
1755 | prq.type = type; | 1758 | prq.type = type; |
@@ -1758,80 +1761,80 @@ handle_p2p_put (void *cls, const struct PutMessage *put) | |||
1758 | prq.anonymity_level = UINT32_MAX; | 1761 | prq.anonymity_level = UINT32_MAX; |
1759 | prq.request_found = GNUNET_NO; | 1762 | prq.request_found = GNUNET_NO; |
1760 | prq.eo = GNUNET_BLOCK_EO_NONE; | 1763 | prq.eo = GNUNET_BLOCK_EO_NONE; |
1761 | GNUNET_CONTAINER_multihashmap_get_multiple (pr_map, | 1764 | GNUNET_CONTAINER_multihashmap_get_multiple(pr_map, |
1762 | &query, | 1765 | &query, |
1763 | &process_reply, | 1766 | &process_reply, |
1764 | &prq); | 1767 | &prq); |
1765 | if (NULL != cp) | 1768 | if (NULL != cp) |
1766 | { | 1769 | { |
1767 | GSF_connected_peer_change_preference_ (cp, | 1770 | GSF_connected_peer_change_preference_(cp, |
1768 | CONTENT_BANDWIDTH_VALUE + | 1771 | CONTENT_BANDWIDTH_VALUE + |
1769 | 1000 * prq.priority); | 1772 | 1000 * prq.priority); |
1770 | GSF_get_peer_performance_data_ (cp)->respect += prq.priority; | 1773 | GSF_get_peer_performance_data_(cp)->respect += prq.priority; |
1771 | } | 1774 | } |
1772 | if ((GNUNET_YES == active_to_migration) && (NULL != cp) && | 1775 | if ((GNUNET_YES == active_to_migration) && (NULL != cp) && |
1773 | (GNUNET_NO == test_put_load_too_high (prq.priority))) | 1776 | (GNUNET_NO == test_put_load_too_high(prq.priority))) |
1774 | { | ||
1775 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1776 | "Replicating result for query `%s' with priority %u\n", | ||
1777 | GNUNET_h2s (&query), | ||
1778 | prq.priority); | ||
1779 | pmc = GNUNET_new (struct PutMigrationContext); | ||
1780 | pmc->start = GNUNET_TIME_absolute_get (); | ||
1781 | pmc->requested = prq.request_found; | ||
1782 | GNUNET_assert (0 != GSF_get_peer_performance_data_ (cp)->pid); | ||
1783 | GNUNET_PEER_resolve (GSF_get_peer_performance_data_ (cp)->pid, | ||
1784 | &pmc->origin); | ||
1785 | if (NULL == GNUNET_DATASTORE_put (GSF_dsh, | ||
1786 | 0, | ||
1787 | &query, | ||
1788 | dsize, | ||
1789 | &put[1], | ||
1790 | type, | ||
1791 | prq.priority, | ||
1792 | 1 /* anonymity */, | ||
1793 | 0 /* replication */, | ||
1794 | expiration, | ||
1795 | 1 + prq.priority, | ||
1796 | MAX_DATASTORE_QUEUE, | ||
1797 | &put_migration_continuation, | ||
1798 | pmc)) | ||
1799 | { | 1777 | { |
1800 | put_migration_continuation (pmc, | 1778 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1801 | GNUNET_SYSERR, | 1779 | "Replicating result for query `%s' with priority %u\n", |
1802 | GNUNET_TIME_UNIT_ZERO_ABS, | 1780 | GNUNET_h2s(&query), |
1803 | NULL); | 1781 | prq.priority); |
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 | } | ||
1804 | } | 1808 | } |
1805 | } | ||
1806 | else if (NULL != cp) | 1809 | else if (NULL != cp) |
1807 | { | 1810 | { |
1808 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1811 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1809 | "Choosing not to keep content `%s' (%d/%d)\n", | 1812 | "Choosing not to keep content `%s' (%d/%d)\n", |
1810 | GNUNET_h2s (&query), | 1813 | GNUNET_h2s(&query), |
1811 | active_to_migration, | 1814 | active_to_migration, |
1812 | test_put_load_too_high (prq.priority)); | 1815 | test_put_load_too_high(prq.priority)); |
1813 | } | 1816 | } |
1814 | putl = GNUNET_LOAD_get_load (datastore_put_load); | 1817 | putl = GNUNET_LOAD_get_load(datastore_put_load); |
1815 | if ((NULL != cp) && (GNUNET_NO == prq.request_found) && | 1818 | if ((NULL != cp) && (GNUNET_NO == prq.request_found) && |
1816 | ((GNUNET_YES != active_to_migration) || | 1819 | ((GNUNET_YES != active_to_migration) || |
1817 | (putl > 2.5 * (1 + prq.priority)))) | 1820 | (putl > 2.5 * (1 + prq.priority)))) |
1818 | { | 1821 | { |
1819 | if (GNUNET_YES != active_to_migration) | 1822 | if (GNUNET_YES != active_to_migration) |
1820 | putl = 1.0 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5); | 1823 | putl = 1.0 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 5); |
1821 | block_time = GNUNET_TIME_relative_multiply ( | 1824 | block_time = GNUNET_TIME_relative_multiply( |
1822 | GNUNET_TIME_UNIT_MILLISECONDS, | 1825 | GNUNET_TIME_UNIT_MILLISECONDS, |
1823 | 5000 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1826 | 5000 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
1824 | (unsigned int) (60000 * putl * putl))); | 1827 | (unsigned int)(60000 * putl * putl))); |
1825 | GNUNET_log ( | 1828 | GNUNET_log( |
1826 | GNUNET_ERROR_TYPE_DEBUG, | 1829 | GNUNET_ERROR_TYPE_DEBUG, |
1827 | "Asking to stop migration for %s because of load %f and events %d/%d\n", | 1830 | "Asking to stop migration for %s because of load %f and events %d/%d\n", |
1828 | GNUNET_STRINGS_relative_time_to_string (block_time, GNUNET_YES), | 1831 | GNUNET_STRINGS_relative_time_to_string(block_time, GNUNET_YES), |
1829 | putl, | 1832 | putl, |
1830 | active_to_migration, | 1833 | active_to_migration, |
1831 | (GNUNET_NO == prq.request_found)); | 1834 | (GNUNET_NO == prq.request_found)); |
1832 | GSF_block_peer_migration_ (cp, | 1835 | GSF_block_peer_migration_(cp, |
1833 | GNUNET_TIME_relative_to_absolute (block_time)); | 1836 | GNUNET_TIME_relative_to_absolute(block_time)); |
1834 | } | 1837 | } |
1835 | } | 1838 | } |
1836 | 1839 | ||
1837 | 1840 | ||
@@ -1842,7 +1845,7 @@ handle_p2p_put (void *cls, const struct PutMessage *put) | |||
1842 | * @return #GNUNET_YES if the request is still active | 1845 | * @return #GNUNET_YES if the request is still active |
1843 | */ | 1846 | */ |
1844 | int | 1847 | int |
1845 | GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr) | 1848 | GSF_pending_request_test_active_(struct GSF_PendingRequest *pr) |
1846 | { | 1849 | { |
1847 | return (NULL != pr->rh) ? GNUNET_YES : GNUNET_NO; | 1850 | return (NULL != pr->rh) ? GNUNET_YES : GNUNET_NO; |
1848 | } | 1851 | } |
@@ -1852,24 +1855,24 @@ GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr) | |||
1852 | * Setup the subsystem. | 1855 | * Setup the subsystem. |
1853 | */ | 1856 | */ |
1854 | void | 1857 | void |
1855 | GSF_pending_request_init_ () | 1858 | GSF_pending_request_init_() |
1856 | { | 1859 | { |
1857 | if (GNUNET_OK != | 1860 | if (GNUNET_OK != |
1858 | GNUNET_CONFIGURATION_get_value_number (GSF_cfg, | 1861 | GNUNET_CONFIGURATION_get_value_number(GSF_cfg, |
1859 | "fs", | 1862 | "fs", |
1860 | "MAX_PENDING_REQUESTS", | 1863 | "MAX_PENDING_REQUESTS", |
1861 | &max_pending_requests)) | 1864 | &max_pending_requests)) |
1862 | { | 1865 | { |
1863 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO, | 1866 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_INFO, |
1864 | "fs", | 1867 | "fs", |
1865 | "MAX_PENDING_REQUESTS"); | 1868 | "MAX_PENDING_REQUESTS"); |
1866 | } | 1869 | } |
1867 | active_to_migration = | 1870 | active_to_migration = |
1868 | GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_CACHING"); | 1871 | GNUNET_CONFIGURATION_get_value_yesno(GSF_cfg, "FS", "CONTENT_CACHING"); |
1869 | datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); | 1872 | datastore_put_load = GNUNET_LOAD_value_init(DATASTORE_LOAD_AUTODECLINE); |
1870 | pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024, GNUNET_YES); | 1873 | pr_map = GNUNET_CONTAINER_multihashmap_create(32 * 1024, GNUNET_YES); |
1871 | requests_by_expiration_heap = | 1874 | requests_by_expiration_heap = |
1872 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1875 | GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1873 | } | 1876 | } |
1874 | 1877 | ||
1875 | 1878 | ||
@@ -1877,14 +1880,14 @@ GSF_pending_request_init_ () | |||
1877 | * Shutdown the subsystem. | 1880 | * Shutdown the subsystem. |
1878 | */ | 1881 | */ |
1879 | void | 1882 | void |
1880 | GSF_pending_request_done_ () | 1883 | GSF_pending_request_done_() |
1881 | { | 1884 | { |
1882 | GNUNET_CONTAINER_multihashmap_iterate (pr_map, &clean_request, NULL); | 1885 | GNUNET_CONTAINER_multihashmap_iterate(pr_map, &clean_request, NULL); |
1883 | GNUNET_CONTAINER_multihashmap_destroy (pr_map); | 1886 | GNUNET_CONTAINER_multihashmap_destroy(pr_map); |
1884 | pr_map = NULL; | 1887 | pr_map = NULL; |
1885 | GNUNET_CONTAINER_heap_destroy (requests_by_expiration_heap); | 1888 | GNUNET_CONTAINER_heap_destroy(requests_by_expiration_heap); |
1886 | requests_by_expiration_heap = NULL; | 1889 | requests_by_expiration_heap = NULL; |
1887 | GNUNET_LOAD_value_free (datastore_put_load); | 1890 | GNUNET_LOAD_value_free(datastore_put_load); |
1888 | datastore_put_load = NULL; | 1891 | datastore_put_load = NULL; |
1889 | } | 1892 | } |
1890 | 1893 | ||
diff --git a/src/fs/gnunet-service-fs_pr.h b/src/fs/gnunet-service-fs_pr.h index abdb0c9f6..39e471c4d 100644 --- a/src/fs/gnunet-service-fs_pr.h +++ b/src/fs/gnunet-service-fs_pr.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_pr.h | 22 | * @file fs/gnunet-service-fs_pr.h |
@@ -32,9 +32,7 @@ | |||
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 | { | ||
37 | |||
38 | /** | 36 | /** |
39 | * No special options (P2P-default). | 37 | * No special options (P2P-default). |
40 | */ | 38 | */ |
@@ -69,7 +67,7 @@ enum GSF_PendingRequestOptions | |||
69 | * Option mask for typical local requests. | 67 | * Option mask for typical local requests. |
70 | */ | 68 | */ |
71 | GSF_PRO_LOCAL_REQUEST = | 69 | GSF_PRO_LOCAL_REQUEST = |
72 | (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED | GSF_PRO_REQUEST_NEVER_EXPIRES) | 70 | (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED | GSF_PRO_REQUEST_NEVER_EXPIRES) |
73 | }; | 71 | }; |
74 | 72 | ||
75 | 73 | ||
@@ -78,9 +76,7 @@ enum GSF_PendingRequestOptions | |||
78 | * 'gnunet-service-fs_pr', not in the sense of network-wide | 76 | * 'gnunet-service-fs_pr', not in the sense of network-wide |
79 | * known) associated with each pending request. | 77 | * known) associated with each pending request. |
80 | */ | 78 | */ |
81 | struct GSF_PendingRequestData | 79 | struct GSF_PendingRequestData { |
82 | { | ||
83 | |||
84 | /** | 80 | /** |
85 | * Primary query hash for this request. | 81 | * Primary query hash for this request. |
86 | */ | 82 | */ |
@@ -163,7 +159,6 @@ struct GSF_PendingRequestData | |||
163 | * we still constructing it? | 159 | * we still constructing it? |
164 | */ | 160 | */ |
165 | int has_started; | 161 | int has_started; |
166 | |||
167 | }; | 162 | }; |
168 | 163 | ||
169 | 164 | ||
@@ -220,22 +215,22 @@ typedef void | |||
220 | * @return handle for the new pending request | 215 | * @return handle for the new pending request |
221 | */ | 216 | */ |
222 | struct GSF_PendingRequest * | 217 | struct GSF_PendingRequest * |
223 | GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, | 218 | GSF_pending_request_create_(enum GSF_PendingRequestOptions options, |
224 | enum GNUNET_BLOCK_Type type, | 219 | enum GNUNET_BLOCK_Type type, |
225 | const struct GNUNET_HashCode *query, | 220 | const struct GNUNET_HashCode *query, |
226 | const struct GNUNET_PeerIdentity *target, | 221 | const struct GNUNET_PeerIdentity *target, |
227 | const char *bf_data, | 222 | const char *bf_data, |
228 | size_t bf_size, | 223 | size_t bf_size, |
229 | uint32_t mingle, | 224 | uint32_t mingle, |
230 | uint32_t anonymity_level, | 225 | uint32_t anonymity_level, |
231 | uint32_t priority, | 226 | uint32_t priority, |
232 | int32_t ttl, | 227 | int32_t ttl, |
233 | GNUNET_PEER_Id sender_pid, | 228 | GNUNET_PEER_Id sender_pid, |
234 | GNUNET_PEER_Id origin_pid, | 229 | GNUNET_PEER_Id origin_pid, |
235 | const struct GNUNET_HashCode *replies_seen, | 230 | const struct GNUNET_HashCode *replies_seen, |
236 | unsigned int replies_seen_count, | 231 | unsigned int replies_seen_count, |
237 | GSF_PendingRequestReplyHandler rh, | 232 | GSF_PendingRequestReplyHandler rh, |
238 | void *rh_cls); | 233 | void *rh_cls); |
239 | 234 | ||
240 | 235 | ||
241 | /** | 236 | /** |
@@ -247,9 +242,9 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, | |||
247 | * @param replies_seen_count size of the @a replies_seen array | 242 | * @param replies_seen_count size of the @a replies_seen array |
248 | */ | 243 | */ |
249 | void | 244 | void |
250 | GSF_pending_request_update_ (struct GSF_PendingRequest *pr, | 245 | GSF_pending_request_update_(struct GSF_PendingRequest *pr, |
251 | const struct GNUNET_HashCode *replies_seen, | 246 | const struct GNUNET_HashCode *replies_seen, |
252 | unsigned int replies_seen_count); | 247 | unsigned int replies_seen_count); |
253 | 248 | ||
254 | 249 | ||
255 | /** | 250 | /** |
@@ -259,7 +254,7 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr, | |||
259 | * @return associated public data | 254 | * @return associated public data |
260 | */ | 255 | */ |
261 | struct GSF_PendingRequestData * | 256 | struct GSF_PendingRequestData * |
262 | GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr); | 257 | GSF_pending_request_get_data_(struct GSF_PendingRequest *pr); |
263 | 258 | ||
264 | 259 | ||
265 | /** | 260 | /** |
@@ -269,7 +264,7 @@ GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr); | |||
269 | * @return #GNUNET_YES if the request is still active | 264 | * @return #GNUNET_YES if the request is still active |
270 | */ | 265 | */ |
271 | int | 266 | int |
272 | GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr); | 267 | GSF_pending_request_test_active_(struct GSF_PendingRequest *pr); |
273 | 268 | ||
274 | 269 | ||
275 | /** | 270 | /** |
@@ -282,8 +277,8 @@ GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr); | |||
282 | * @return #GNUNET_OK if the requests are compatible | 277 | * @return #GNUNET_OK if the requests are compatible |
283 | */ | 278 | */ |
284 | int | 279 | int |
285 | GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, | 280 | GSF_pending_request_is_compatible_(struct GSF_PendingRequest *pra, |
286 | struct GSF_PendingRequest *prb); | 281 | struct GSF_PendingRequest *prb); |
287 | 282 | ||
288 | 283 | ||
289 | /** | 284 | /** |
@@ -294,7 +289,7 @@ GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, | |||
294 | * @return envelope with the request message | 289 | * @return envelope with the request message |
295 | */ | 290 | */ |
296 | struct GNUNET_MQ_Envelope * | 291 | struct GNUNET_MQ_Envelope * |
297 | GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr); | 292 | GSF_pending_request_get_message_(struct GSF_PendingRequest *pr); |
298 | 293 | ||
299 | 294 | ||
300 | /** | 295 | /** |
@@ -304,8 +299,8 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr); | |||
304 | * @param full_cleanup fully purge the request | 299 | * @param full_cleanup fully purge the request |
305 | */ | 300 | */ |
306 | void | 301 | void |
307 | GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, | 302 | GSF_pending_request_cancel_(struct GSF_PendingRequest *pr, |
308 | int full_cleanup); | 303 | int full_cleanup); |
309 | 304 | ||
310 | 305 | ||
311 | /** | 306 | /** |
@@ -330,8 +325,8 @@ typedef int | |||
330 | * @param cls closure for it | 325 | * @param cls closure for it |
331 | */ | 326 | */ |
332 | void | 327 | void |
333 | GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, | 328 | GSF_iterate_pending_requests_(GSF_PendingRequestIterator it, |
334 | void *cls); | 329 | void *cls); |
335 | 330 | ||
336 | 331 | ||
337 | /** | 332 | /** |
@@ -344,8 +339,8 @@ GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, | |||
344 | * @param put the actual message | 339 | * @param put the actual message |
345 | */ | 340 | */ |
346 | void | 341 | void |
347 | handle_p2p_put (void *cls, | 342 | handle_p2p_put(void *cls, |
348 | const struct PutMessage *put); | 343 | const struct PutMessage *put); |
349 | 344 | ||
350 | 345 | ||
351 | /** | 346 | /** |
@@ -354,7 +349,7 @@ handle_p2p_put (void *cls, | |||
354 | * @param pr the pending request to process | 349 | * @param pr the pending request to process |
355 | */ | 350 | */ |
356 | void | 351 | void |
357 | GSF_dht_lookup_ (struct GSF_PendingRequest *pr); | 352 | GSF_dht_lookup_(struct GSF_PendingRequest *pr); |
358 | 353 | ||
359 | 354 | ||
360 | /** | 355 | /** |
@@ -363,7 +358,7 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr); | |||
363 | * @param pr the pending request to process | 358 | * @param pr the pending request to process |
364 | */ | 359 | */ |
365 | void | 360 | void |
366 | GSF_cadet_lookup_ (struct GSF_PendingRequest *pr); | 361 | GSF_cadet_lookup_(struct GSF_PendingRequest *pr); |
367 | 362 | ||
368 | 363 | ||
369 | /** | 364 | /** |
@@ -388,9 +383,9 @@ typedef void | |||
388 | * @param cont_cls closure for @a cont | 383 | * @param cont_cls closure for @a cont |
389 | */ | 384 | */ |
390 | void | 385 | void |
391 | GSF_local_lookup_ (struct GSF_PendingRequest *pr, | 386 | GSF_local_lookup_(struct GSF_PendingRequest *pr, |
392 | GSF_LocalLookupContinuation cont, | 387 | GSF_LocalLookupContinuation cont, |
393 | void *cont_cls); | 388 | void *cont_cls); |
394 | 389 | ||
395 | 390 | ||
396 | /** | 391 | /** |
@@ -401,8 +396,8 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr, | |||
401 | * @return #GNUNET_YES if this request could be forwarded to the given peer | 396 | * @return #GNUNET_YES if this request could be forwarded to the given peer |
402 | */ | 397 | */ |
403 | int | 398 | int |
404 | GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, | 399 | GSF_pending_request_test_target_(struct GSF_PendingRequest *pr, |
405 | const struct GNUNET_PeerIdentity *target); | 400 | const struct GNUNET_PeerIdentity *target); |
406 | 401 | ||
407 | 402 | ||
408 | 403 | ||
@@ -410,14 +405,14 @@ GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, | |||
410 | * Setup the subsystem. | 405 | * Setup the subsystem. |
411 | */ | 406 | */ |
412 | void | 407 | void |
413 | GSF_pending_request_init_ (void); | 408 | GSF_pending_request_init_(void); |
414 | 409 | ||
415 | 410 | ||
416 | /** | 411 | /** |
417 | * Shutdown the subsystem. | 412 | * Shutdown the subsystem. |
418 | */ | 413 | */ |
419 | void | 414 | void |
420 | GSF_pending_request_done_ (void); | 415 | GSF_pending_request_done_(void); |
421 | 416 | ||
422 | 417 | ||
423 | #endif | 418 | #endif |
diff --git a/src/fs/gnunet-service-fs_push.c b/src/fs/gnunet-service-fs_push.c index a75f17f82..162dcc0b5 100644 --- a/src/fs/gnunet-service-fs_push.c +++ b/src/fs/gnunet-service-fs_push.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_push.c | 22 | * @file fs/gnunet-service-fs_push.c |
@@ -49,15 +49,13 @@ | |||
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(GNUNET_TIME_UNIT_MINUTES, 30) |
53 | 53 | ||
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Block that is ready for migration to other peers. Actual data is at the end of the block. | 56 | * Block that is ready for migration to other peers. Actual data is at the end of the block. |
57 | */ | 57 | */ |
58 | struct MigrationReadyBlock | 58 | struct MigrationReadyBlock { |
59 | { | ||
60 | |||
61 | /** | 59 | /** |
62 | * This is a doubly-linked list. | 60 | * This is a doubly-linked list. |
63 | */ | 61 | */ |
@@ -104,8 +102,7 @@ struct MigrationReadyBlock | |||
104 | /** | 102 | /** |
105 | * Information about a peer waiting for migratable data. | 103 | * Information about a peer waiting for migratable data. |
106 | */ | 104 | */ |
107 | struct MigrationReadyPeer | 105 | struct MigrationReadyPeer { |
108 | { | ||
109 | /** | 106 | /** |
110 | * This is a doubly-linked list. | 107 | * This is a doubly-linked list. |
111 | */ | 108 | */ |
@@ -186,15 +183,15 @@ static int value_found; | |||
186 | * @param mb block to delete | 183 | * @param mb block to delete |
187 | */ | 184 | */ |
188 | static void | 185 | static void |
189 | delete_migration_block (struct MigrationReadyBlock *mb) | 186 | delete_migration_block(struct MigrationReadyBlock *mb) |
190 | { | 187 | { |
191 | GNUNET_CONTAINER_DLL_remove (mig_head, | 188 | GNUNET_CONTAINER_DLL_remove(mig_head, |
192 | mig_tail, | 189 | mig_tail, |
193 | mb); | 190 | mb); |
194 | GNUNET_PEER_decrement_rcs (mb->target_list, | 191 | GNUNET_PEER_decrement_rcs(mb->target_list, |
195 | MIGRATION_LIST_SIZE); | 192 | MIGRATION_LIST_SIZE); |
196 | mig_size--; | 193 | mig_size--; |
197 | GNUNET_free (mb); | 194 | GNUNET_free(mb); |
198 | } | 195 | } |
199 | 196 | ||
200 | 197 | ||
@@ -204,7 +201,7 @@ delete_migration_block (struct MigrationReadyBlock *mb) | |||
204 | * @param cls a `struct MigrationReadyPeer *` | 201 | * @param cls a `struct MigrationReadyPeer *` |
205 | */ | 202 | */ |
206 | static void | 203 | static void |
207 | find_content (void *cls); | 204 | find_content(void *cls); |
208 | 205 | ||
209 | 206 | ||
210 | /** | 207 | /** |
@@ -215,50 +212,50 @@ find_content (void *cls); | |||
215 | * @return #GNUNET_YES if the block was deleted (!) | 212 | * @return #GNUNET_YES if the block was deleted (!) |
216 | */ | 213 | */ |
217 | static int | 214 | static int |
218 | transmit_content (struct MigrationReadyPeer *mrp, | 215 | transmit_content(struct MigrationReadyPeer *mrp, |
219 | struct MigrationReadyBlock *block) | 216 | struct MigrationReadyBlock *block) |
220 | { | 217 | { |
221 | struct PutMessage *msg; | 218 | struct PutMessage *msg; |
222 | unsigned int i; | 219 | unsigned int i; |
223 | struct GSF_PeerPerformanceData *ppd; | 220 | struct GSF_PeerPerformanceData *ppd; |
224 | int ret; | 221 | int ret; |
225 | 222 | ||
226 | ppd = GSF_get_peer_performance_data_ (mrp->peer); | 223 | ppd = GSF_get_peer_performance_data_(mrp->peer); |
227 | GNUNET_assert (NULL == mrp->env); | 224 | GNUNET_assert(NULL == mrp->env); |
228 | mrp->env = GNUNET_MQ_msg_extra (msg, | 225 | mrp->env = GNUNET_MQ_msg_extra(msg, |
229 | block->size, | 226 | block->size, |
230 | GNUNET_MESSAGE_TYPE_FS_PUT); | 227 | GNUNET_MESSAGE_TYPE_FS_PUT); |
231 | msg->type = htonl (block->type); | 228 | msg->type = htonl(block->type); |
232 | msg->expiration = GNUNET_TIME_absolute_hton (block->expiration); | 229 | msg->expiration = GNUNET_TIME_absolute_hton(block->expiration); |
233 | GNUNET_memcpy (&msg[1], | 230 | GNUNET_memcpy(&msg[1], |
234 | &block[1], | 231 | &block[1], |
235 | block->size); | 232 | block->size); |
236 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) | 233 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) |
237 | { | ||
238 | if (block->target_list[i] == 0) | ||
239 | { | 234 | { |
240 | block->target_list[i] = ppd->pid; | 235 | if (block->target_list[i] == 0) |
241 | GNUNET_PEER_change_rc (block->target_list[i], | 236 | { |
242 | 1); | 237 | block->target_list[i] = ppd->pid; |
243 | break; | 238 | GNUNET_PEER_change_rc(block->target_list[i], |
239 | 1); | ||
240 | break; | ||
241 | } | ||
244 | } | 242 | } |
245 | } | ||
246 | if (MIGRATION_LIST_SIZE == i) | 243 | if (MIGRATION_LIST_SIZE == i) |
247 | { | 244 | { |
248 | delete_migration_block (block); | 245 | delete_migration_block(block); |
249 | ret = GNUNET_YES; | 246 | ret = GNUNET_YES; |
250 | } | 247 | } |
251 | else | 248 | else |
252 | { | 249 | { |
253 | ret = GNUNET_NO; | 250 | ret = GNUNET_NO; |
254 | } | 251 | } |
255 | GNUNET_MQ_notify_sent (mrp->env, | 252 | GNUNET_MQ_notify_sent(mrp->env, |
256 | &find_content, | 253 | &find_content, |
257 | mrp); | 254 | mrp); |
258 | GSF_peer_transmit_ (mrp->peer, | 255 | GSF_peer_transmit_(mrp->peer, |
259 | GNUNET_NO, | 256 | GNUNET_NO, |
260 | 0 /* priority */ , | 257 | 0 /* priority */, |
261 | mrp->env); | 258 | mrp->env); |
262 | return ret; | 259 | return ret; |
263 | } | 260 | } |
264 | 261 | ||
@@ -271,7 +268,7 @@ transmit_content (struct MigrationReadyPeer *mrp, | |||
271 | * @return number of times block was forwarded | 268 | * @return number of times block was forwarded |
272 | */ | 269 | */ |
273 | static unsigned int | 270 | static unsigned int |
274 | count_targets (struct MigrationReadyBlock *block) | 271 | count_targets(struct MigrationReadyBlock *block) |
275 | { | 272 | { |
276 | unsigned int i; | 273 | unsigned int i; |
277 | 274 | ||
@@ -291,8 +288,8 @@ count_targets (struct MigrationReadyBlock *block) | |||
291 | * @return score (>= 0: feasible, negative: infeasible) | 288 | * @return score (>= 0: feasible, negative: infeasible) |
292 | */ | 289 | */ |
293 | static long | 290 | static long |
294 | score_content (struct MigrationReadyPeer *mrp, | 291 | score_content(struct MigrationReadyPeer *mrp, |
295 | struct MigrationReadyBlock *block) | 292 | struct MigrationReadyBlock *block) |
296 | { | 293 | { |
297 | unsigned int i; | 294 | unsigned int i; |
298 | struct GSF_PeerPerformanceData *ppd; | 295 | struct GSF_PeerPerformanceData *ppd; |
@@ -300,18 +297,18 @@ score_content (struct MigrationReadyPeer *mrp, | |||
300 | struct GNUNET_HashCode hc; | 297 | struct GNUNET_HashCode hc; |
301 | uint32_t dist; | 298 | uint32_t dist; |
302 | 299 | ||
303 | ppd = GSF_get_peer_performance_data_ (mrp->peer); | 300 | ppd = GSF_get_peer_performance_data_(mrp->peer); |
304 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) | 301 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) |
305 | if (block->target_list[i] == ppd->pid) | 302 | if (block->target_list[i] == ppd->pid) |
306 | return -1; | 303 | return -1; |
307 | GNUNET_assert (0 != ppd->pid); | 304 | GNUNET_assert(0 != ppd->pid); |
308 | GNUNET_PEER_resolve (ppd->pid, | 305 | GNUNET_PEER_resolve(ppd->pid, |
309 | &id); | 306 | &id); |
310 | GNUNET_CRYPTO_hash (&id, | 307 | GNUNET_CRYPTO_hash(&id, |
311 | sizeof (struct GNUNET_PeerIdentity), | 308 | sizeof(struct GNUNET_PeerIdentity), |
312 | &hc); | 309 | &hc); |
313 | dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query, | 310 | dist = GNUNET_CRYPTO_hash_distance_u32(&block->query, |
314 | &hc); | 311 | &hc); |
315 | /* closer distance, higher score: */ | 312 | /* closer distance, higher score: */ |
316 | return UINT32_MAX - dist; | 313 | return UINT32_MAX - dist; |
317 | } | 314 | } |
@@ -322,7 +319,7 @@ score_content (struct MigrationReadyPeer *mrp, | |||
322 | * (re)scheduling it with the appropriate delay. | 319 | * (re)scheduling it with the appropriate delay. |
323 | */ | 320 | */ |
324 | static void | 321 | static void |
325 | consider_gathering (void); | 322 | consider_gathering(void); |
326 | 323 | ||
327 | 324 | ||
328 | /** | 325 | /** |
@@ -331,7 +328,7 @@ consider_gathering (void); | |||
331 | * @param cls peer to find content for | 328 | * @param cls peer to find content for |
332 | */ | 329 | */ |
333 | static void | 330 | static void |
334 | find_content (void *cls) | 331 | find_content(void *cls) |
335 | { | 332 | { |
336 | struct MigrationReadyPeer *mrp = cls; | 333 | struct MigrationReadyPeer *mrp = cls; |
337 | struct MigrationReadyBlock *pos; | 334 | struct MigrationReadyBlock *pos; |
@@ -344,48 +341,48 @@ find_content (void *cls) | |||
344 | best_score = -1; | 341 | best_score = -1; |
345 | pos = mig_head; | 342 | pos = mig_head; |
346 | while (NULL != pos) | 343 | while (NULL != pos) |
347 | { | ||
348 | score = score_content (mrp, pos); | ||
349 | if (score > best_score) | ||
350 | { | 344 | { |
351 | best_score = score; | 345 | score = score_content(mrp, pos); |
352 | best = pos; | 346 | if (score > best_score) |
347 | { | ||
348 | best_score = score; | ||
349 | best = pos; | ||
350 | } | ||
351 | pos = pos->next; | ||
353 | } | 352 | } |
354 | pos = pos->next; | ||
355 | } | ||
356 | if (NULL == best) | 353 | if (NULL == best) |
357 | { | ||
358 | if (mig_size < MAX_MIGRATION_QUEUE) | ||
359 | { | 354 | { |
360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 355 | if (mig_size < MAX_MIGRATION_QUEUE) |
361 | "No content found for pushing, waiting for queue to fill\n"); | 356 | { |
362 | return; /* will fill up eventually... */ | 357 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
363 | } | 358 | "No content found for pushing, waiting for queue to fill\n"); |
364 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 359 | return; /* will fill up eventually... */ |
365 | "No suitable content found, purging content from full queue\n"); | 360 | } |
366 | /* failed to find migration target AND | 361 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
367 | * queue is full, purge most-forwarded | 362 | "No suitable content found, purging content from full queue\n"); |
368 | * block from queue to make room for more */ | 363 | /* failed to find migration target AND |
369 | pos = mig_head; | 364 | * queue is full, purge most-forwarded |
370 | while (NULL != pos) | 365 | * block from queue to make room for more */ |
371 | { | 366 | pos = mig_head; |
372 | score = count_targets (pos); | 367 | while (NULL != pos) |
373 | if (score >= best_score) | 368 | { |
374 | { | 369 | score = count_targets(pos); |
375 | best_score = score; | 370 | if (score >= best_score) |
376 | best = pos; | 371 | { |
377 | } | 372 | best_score = score; |
378 | pos = pos->next; | 373 | best = pos; |
374 | } | ||
375 | pos = pos->next; | ||
376 | } | ||
377 | GNUNET_assert(NULL != best); | ||
378 | delete_migration_block(best); | ||
379 | consider_gathering(); | ||
380 | return; | ||
379 | } | 381 | } |
380 | GNUNET_assert (NULL != best); | 382 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
381 | delete_migration_block (best); | 383 | "Preparing to push best content to peer\n"); |
382 | consider_gathering (); | 384 | transmit_content(mrp, |
383 | return; | 385 | best); |
384 | } | ||
385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
386 | "Preparing to push best content to peer\n"); | ||
387 | transmit_content (mrp, | ||
388 | best); | ||
389 | } | 386 | } |
390 | 387 | ||
391 | 388 | ||
@@ -396,7 +393,7 @@ find_content (void *cls) | |||
396 | * @param cls unused | 393 | * @param cls unused |
397 | */ | 394 | */ |
398 | static void | 395 | static void |
399 | gather_migration_blocks (void *cls); | 396 | gather_migration_blocks(void *cls); |
400 | 397 | ||
401 | 398 | ||
402 | /** | 399 | /** |
@@ -404,7 +401,7 @@ gather_migration_blocks (void *cls); | |||
404 | * (re)scheduling it with the appropriate delay. | 401 | * (re)scheduling it with the appropriate delay. |
405 | */ | 402 | */ |
406 | static void | 403 | static void |
407 | consider_gathering () | 404 | consider_gathering() |
408 | { | 405 | { |
409 | struct GNUNET_TIME_Relative delay; | 406 | struct GNUNET_TIME_Relative delay; |
410 | 407 | ||
@@ -416,25 +413,25 @@ consider_gathering () | |||
416 | return; | 413 | return; |
417 | if (mig_size >= MAX_MIGRATION_QUEUE) | 414 | if (mig_size >= MAX_MIGRATION_QUEUE) |
418 | return; | 415 | return; |
419 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 416 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
420 | mig_size); | 417 | mig_size); |
421 | delay = GNUNET_TIME_relative_divide (delay, | 418 | delay = GNUNET_TIME_relative_divide(delay, |
422 | MAX_MIGRATION_QUEUE); | 419 | MAX_MIGRATION_QUEUE); |
423 | delay = GNUNET_TIME_relative_max (delay, | 420 | delay = GNUNET_TIME_relative_max(delay, |
424 | min_migration_delay); | 421 | min_migration_delay); |
425 | if (GNUNET_NO == value_found) | 422 | if (GNUNET_NO == value_found) |
426 | { | 423 | { |
427 | /* wait at least 5s if the datastore is empty */ | 424 | /* wait at least 5s if the datastore is empty */ |
428 | delay = GNUNET_TIME_relative_max (delay, | 425 | delay = GNUNET_TIME_relative_max(delay, |
429 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 426 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
430 | 5)); | 427 | 5)); |
431 | } | 428 | } |
432 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 429 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
433 | "Scheduling gathering task (queue size: %u)\n", | 430 | "Scheduling gathering task (queue size: %u)\n", |
434 | mig_size); | 431 | mig_size); |
435 | mig_task = GNUNET_SCHEDULER_add_delayed (delay, | 432 | mig_task = GNUNET_SCHEDULER_add_delayed(delay, |
436 | &gather_migration_blocks, | 433 | &gather_migration_blocks, |
437 | NULL); | 434 | NULL); |
438 | } | 435 | } |
439 | 436 | ||
440 | 437 | ||
@@ -454,81 +451,82 @@ consider_gathering () | |||
454 | * maybe 0 if no unique identifier is available | 451 | * maybe 0 if no unique identifier is available |
455 | */ | 452 | */ |
456 | static void | 453 | static void |
457 | process_migration_content (void *cls, | 454 | process_migration_content(void *cls, |
458 | const struct GNUNET_HashCode *key, | 455 | const struct GNUNET_HashCode *key, |
459 | size_t size, | 456 | size_t size, |
460 | const void *data, | 457 | const void *data, |
461 | enum GNUNET_BLOCK_Type type, | 458 | enum GNUNET_BLOCK_Type type, |
462 | uint32_t priority, | 459 | uint32_t priority, |
463 | uint32_t anonymity, | 460 | uint32_t anonymity, |
464 | uint32_t replication, | 461 | uint32_t replication, |
465 | struct GNUNET_TIME_Absolute expiration, | 462 | struct GNUNET_TIME_Absolute expiration, |
466 | uint64_t uid) | 463 | uint64_t uid) |
467 | { | 464 | { |
468 | struct MigrationReadyBlock *mb; | 465 | struct MigrationReadyBlock *mb; |
469 | struct MigrationReadyPeer *pos; | 466 | struct MigrationReadyPeer *pos; |
470 | 467 | ||
471 | mig_qe = NULL; | 468 | mig_qe = NULL; |
472 | if (NULL == key) | 469 | if (NULL == key) |
473 | { | 470 | { |
474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 471 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
475 | "No content found for migration...\n"); | 472 | "No content found for migration...\n"); |
476 | consider_gathering (); | 473 | consider_gathering(); |
477 | return; | 474 | return; |
478 | } | 475 | } |
479 | value_found = GNUNET_YES; | 476 | value_found = GNUNET_YES; |
480 | if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us < | 477 | if (GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us < |
481 | MIN_MIGRATION_CONTENT_LIFETIME.rel_value_us) | 478 | MIN_MIGRATION_CONTENT_LIFETIME.rel_value_us) |
482 | { | 479 | { |
483 | /* content will expire soon, don't bother */ | 480 | /* content will expire soon, don't bother */ |
484 | consider_gathering (); | 481 | consider_gathering(); |
485 | return; | 482 | return; |
486 | } | 483 | } |
487 | if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) | 484 | if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) |
488 | { | 485 | { |
489 | if (GNUNET_OK != | 486 | if (GNUNET_OK != |
490 | GNUNET_FS_handle_on_demand_block (key, | 487 | GNUNET_FS_handle_on_demand_block(key, |
491 | size, | 488 | size, |
492 | data, | 489 | data, |
493 | type, | 490 | type, |
494 | priority, | 491 | priority, |
495 | anonymity, | 492 | anonymity, |
496 | replication, | 493 | replication, |
497 | expiration, | 494 | expiration, |
498 | uid, | 495 | uid, |
499 | &process_migration_content, | 496 | &process_migration_content, |
500 | NULL)) | 497 | NULL)) |
501 | consider_gathering (); | 498 | consider_gathering(); |
502 | return; | 499 | return; |
503 | } | 500 | } |
504 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 501 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
505 | "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n", | 502 | "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n", |
506 | GNUNET_h2s (key), | 503 | GNUNET_h2s(key), |
507 | type, mig_size + 1, | 504 | type, mig_size + 1, |
508 | MAX_MIGRATION_QUEUE); | 505 | MAX_MIGRATION_QUEUE); |
509 | mb = GNUNET_malloc (sizeof (struct MigrationReadyBlock) + size); | 506 | mb = GNUNET_malloc(sizeof(struct MigrationReadyBlock) + size); |
510 | mb->query = *key; | 507 | mb->query = *key; |
511 | mb->expiration = expiration; | 508 | mb->expiration = expiration; |
512 | mb->size = size; | 509 | mb->size = size; |
513 | mb->type = type; | 510 | mb->type = type; |
514 | GNUNET_memcpy (&mb[1], data, size); | 511 | GNUNET_memcpy(&mb[1], data, size); |
515 | GNUNET_CONTAINER_DLL_insert_after (mig_head, | 512 | GNUNET_CONTAINER_DLL_insert_after(mig_head, |
516 | mig_tail, | 513 | mig_tail, |
517 | mig_tail, | 514 | mig_tail, |
518 | mb); | 515 | mb); |
519 | mig_size++; | 516 | mig_size++; |
520 | for (pos = peer_head; NULL != pos; pos = pos->next) | 517 | for (pos = peer_head; NULL != pos; pos = pos->next) |
521 | { | 518 | { |
522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 519 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
523 | "Preparing to push best content to peer %s\n", | 520 | "Preparing to push best content to peer %s\n", |
524 | GNUNET_i2s (GSF_connected_peer_get_identity2_(pos->peer))); | 521 | GNUNET_i2s(GSF_connected_peer_get_identity2_(pos->peer))); |
525 | if ( (NULL == pos->env) && | 522 | if ((NULL == pos->env) && |
526 | (GNUNET_YES == transmit_content (pos, | 523 | (GNUNET_YES == transmit_content(pos, |
527 | mb)) ) { | 524 | mb))) |
528 | break; /* 'mb' was freed! */ | 525 | { |
526 | break; /* 'mb' was freed! */ | ||
527 | } | ||
529 | } | 528 | } |
530 | } | 529 | consider_gathering(); |
531 | consider_gathering (); | ||
532 | } | 530 | } |
533 | 531 | ||
534 | 532 | ||
@@ -539,24 +537,24 @@ process_migration_content (void *cls, | |||
539 | * @param cls unused | 537 | * @param cls unused |
540 | */ | 538 | */ |
541 | static void | 539 | static void |
542 | gather_migration_blocks (void *cls) | 540 | gather_migration_blocks(void *cls) |
543 | { | 541 | { |
544 | mig_task = NULL; | 542 | mig_task = NULL; |
545 | if (mig_size >= MAX_MIGRATION_QUEUE) | 543 | if (mig_size >= MAX_MIGRATION_QUEUE) |
546 | return; | 544 | return; |
547 | if (NULL == GSF_dsh) | 545 | if (NULL == GSF_dsh) |
548 | return; | 546 | return; |
549 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 547 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
550 | "Asking datastore for content for replication (queue size: %u)\n", | 548 | "Asking datastore for content for replication (queue size: %u)\n", |
551 | mig_size); | 549 | mig_size); |
552 | value_found = GNUNET_NO; | 550 | value_found = GNUNET_NO; |
553 | mig_qe = GNUNET_DATASTORE_get_for_replication (GSF_dsh, | 551 | mig_qe = GNUNET_DATASTORE_get_for_replication(GSF_dsh, |
554 | 0, | 552 | 0, |
555 | UINT_MAX, | 553 | UINT_MAX, |
556 | &process_migration_content, | 554 | &process_migration_content, |
557 | NULL); | 555 | NULL); |
558 | if (NULL == mig_qe) | 556 | if (NULL == mig_qe) |
559 | consider_gathering (); | 557 | consider_gathering(); |
560 | } | 558 | } |
561 | 559 | ||
562 | 560 | ||
@@ -567,7 +565,7 @@ gather_migration_blocks (void *cls) | |||
567 | * @param peer handle for the peer that connected | 565 | * @param peer handle for the peer that connected |
568 | */ | 566 | */ |
569 | void | 567 | void |
570 | GSF_push_start_ (struct GSF_ConnectedPeer *peer) | 568 | GSF_push_start_(struct GSF_ConnectedPeer *peer) |
571 | { | 569 | { |
572 | struct MigrationReadyPeer *mrp; | 570 | struct MigrationReadyPeer *mrp; |
573 | 571 | ||
@@ -577,22 +575,22 @@ GSF_push_start_ (struct GSF_ConnectedPeer *peer) | |||
577 | if (mrp->peer == peer) | 575 | if (mrp->peer == peer) |
578 | break; | 576 | break; |
579 | if (NULL != mrp) | 577 | if (NULL != mrp) |
580 | { | 578 | { |
581 | /* same peer added twice, must not happen */ | 579 | /* same peer added twice, must not happen */ |
582 | GNUNET_break (0); | 580 | GNUNET_break(0); |
583 | return; | 581 | return; |
584 | } | 582 | } |
585 | 583 | ||
586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 584 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
587 | "Adding peer %s to list for pushing\n", | 585 | "Adding peer %s to list for pushing\n", |
588 | GNUNET_i2s (GSF_connected_peer_get_identity2_(peer))); | 586 | GNUNET_i2s(GSF_connected_peer_get_identity2_(peer))); |
589 | 587 | ||
590 | mrp = GNUNET_new (struct MigrationReadyPeer); | 588 | mrp = GNUNET_new(struct MigrationReadyPeer); |
591 | mrp->peer = peer; | 589 | mrp->peer = peer; |
592 | find_content (mrp); | 590 | find_content(mrp); |
593 | GNUNET_CONTAINER_DLL_insert (peer_head, | 591 | GNUNET_CONTAINER_DLL_insert(peer_head, |
594 | peer_tail, | 592 | peer_tail, |
595 | mrp); | 593 | mrp); |
596 | } | 594 | } |
597 | 595 | ||
598 | 596 | ||
@@ -603,7 +601,7 @@ GSF_push_start_ (struct GSF_ConnectedPeer *peer) | |||
603 | * @param peer handle for the peer that disconnected | 601 | * @param peer handle for the peer that disconnected |
604 | */ | 602 | */ |
605 | void | 603 | void |
606 | GSF_push_stop_ (struct GSF_ConnectedPeer *peer) | 604 | GSF_push_stop_(struct GSF_ConnectedPeer *peer) |
607 | { | 605 | { |
608 | struct MigrationReadyPeer *pos; | 606 | struct MigrationReadyPeer *pos; |
609 | 607 | ||
@@ -613,11 +611,11 @@ GSF_push_stop_ (struct GSF_ConnectedPeer *peer) | |||
613 | if (NULL == pos) | 611 | if (NULL == pos) |
614 | return; | 612 | return; |
615 | if (NULL != pos->env) | 613 | if (NULL != pos->env) |
616 | GNUNET_MQ_send_cancel (pos->env); | 614 | GNUNET_MQ_send_cancel(pos->env); |
617 | GNUNET_CONTAINER_DLL_remove (peer_head, | 615 | GNUNET_CONTAINER_DLL_remove(peer_head, |
618 | peer_tail, | 616 | peer_tail, |
619 | pos); | 617 | pos); |
620 | GNUNET_free (pos); | 618 | GNUNET_free(pos); |
621 | } | 619 | } |
622 | 620 | ||
623 | 621 | ||
@@ -625,28 +623,28 @@ GSF_push_stop_ (struct GSF_ConnectedPeer *peer) | |||
625 | * Setup the module. | 623 | * Setup the module. |
626 | */ | 624 | */ |
627 | void | 625 | void |
628 | GSF_push_init_ () | 626 | GSF_push_init_() |
629 | { | 627 | { |
630 | enabled = | 628 | enabled = |
631 | GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, | 629 | GNUNET_CONFIGURATION_get_value_yesno(GSF_cfg, |
632 | "FS", | 630 | "FS", |
633 | "CONTENT_PUSHING"); | 631 | "CONTENT_PUSHING"); |
634 | if (GNUNET_YES != enabled) | 632 | if (GNUNET_YES != enabled) |
635 | return; | 633 | return; |
636 | 634 | ||
637 | if (GNUNET_OK != | 635 | if (GNUNET_OK != |
638 | GNUNET_CONFIGURATION_get_value_time (GSF_cfg, | 636 | GNUNET_CONFIGURATION_get_value_time(GSF_cfg, |
639 | "fs", | 637 | "fs", |
640 | "MIN_MIGRATION_DELAY", | 638 | "MIN_MIGRATION_DELAY", |
641 | &min_migration_delay)) | 639 | &min_migration_delay)) |
642 | { | 640 | { |
643 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, | 641 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, |
644 | "fs", | 642 | "fs", |
645 | "MIN_MIGRATION_DELAY", | 643 | "MIN_MIGRATION_DELAY", |
646 | _("time required, content pushing disabled")); | 644 | _("time required, content pushing disabled")); |
647 | return; | 645 | return; |
648 | } | 646 | } |
649 | consider_gathering (); | 647 | consider_gathering(); |
650 | } | 648 | } |
651 | 649 | ||
652 | 650 | ||
@@ -654,21 +652,21 @@ GSF_push_init_ () | |||
654 | * Shutdown the module. | 652 | * Shutdown the module. |
655 | */ | 653 | */ |
656 | void | 654 | void |
657 | GSF_push_done_ () | 655 | GSF_push_done_() |
658 | { | 656 | { |
659 | if (NULL != mig_task) | 657 | if (NULL != mig_task) |
660 | { | 658 | { |
661 | GNUNET_SCHEDULER_cancel (mig_task); | 659 | GNUNET_SCHEDULER_cancel(mig_task); |
662 | mig_task = NULL; | 660 | mig_task = NULL; |
663 | } | 661 | } |
664 | if (NULL != mig_qe) | 662 | if (NULL != mig_qe) |
665 | { | 663 | { |
666 | GNUNET_DATASTORE_cancel (mig_qe); | 664 | GNUNET_DATASTORE_cancel(mig_qe); |
667 | mig_qe = NULL; | 665 | mig_qe = NULL; |
668 | } | 666 | } |
669 | while (NULL != mig_head) | 667 | while (NULL != mig_head) |
670 | delete_migration_block (mig_head); | 668 | delete_migration_block(mig_head); |
671 | GNUNET_assert (0 == mig_size); | 669 | GNUNET_assert(0 == mig_size); |
672 | } | 670 | } |
673 | 671 | ||
674 | /* end of gnunet-service-fs_push.c */ | 672 | /* 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 ab2d2204a..0917364e2 100644 --- a/src/fs/gnunet-service-fs_push.h +++ b/src/fs/gnunet-service-fs_push.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_push.h | 22 | * @file 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 78a4b98df..deba91a0c 100644 --- a/src/fs/gnunet-service-fs_put.c +++ b/src/fs/gnunet-service-fs_put.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_put.c | 22 | * @file fs/gnunet-service-fs_put.c |
@@ -31,7 +31,7 @@ | |||
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(GNUNET_TIME_UNIT_SECONDS, 5) |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * How many replicas do we try to create per PUT? | 37 | * How many replicas do we try to create per PUT? |
@@ -42,9 +42,7 @@ | |||
42 | /** | 42 | /** |
43 | * Context for each zero-anonymity iterator. | 43 | * Context for each zero-anonymity iterator. |
44 | */ | 44 | */ |
45 | struct PutOperator | 45 | struct PutOperator { |
46 | { | ||
47 | |||
48 | /** | 46 | /** |
49 | * Request to datastore for DHT PUTs (or NULL). | 47 | * Request to datastore for DHT PUTs (or NULL). |
50 | */ | 48 | */ |
@@ -88,8 +86,8 @@ struct PutOperator | |||
88 | * of block that we're putting into the DHT). | 86 | * of block that we're putting into the DHT). |
89 | */ | 87 | */ |
90 | static struct PutOperator operators[] = { | 88 | static struct PutOperator operators[] = { |
91 | {NULL, GNUNET_BLOCK_TYPE_FS_UBLOCK, 0, 0, 0}, | 89 | { NULL, GNUNET_BLOCK_TYPE_FS_UBLOCK, 0, 0, 0 }, |
92 | {NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0} | 90 | { NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0 } |
93 | }; | 91 | }; |
94 | 92 | ||
95 | 93 | ||
@@ -100,7 +98,7 @@ static struct PutOperator operators[] = { | |||
100 | * @param tc scheduler context (unused) | 98 | * @param tc scheduler context (unused) |
101 | */ | 99 | */ |
102 | static void | 100 | static void |
103 | gather_dht_put_blocks (void *cls); | 101 | gather_dht_put_blocks(void *cls); |
104 | 102 | ||
105 | 103 | ||
106 | /** | 104 | /** |
@@ -109,25 +107,25 @@ gather_dht_put_blocks (void *cls); | |||
109 | * @param po put operator to schedule | 107 | * @param po put operator to schedule |
110 | */ | 108 | */ |
111 | static void | 109 | static void |
112 | schedule_next_put (struct PutOperator *po) | 110 | schedule_next_put(struct PutOperator *po) |
113 | { | 111 | { |
114 | struct GNUNET_TIME_Relative delay; | 112 | struct GNUNET_TIME_Relative delay; |
115 | 113 | ||
116 | if (po->zero_anonymity_count_estimate > 0) | 114 | if (po->zero_anonymity_count_estimate > 0) |
117 | { | 115 | { |
118 | delay = | 116 | delay = |
119 | GNUNET_TIME_relative_divide (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, | 117 | GNUNET_TIME_relative_divide(GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, |
120 | po->zero_anonymity_count_estimate); | 118 | po->zero_anonymity_count_estimate); |
121 | delay = GNUNET_TIME_relative_min (delay, MAX_DHT_PUT_FREQ); | 119 | delay = GNUNET_TIME_relative_min(delay, MAX_DHT_PUT_FREQ); |
122 | } | 120 | } |
123 | else | 121 | else |
124 | { | 122 | { |
125 | /* if we have NO zero-anonymity content yet, wait 5 minutes for some to | 123 | /* if we have NO zero-anonymity content yet, wait 5 minutes for some to |
126 | * (hopefully) appear */ | 124 | * (hopefully) appear */ |
127 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5); | 125 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5); |
128 | } | 126 | } |
129 | po->dht_task = | 127 | po->dht_task = |
130 | GNUNET_SCHEDULER_add_delayed (delay, &gather_dht_put_blocks, po); | 128 | GNUNET_SCHEDULER_add_delayed(delay, &gather_dht_put_blocks, po); |
131 | } | 129 | } |
132 | 130 | ||
133 | 131 | ||
@@ -137,12 +135,12 @@ schedule_next_put (struct PutOperator *po) | |||
137 | * @param cls type of blocks to gather | 135 | * @param cls type of blocks to gather |
138 | */ | 136 | */ |
139 | static void | 137 | static void |
140 | delay_dht_put_blocks (void *cls) | 138 | delay_dht_put_blocks(void *cls) |
141 | { | 139 | { |
142 | struct PutOperator *po = cls; | 140 | struct PutOperator *po = cls; |
143 | 141 | ||
144 | po->dht_put = NULL; | 142 | po->dht_put = NULL; |
145 | schedule_next_put (po); | 143 | schedule_next_put(po); |
146 | } | 144 | } |
147 | 145 | ||
148 | 146 | ||
@@ -152,12 +150,12 @@ delay_dht_put_blocks (void *cls) | |||
152 | * @param cls type of blocks to gather | 150 | * @param cls type of blocks to gather |
153 | */ | 151 | */ |
154 | static void | 152 | static void |
155 | delay_dht_put_task (void *cls) | 153 | delay_dht_put_task(void *cls) |
156 | { | 154 | { |
157 | struct PutOperator *po = cls; | 155 | struct PutOperator *po = cls; |
158 | 156 | ||
159 | po->dht_task = NULL; | 157 | po->dht_task = NULL; |
160 | schedule_next_put (po); | 158 | schedule_next_put(po); |
161 | } | 159 | } |
162 | 160 | ||
163 | 161 | ||
@@ -177,45 +175,45 @@ delay_dht_put_task (void *cls) | |||
177 | * maybe 0 if no unique identifier is available | 175 | * maybe 0 if no unique identifier is available |
178 | */ | 176 | */ |
179 | static void | 177 | static void |
180 | process_dht_put_content (void *cls, | 178 | process_dht_put_content(void *cls, |
181 | const struct GNUNET_HashCode * key, | 179 | const struct GNUNET_HashCode * key, |
182 | size_t size, | 180 | size_t size, |
183 | const void *data, | 181 | const void *data, |
184 | enum GNUNET_BLOCK_Type type, | 182 | enum GNUNET_BLOCK_Type type, |
185 | uint32_t priority, | 183 | uint32_t priority, |
186 | uint32_t anonymity, | 184 | uint32_t anonymity, |
187 | uint32_t replication, | 185 | uint32_t replication, |
188 | struct GNUNET_TIME_Absolute expiration, | 186 | struct GNUNET_TIME_Absolute expiration, |
189 | uint64_t uid) | 187 | uint64_t uid) |
190 | { | 188 | { |
191 | struct PutOperator *po = cls; | 189 | struct PutOperator *po = cls; |
192 | 190 | ||
193 | po->dht_qe = NULL; | 191 | po->dht_qe = NULL; |
194 | if (key == NULL) | 192 | if (key == NULL) |
195 | { | 193 | { |
196 | po->zero_anonymity_count_estimate = po->result_count; | 194 | po->zero_anonymity_count_estimate = po->result_count; |
197 | po->result_count = 0; | 195 | po->result_count = 0; |
198 | po->next_uid = 0; | 196 | po->next_uid = 0; |
199 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po); | 197 | po->dht_task = GNUNET_SCHEDULER_add_now(&delay_dht_put_task, po); |
200 | return; | 198 | return; |
201 | } | 199 | } |
202 | po->result_count++; | 200 | po->result_count++; |
203 | po->next_uid = uid + 1; | 201 | po->next_uid = uid + 1; |
204 | po->zero_anonymity_count_estimate = | 202 | po->zero_anonymity_count_estimate = |
205 | GNUNET_MAX (po->result_count, po->zero_anonymity_count_estimate); | 203 | GNUNET_MAX(po->result_count, po->zero_anonymity_count_estimate); |
206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 204 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
207 | "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key), | 205 | "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s(key), |
208 | type); | 206 | type); |
209 | po->dht_put = GNUNET_DHT_put (GSF_dht, | 207 | po->dht_put = GNUNET_DHT_put(GSF_dht, |
210 | key, | 208 | key, |
211 | DEFAULT_PUT_REPLICATION, | 209 | DEFAULT_PUT_REPLICATION, |
212 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 210 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
213 | type, | 211 | type, |
214 | size, | 212 | size, |
215 | data, | 213 | data, |
216 | expiration, | 214 | expiration, |
217 | &delay_dht_put_blocks, | 215 | &delay_dht_put_blocks, |
218 | po); | 216 | po); |
219 | } | 217 | } |
220 | 218 | ||
221 | 219 | ||
@@ -225,21 +223,21 @@ process_dht_put_content (void *cls, | |||
225 | * @param cls type of blocks to gather | 223 | * @param cls type of blocks to gather |
226 | */ | 224 | */ |
227 | static void | 225 | static void |
228 | gather_dht_put_blocks (void *cls) | 226 | gather_dht_put_blocks(void *cls) |
229 | { | 227 | { |
230 | struct PutOperator *po = cls; | 228 | struct PutOperator *po = cls; |
231 | 229 | ||
232 | po->dht_task = NULL; | 230 | po->dht_task = NULL; |
233 | po->dht_qe = | 231 | po->dht_qe = |
234 | GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, | 232 | GNUNET_DATASTORE_get_zero_anonymity(GSF_dsh, |
235 | po->next_uid, | 233 | po->next_uid, |
236 | 0, | 234 | 0, |
237 | UINT_MAX, | 235 | UINT_MAX, |
238 | po->dht_put_type, | 236 | po->dht_put_type, |
239 | &process_dht_put_content, | 237 | &process_dht_put_content, |
240 | po); | 238 | po); |
241 | if (NULL == po->dht_qe) | 239 | if (NULL == po->dht_qe) |
242 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po); | 240 | po->dht_task = GNUNET_SCHEDULER_add_now(&delay_dht_put_task, po); |
243 | } | 241 | } |
244 | 242 | ||
245 | 243 | ||
@@ -247,17 +245,17 @@ gather_dht_put_blocks (void *cls) | |||
247 | * Setup the module. | 245 | * Setup the module. |
248 | */ | 246 | */ |
249 | void | 247 | void |
250 | GSF_put_init_ () | 248 | GSF_put_init_() |
251 | { | 249 | { |
252 | unsigned int i; | 250 | unsigned int i; |
253 | 251 | ||
254 | i = 0; | 252 | i = 0; |
255 | while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY) | 253 | while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY) |
256 | { | 254 | { |
257 | operators[i].dht_task = | 255 | operators[i].dht_task = |
258 | GNUNET_SCHEDULER_add_now (&gather_dht_put_blocks, &operators[i]); | 256 | GNUNET_SCHEDULER_add_now(&gather_dht_put_blocks, &operators[i]); |
259 | i++; | 257 | i++; |
260 | } | 258 | } |
261 | } | 259 | } |
262 | 260 | ||
263 | 261 | ||
@@ -265,31 +263,31 @@ GSF_put_init_ () | |||
265 | * Shutdown the module. | 263 | * Shutdown the module. |
266 | */ | 264 | */ |
267 | void | 265 | void |
268 | GSF_put_done_ () | 266 | GSF_put_done_() |
269 | { | 267 | { |
270 | struct PutOperator *po; | 268 | struct PutOperator *po; |
271 | unsigned int i; | 269 | unsigned int i; |
272 | 270 | ||
273 | i = 0; | 271 | i = 0; |
274 | while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY) | 272 | 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) | ||
287 | { | 273 | { |
288 | GNUNET_DATASTORE_cancel (po->dht_qe); | 274 | if (NULL != po->dht_task) |
289 | po->dht_qe = NULL; | 275 | { |
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 | } | ||
293 | } | 291 | } |
294 | 292 | ||
295 | /* end of gnunet-service-fs_put.c */ | 293 | /* 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 de9751842..2d85d9831 100644 --- a/src/fs/gnunet-service-fs_put.h +++ b/src/fs/gnunet-service-fs_put.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/gnunet-service-fs_put.h | 22 | * @file 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 4d13e7ef3..873dfa5eb 100644 --- a/src/fs/gnunet-unindex.c +++ b/src/fs/gnunet-unindex.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/gnunet-unindex.c | 21 | * @file fs/gnunet-unindex.c |
22 | * @brief unindex files published on GNUnet | 22 | * @brief unindex files published on GNUnet |
@@ -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,43 +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 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | ||
86 | if (verbose) | ||
87 | { | 82 | { |
88 | s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta, | 83 | case GNUNET_FS_STATUS_UNINDEX_START: |
89 | GNUNET_YES); | 84 | break; |
90 | fprintf (stdout, | 85 | |
91 | _ ("Unindexing at %llu/%llu (%s remaining)\n"), | 86 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: |
92 | (unsigned long long) info->value.unindex.completed, | 87 | if (verbose) |
93 | (unsigned long long) info->value.unindex.size, | 88 | { |
94 | s); | 89 | s = GNUNET_STRINGS_relative_time_to_string(info->value.unindex.eta, |
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; | ||
95 | } | 118 | } |
96 | break; | ||
97 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | ||
98 | fprintf (stderr, | ||
99 | _ ("Error unindexing: %s.\n"), | ||
100 | info->value.unindex.specifics.error.message); | ||
101 | GNUNET_SCHEDULER_shutdown (); | ||
102 | break; | ||
103 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | ||
104 | fprintf (stdout, "%s", _ ("Unindexing done.\n")); | ||
105 | GNUNET_SCHEDULER_shutdown (); | ||
106 | break; | ||
107 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | ||
108 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | ||
109 | break; | ||
110 | default: | ||
111 | fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); | ||
112 | break; | ||
113 | } | ||
114 | return NULL; | 119 | return NULL; |
115 | } | 120 | } |
116 | 121 | ||
@@ -124,39 +129,39 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
124 | * @param c configuration | 129 | * @param c configuration |
125 | */ | 130 | */ |
126 | static void | 131 | static void |
127 | run (void *cls, | 132 | run(void *cls, |
128 | char *const *args, | 133 | char *const *args, |
129 | const char *cfgfile, | 134 | const char *cfgfile, |
130 | const struct GNUNET_CONFIGURATION_Handle *c) | 135 | const struct GNUNET_CONFIGURATION_Handle *c) |
131 | { | 136 | { |
132 | /* check arguments */ | 137 | /* check arguments */ |
133 | if ((args[0] == NULL) || (args[1] != NULL)) | 138 | if ((args[0] == NULL) || (args[1] != NULL)) |
134 | { | 139 | { |
135 | 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")); |
136 | ret = -1; | 141 | ret = -1; |
137 | return; | 142 | return; |
138 | } | 143 | } |
139 | cfg = c; | 144 | cfg = c; |
140 | ctx = GNUNET_FS_start (cfg, | 145 | ctx = GNUNET_FS_start(cfg, |
141 | "gnunet-unindex", | 146 | "gnunet-unindex", |
142 | &progress_cb, | 147 | &progress_cb, |
143 | NULL, | 148 | NULL, |
144 | GNUNET_FS_FLAGS_NONE, | 149 | GNUNET_FS_FLAGS_NONE, |
145 | GNUNET_FS_OPTIONS_END); | 150 | GNUNET_FS_OPTIONS_END); |
146 | if (NULL == ctx) | 151 | if (NULL == ctx) |
147 | { | 152 | { |
148 | fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); | 153 | fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); |
149 | ret = 1; | 154 | ret = 1; |
150 | return; | 155 | return; |
151 | } | 156 | } |
152 | uc = GNUNET_FS_unindex_start (ctx, args[0], NULL); | 157 | uc = GNUNET_FS_unindex_start(ctx, args[0], NULL); |
153 | if (NULL == uc) | 158 | if (NULL == uc) |
154 | { | 159 | { |
155 | fprintf (stderr, "%s", _ ("Could not start unindex operation.\n")); | 160 | fprintf(stderr, "%s", _("Could not start unindex operation.\n")); |
156 | GNUNET_FS_stop (ctx); | 161 | GNUNET_FS_stop(ctx); |
157 | return; | 162 | return; |
158 | } | 163 | } |
159 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 164 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
160 | } | 165 | } |
161 | 166 | ||
162 | 167 | ||
@@ -168,30 +173,30 @@ run (void *cls, | |||
168 | * @return 0 ok, 1 on error | 173 | * @return 0 ok, 1 on error |
169 | */ | 174 | */ |
170 | int | 175 | int |
171 | main (int argc, char *const *argv) | 176 | main(int argc, char *const *argv) |
172 | { | 177 | { |
173 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 178 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
179 | GNUNET_GETOPT_option_verbose(&verbose), | ||
174 | 180 | ||
175 | GNUNET_GETOPT_option_verbose (&verbose), | 181 | GNUNET_GETOPT_OPTION_END |
176 | 182 | }; | |
177 | GNUNET_GETOPT_OPTION_END}; | ||
178 | 183 | ||
179 | 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)) |
180 | return 2; | 185 | return 2; |
181 | 186 | ||
182 | ret = (GNUNET_OK == | 187 | ret = (GNUNET_OK == |
183 | GNUNET_PROGRAM_run ( | 188 | GNUNET_PROGRAM_run( |
184 | argc, | 189 | argc, |
185 | argv, | 190 | argv, |
186 | "gnunet-unindex [OPTIONS] FILENAME", | 191 | "gnunet-unindex [OPTIONS] FILENAME", |
187 | gettext_noop ( | 192 | gettext_noop( |
188 | "Unindex a file that was previously indexed with gnunet-publish."), | 193 | "Unindex a file that was previously indexed with gnunet-publish."), |
189 | options, | 194 | options, |
190 | &run, | 195 | &run, |
191 | NULL)) | 196 | NULL)) |
192 | ? ret | 197 | ? ret |
193 | : 1; | 198 | : 1; |
194 | GNUNET_free ((void *) argv); | 199 | GNUNET_free((void *)argv); |
195 | return ret; | 200 | return ret; |
196 | } | 201 | } |
197 | 202 | ||
diff --git a/src/fs/perf_gnunet_service_fs_p2p.c b/src/fs/perf_gnunet_service_fs_p2p.c index 0d76dfc3d..515144eb1 100644 --- a/src/fs/perf_gnunet_service_fs_p2p.c +++ b/src/fs/perf_gnunet_service_fs_p2p.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/perf_gnunet_service_fs_p2p.c | 22 | * @file 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,16 +57,14 @@ 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 | { | ||
62 | struct GNUNET_STATISTICS_Handle *stat; | 61 | struct GNUNET_STATISTICS_Handle *stat; |
63 | struct GNUNET_TESTBED_Operation *op; | 62 | struct GNUNET_TESTBED_Operation *op; |
64 | unsigned int daemon; | 63 | unsigned int daemon; |
65 | unsigned int value; | 64 | unsigned int value; |
66 | }; | 65 | }; |
67 | 66 | ||
68 | struct StatValues | 67 | struct StatValues { |
69 | { | ||
70 | const char *subsystem; | 68 | const char *subsystem; |
71 | const char *name; | 69 | const char *name; |
72 | }; | 70 | }; |
@@ -75,28 +73,28 @@ struct StatValues | |||
75 | * Statistics we print out. | 73 | * Statistics we print out. |
76 | */ | 74 | */ |
77 | static struct StatValues stats[] = { | 75 | static struct StatValues stats[] = { |
78 | {"fs", "# queries forwarded"}, | 76 | { "fs", "# queries forwarded" }, |
79 | {"fs", "# replies received and matched"}, | 77 | { "fs", "# replies received and matched" }, |
80 | {"fs", "# results found locally"}, | 78 | { "fs", "# results found locally" }, |
81 | {"fs", "# requests forwarded due to high load"}, | 79 | { "fs", "# requests forwarded due to high load" }, |
82 | {"fs", "# requests done for free (low load)"}, | 80 | { "fs", "# requests done for free (low load)" }, |
83 | {"fs", "# requests dropped, priority insufficient"}, | 81 | { "fs", "# requests dropped, priority insufficient" }, |
84 | {"fs", "# requests done for a price (normal load)"}, | 82 | { "fs", "# requests done for a price (normal load)" }, |
85 | {"fs", "# requests dropped by datastore (queue length limit)"}, | 83 | { "fs", "# requests dropped by datastore (queue length limit)" }, |
86 | {"fs", "# P2P searches received"}, | 84 | { "fs", "# P2P searches received" }, |
87 | {"fs", "# P2P searches discarded (queue length bound)"}, | 85 | { "fs", "# P2P searches discarded (queue length bound)" }, |
88 | {"fs", "# replies received for local clients"}, | 86 | { "fs", "# replies received for local clients" }, |
89 | {"fs", "# queries retransmitted to same target"}, | 87 | { "fs", "# queries retransmitted to same target" }, |
90 | {"core", "# bytes decrypted"}, | 88 | { "core", "# bytes decrypted" }, |
91 | {"core", "# bytes encrypted"}, | 89 | { "core", "# bytes encrypted" }, |
92 | {"core", "# discarded CORE_SEND requests"}, | 90 | { "core", "# discarded CORE_SEND requests" }, |
93 | {"core", "# discarded CORE_SEND request bytes"}, | 91 | { "core", "# discarded CORE_SEND request bytes" }, |
94 | {"core", "# discarded lower priority CORE_SEND requests"}, | 92 | { "core", "# discarded lower priority CORE_SEND requests" }, |
95 | {"core", "# discarded lower priority CORE_SEND request bytes"}, | 93 | { "core", "# discarded lower priority CORE_SEND request bytes" }, |
96 | {"transport", "# bytes received via TCP"}, | 94 | { "transport", "# bytes received via TCP" }, |
97 | {"transport", "# bytes transmitted via TCP"}, | 95 | { "transport", "# bytes transmitted via TCP" }, |
98 | {"datacache", "# bytes stored"}, | 96 | { "datacache", "# bytes stored" }, |
99 | {NULL, NULL} | 97 | { NULL, NULL } |
100 | }; | 98 | }; |
101 | 99 | ||
102 | 100 | ||
@@ -111,17 +109,17 @@ static struct StatValues stats[] = { | |||
111 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 109 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
112 | */ | 110 | */ |
113 | static int | 111 | static int |
114 | print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, | 112 | print_stat(void *cls, const char *subsystem, const char *name, uint64_t value, |
115 | int is_persistent) | 113 | int is_persistent) |
116 | { | 114 | { |
117 | struct StatMaster *sm = cls; | 115 | struct StatMaster *sm = cls; |
118 | 116 | ||
119 | fprintf (stderr, | 117 | fprintf(stderr, |
120 | "Peer %2u: %12s/%50s = %12llu\n", | 118 | "Peer %2u: %12s/%50s = %12llu\n", |
121 | sm->daemon, | 119 | sm->daemon, |
122 | subsystem, | 120 | subsystem, |
123 | name, | 121 | name, |
124 | (unsigned long long) value); | 122 | (unsigned long long)value); |
125 | return GNUNET_OK; | 123 | return GNUNET_OK; |
126 | } | 124 | } |
127 | 125 | ||
@@ -130,23 +128,23 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, | |||
130 | * Function that gathers stats from all daemons. | 128 | * Function that gathers stats from all daemons. |
131 | */ | 129 | */ |
132 | static void | 130 | static void |
133 | stat_run (void *cls, | 131 | stat_run(void *cls, |
134 | struct GNUNET_TESTBED_Operation *op, | 132 | struct GNUNET_TESTBED_Operation *op, |
135 | void *ca_result, | 133 | void *ca_result, |
136 | const char *emsg); | 134 | const char *emsg); |
137 | 135 | ||
138 | 136 | ||
139 | /** | 137 | /** |
140 | * Function called when GET operation on stats is done. | 138 | * Function called when GET operation on stats is done. |
141 | */ | 139 | */ |
142 | static void | 140 | static void |
143 | get_done (void *cls, int success) | 141 | get_done(void *cls, int success) |
144 | { | 142 | { |
145 | struct StatMaster *sm = cls; | 143 | struct StatMaster *sm = cls; |
146 | 144 | ||
147 | GNUNET_break (GNUNET_OK == success); | 145 | GNUNET_break(GNUNET_OK == success); |
148 | sm->value++; | 146 | sm->value++; |
149 | stat_run (sm, sm->op, sm->stat, NULL); | 147 | stat_run(sm, sm->op, sm->stat, NULL); |
150 | } | 148 | } |
151 | 149 | ||
152 | 150 | ||
@@ -161,11 +159,11 @@ get_done (void *cls, int success) | |||
161 | * @return service handle to return in 'op_result', NULL on error | 159 | * @return service handle to return in 'op_result', NULL on error |
162 | */ | 160 | */ |
163 | static void * | 161 | static void * |
164 | statistics_connect_adapter (void *cls, | 162 | statistics_connect_adapter(void *cls, |
165 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 163 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
166 | { | 164 | { |
167 | return GNUNET_STATISTICS_create ("<driver>", | 165 | return GNUNET_STATISTICS_create("<driver>", |
168 | cfg); | 166 | cfg); |
169 | } | 167 | } |
170 | 168 | ||
171 | 169 | ||
@@ -177,10 +175,10 @@ statistics_connect_adapter (void *cls, | |||
177 | * @param op_result service handle returned from the connect adapter | 175 | * @param op_result service handle returned from the connect adapter |
178 | */ | 176 | */ |
179 | static void | 177 | static void |
180 | statistics_disconnect_adapter (void *cls, | 178 | statistics_disconnect_adapter(void *cls, |
181 | void *op_result) | 179 | void *op_result) |
182 | { | 180 | { |
183 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); | 181 | GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); |
184 | } | 182 | } |
185 | 183 | ||
186 | 184 | ||
@@ -188,57 +186,57 @@ statistics_disconnect_adapter (void *cls, | |||
188 | * Function that gathers stats from all daemons. | 186 | * Function that gathers stats from all daemons. |
189 | */ | 187 | */ |
190 | static void | 188 | static void |
191 | stat_run (void *cls, | 189 | stat_run(void *cls, |
192 | struct GNUNET_TESTBED_Operation *op, | 190 | struct GNUNET_TESTBED_Operation *op, |
193 | void *ca_result, | 191 | void *ca_result, |
194 | const char *emsg) | 192 | const char *emsg) |
195 | { | 193 | { |
196 | struct StatMaster *sm = cls; | 194 | struct StatMaster *sm = cls; |
197 | 195 | ||
198 | if (NULL != emsg) | 196 | if (NULL != emsg) |
199 | { | 197 | { |
200 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 198 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
201 | "Failed to statistics service: %s\n", | 199 | "Failed to statistics service: %s\n", |
202 | emsg); | 200 | emsg); |
203 | GNUNET_SCHEDULER_shutdown (); | 201 | GNUNET_SCHEDULER_shutdown(); |
204 | return; | 202 | return; |
205 | } | 203 | } |
206 | sm->stat = ca_result; | 204 | sm->stat = ca_result; |
207 | 205 | ||
208 | if (stats[sm->value].name != NULL) | 206 | if (stats[sm->value].name != NULL) |
209 | { | 207 | { |
210 | GNUNET_STATISTICS_get (sm->stat, | 208 | GNUNET_STATISTICS_get(sm->stat, |
211 | #if 0 | 209 | #if 0 |
212 | NULL, NULL, | 210 | NULL, NULL, |
213 | #else | 211 | #else |
214 | stats[sm->value].subsystem, stats[sm->value].name, | 212 | stats[sm->value].subsystem, stats[sm->value].name, |
215 | #endif | 213 | #endif |
216 | &get_done, &print_stat, | 214 | &get_done, &print_stat, |
217 | sm); | 215 | sm); |
218 | return; | 216 | return; |
219 | } | 217 | } |
220 | GNUNET_TESTBED_operation_done (sm->op); | 218 | GNUNET_TESTBED_operation_done(sm->op); |
221 | sm->value = 0; | 219 | sm->value = 0; |
222 | sm->daemon++; | 220 | sm->daemon++; |
223 | if (NUM_DAEMONS == sm->daemon) | 221 | if (NUM_DAEMONS == sm->daemon) |
224 | { | 222 | { |
225 | GNUNET_free (sm); | 223 | GNUNET_free(sm); |
226 | GNUNET_SCHEDULER_shutdown (); | 224 | GNUNET_SCHEDULER_shutdown(); |
227 | return; | 225 | return; |
228 | } | 226 | } |
229 | sm->op = | 227 | sm->op = |
230 | GNUNET_TESTBED_service_connect (NULL, | 228 | GNUNET_TESTBED_service_connect(NULL, |
231 | daemons[sm->daemon], | 229 | daemons[sm->daemon], |
232 | "statistics", | 230 | "statistics", |
233 | &stat_run, sm, | 231 | &stat_run, sm, |
234 | &statistics_connect_adapter, | 232 | &statistics_connect_adapter, |
235 | &statistics_disconnect_adapter, | 233 | &statistics_disconnect_adapter, |
236 | NULL); | 234 | NULL); |
237 | } | 235 | } |
238 | 236 | ||
239 | 237 | ||
240 | static void | 238 | static void |
241 | do_report (void *cls) | 239 | do_report(void *cls) |
242 | { | 240 | { |
243 | char *fn = cls; | 241 | char *fn = cls; |
244 | struct GNUNET_TIME_Relative del; | 242 | struct GNUNET_TIME_Relative del; |
@@ -246,120 +244,120 @@ do_report (void *cls) | |||
246 | struct StatMaster *sm; | 244 | struct StatMaster *sm; |
247 | 245 | ||
248 | if (NULL != fn) | 246 | if (NULL != fn) |
249 | { | 247 | { |
250 | GNUNET_DISK_directory_remove (fn); | 248 | GNUNET_DISK_directory_remove(fn); |
251 | GNUNET_free (fn); | 249 | GNUNET_free(fn); |
252 | } | 250 | } |
253 | if (0 == | 251 | if (0 == |
254 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, | 252 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, |
255 | TIMEOUT)).rel_value_us) | 253 | TIMEOUT)).rel_value_us) |
256 | { | 254 | { |
257 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 255 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
258 | "Timeout during download, shutting down with error\n"); | 256 | "Timeout during download, shutting down with error\n"); |
259 | ok = 1; | 257 | ok = 1; |
260 | GNUNET_SCHEDULER_shutdown (); | 258 | GNUNET_SCHEDULER_shutdown(); |
261 | return; | 259 | return; |
262 | } | 260 | } |
263 | 261 | ||
264 | del = GNUNET_TIME_absolute_get_duration (start_time); | 262 | del = GNUNET_TIME_absolute_get_duration(start_time); |
265 | if (del.rel_value_us == 0) | 263 | if (del.rel_value_us == 0) |
266 | del.rel_value_us = 1; | 264 | del.rel_value_us = 1; |
267 | fancy = | 265 | fancy = |
268 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * | 266 | GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * |
269 | 1000000LL / del.rel_value_us); | 267 | 1000000LL / del.rel_value_us); |
270 | fprintf (stdout, | 268 | fprintf(stdout, |
271 | "Download speed was %s/s\n", | 269 | "Download speed was %s/s\n", |
272 | fancy); | 270 | fancy); |
273 | GNUNET_free (fancy); | 271 | GNUNET_free(fancy); |
274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 272 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
275 | "Finished download, shutting down\n"); | 273 | "Finished download, shutting down\n"); |
276 | sm = GNUNET_new (struct StatMaster); | 274 | sm = GNUNET_new(struct StatMaster); |
277 | sm->op = | 275 | sm->op = |
278 | GNUNET_TESTBED_service_connect (NULL, | 276 | GNUNET_TESTBED_service_connect(NULL, |
279 | daemons[sm->daemon], | 277 | daemons[sm->daemon], |
280 | "statistics", | 278 | "statistics", |
281 | &stat_run, sm, | 279 | &stat_run, sm, |
282 | &statistics_connect_adapter, | 280 | &statistics_connect_adapter, |
283 | &statistics_disconnect_adapter, | 281 | &statistics_disconnect_adapter, |
284 | NULL); | 282 | NULL); |
285 | } | 283 | } |
286 | 284 | ||
287 | 285 | ||
288 | static void | 286 | static void |
289 | do_download (void *cls, | 287 | do_download(void *cls, |
290 | const struct GNUNET_FS_Uri *uri, | 288 | const struct GNUNET_FS_Uri *uri, |
291 | const char *fn) | 289 | const char *fn) |
292 | { | 290 | { |
293 | int anonymity; | 291 | int anonymity; |
294 | 292 | ||
295 | if (NULL == uri) | 293 | if (NULL == uri) |
296 | { | 294 | { |
297 | GNUNET_SCHEDULER_shutdown (); | 295 | GNUNET_SCHEDULER_shutdown(); |
298 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 296 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
299 | "Timeout during upload attempt, shutting down with error\n"); | 297 | "Timeout during upload attempt, shutting down with error\n"); |
300 | ok = 1; | 298 | ok = 1; |
301 | return; | 299 | return; |
302 | } | 300 | } |
303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", | 301 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", |
304 | (unsigned long long) FILESIZE); | 302 | (unsigned long long)FILESIZE); |
305 | start_time = GNUNET_TIME_absolute_get (); | 303 | start_time = GNUNET_TIME_absolute_get(); |
306 | if (NULL != strstr (progname, "dht")) | 304 | if (NULL != strstr(progname, "dht")) |
307 | anonymity = 0; | 305 | anonymity = 0; |
308 | else | 306 | else |
309 | anonymity = 1; | 307 | anonymity = 1; |
310 | start_time = GNUNET_TIME_absolute_get (); | 308 | start_time = GNUNET_TIME_absolute_get(); |
311 | GNUNET_FS_TEST_download (daemons[0], | 309 | GNUNET_FS_TEST_download(daemons[0], |
312 | TIMEOUT, | 310 | TIMEOUT, |
313 | anonymity, | 311 | anonymity, |
314 | SEED, | 312 | SEED, |
315 | uri, | 313 | uri, |
316 | VERBOSE, | 314 | VERBOSE, |
317 | &do_report, | 315 | &do_report, |
318 | (NULL == fn) ? NULL : GNUNET_strdup (fn)); | 316 | (NULL == fn) ? NULL : GNUNET_strdup(fn)); |
319 | } | 317 | } |
320 | 318 | ||
321 | 319 | ||
322 | static void | 320 | static void |
323 | do_publish (void *cls, | 321 | do_publish(void *cls, |
324 | struct GNUNET_TESTBED_RunHandle *h, | 322 | struct GNUNET_TESTBED_RunHandle *h, |
325 | unsigned int num_peers, | 323 | unsigned int num_peers, |
326 | struct GNUNET_TESTBED_Peer **peers, | 324 | struct GNUNET_TESTBED_Peer **peers, |
327 | unsigned int links_succeeded, | 325 | unsigned int links_succeeded, |
328 | unsigned int links_failed) | 326 | unsigned int links_failed) |
329 | { | 327 | { |
330 | unsigned int i; | 328 | unsigned int i; |
331 | int do_index; | 329 | int do_index; |
332 | int anonymity; | 330 | int anonymity; |
333 | 331 | ||
334 | GNUNET_assert (NUM_DAEMONS == num_peers); | 332 | GNUNET_assert(NUM_DAEMONS == num_peers); |
335 | for (i=0;i<num_peers;i++) | 333 | for (i = 0; i < num_peers; i++) |
336 | daemons[i] = peers[i]; | 334 | daemons[i] = peers[i]; |
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", | 335 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", |
338 | (unsigned long long) FILESIZE); | 336 | (unsigned long long)FILESIZE); |
339 | if (NULL != strstr (progname, "index")) | 337 | if (NULL != strstr(progname, "index")) |
340 | do_index = GNUNET_YES; | 338 | do_index = GNUNET_YES; |
341 | else | 339 | else |
342 | do_index = GNUNET_NO; | 340 | do_index = GNUNET_NO; |
343 | if (NULL != strstr (progname, "dht")) | 341 | if (NULL != strstr(progname, "dht")) |
344 | anonymity = 0; | 342 | anonymity = 0; |
345 | else | 343 | else |
346 | anonymity = 1; | 344 | anonymity = 1; |
347 | GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, | 345 | GNUNET_FS_TEST_publish(daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, |
348 | do_index, FILESIZE, SEED, VERBOSE, &do_download, | 346 | do_index, FILESIZE, SEED, VERBOSE, &do_download, |
349 | NULL); | 347 | NULL); |
350 | } | 348 | } |
351 | 349 | ||
352 | 350 | ||
353 | int | 351 | int |
354 | main (int argc, char *argv[]) | 352 | main(int argc, char *argv[]) |
355 | { | 353 | { |
356 | progname = argv[0]; | 354 | progname = argv[0]; |
357 | (void) GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p", | 355 | (void)GNUNET_TESTBED_test_run("perf-gnunet-service-fs-p2p", |
358 | "perf_gnunet_service_fs_p2p.conf", | 356 | "perf_gnunet_service_fs_p2p.conf", |
359 | NUM_DAEMONS, | 357 | NUM_DAEMONS, |
360 | 0, NULL, NULL, | 358 | 0, NULL, NULL, |
361 | &do_publish, NULL); | 359 | &do_publish, NULL); |
362 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | 360 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/"); |
363 | return ok; | 361 | return ok; |
364 | } | 362 | } |
365 | 363 | ||
diff --git a/src/fs/perf_gnunet_service_fs_p2p_respect.c b/src/fs/perf_gnunet_service_fs_p2p_respect.c index 9b14b9eb6..91ec9c66d 100644 --- a/src/fs/perf_gnunet_service_fs_p2p_respect.c +++ b/src/fs/perf_gnunet_service_fs_p2p_respect.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/perf_gnunet_service_fs_p2p_respect.c | 22 | * @file 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,16 +93,14 @@ 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 | { | ||
98 | struct GNUNET_STATISTICS_Handle *stat; | 97 | struct GNUNET_STATISTICS_Handle *stat; |
99 | struct GNUNET_TESTBED_Operation *op; | 98 | struct GNUNET_TESTBED_Operation *op; |
100 | unsigned int daemon; | 99 | unsigned int daemon; |
101 | unsigned int value; | 100 | unsigned int value; |
102 | }; | 101 | }; |
103 | 102 | ||
104 | struct StatValues | 103 | struct StatValues { |
105 | { | ||
106 | const char *subsystem; | 104 | const char *subsystem; |
107 | const char *name; | 105 | const char *name; |
108 | }; | 106 | }; |
@@ -111,44 +109,44 @@ struct StatValues | |||
111 | * Statistics we print out. | 109 | * Statistics we print out. |
112 | */ | 110 | */ |
113 | static struct StatValues stats[] = { | 111 | static struct StatValues stats[] = { |
114 | {"fs", "# artificial delays introduced (ms)"}, | 112 | { "fs", "# artificial delays introduced (ms)" }, |
115 | {"fs", "# queries forwarded"}, | 113 | { "fs", "# queries forwarded" }, |
116 | {"fs", "# replies received and matched"}, | 114 | { "fs", "# replies received and matched" }, |
117 | {"fs", "# results found locally"}, | 115 | { "fs", "# results found locally" }, |
118 | {"fs", "# requests forwarded due to high load"}, | 116 | { "fs", "# requests forwarded due to high load" }, |
119 | {"fs", "# requests done for free (low load)"}, | 117 | { "fs", "# requests done for free (low load)" }, |
120 | {"fs", "# requests dropped, priority insufficient"}, | 118 | { "fs", "# requests dropped, priority insufficient" }, |
121 | {"fs", "# requests done for a price (normal load)"}, | 119 | { "fs", "# requests done for a price (normal load)" }, |
122 | {"fs", "# requests dropped by datastore (queue length limit)"}, | 120 | { "fs", "# requests dropped by datastore (queue length limit)" }, |
123 | {"fs", "# P2P searches received"}, | 121 | { "fs", "# P2P searches received" }, |
124 | {"fs", "# P2P searches discarded (queue length bound)"}, | 122 | { "fs", "# P2P searches discarded (queue length bound)" }, |
125 | {"fs", "# replies received for local clients"}, | 123 | { "fs", "# replies received for local clients" }, |
126 | {"fs", "# queries retransmitted to same target"}, | 124 | { "fs", "# queries retransmitted to same target" }, |
127 | {"core", "# bytes decrypted"}, | 125 | { "core", "# bytes decrypted" }, |
128 | {"core", "# bytes encrypted"}, | 126 | { "core", "# bytes encrypted" }, |
129 | {"core", "# discarded CORE_SEND requests"}, | 127 | { "core", "# discarded CORE_SEND requests" }, |
130 | {"core", "# discarded lower priority CORE_SEND requests"}, | 128 | { "core", "# discarded lower priority CORE_SEND requests" }, |
131 | {"transport", "# bytes received via TCP"}, | 129 | { "transport", "# bytes received via TCP" }, |
132 | {"transport", "# bytes transmitted via TCP"}, | 130 | { "transport", "# bytes transmitted via TCP" }, |
133 | {"datacache", "# bytes stored"}, | 131 | { "datacache", "# bytes stored" }, |
134 | {NULL, NULL} | 132 | { NULL, NULL } |
135 | }; | 133 | }; |
136 | 134 | ||
137 | 135 | ||
138 | static void | 136 | static void |
139 | cleanup () | 137 | cleanup() |
140 | { | 138 | { |
141 | GNUNET_SCHEDULER_shutdown (); | 139 | GNUNET_SCHEDULER_shutdown(); |
142 | if (NULL != fn1) | 140 | if (NULL != fn1) |
143 | { | 141 | { |
144 | GNUNET_DISK_directory_remove (fn1); | 142 | GNUNET_DISK_directory_remove(fn1); |
145 | GNUNET_free (fn1); | 143 | GNUNET_free(fn1); |
146 | } | 144 | } |
147 | if (NULL != fn2) | 145 | if (NULL != fn2) |
148 | { | 146 | { |
149 | GNUNET_DISK_directory_remove (fn2); | 147 | GNUNET_DISK_directory_remove(fn2); |
150 | GNUNET_free (fn2); | 148 | GNUNET_free(fn2); |
151 | } | 149 | } |
152 | } | 150 | } |
153 | 151 | ||
154 | 152 | ||
@@ -163,13 +161,13 @@ cleanup () | |||
163 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 161 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration |
164 | */ | 162 | */ |
165 | static int | 163 | static int |
166 | print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, | 164 | print_stat(void *cls, const char *subsystem, const char *name, uint64_t value, |
167 | int is_persistent) | 165 | int is_persistent) |
168 | { | 166 | { |
169 | struct StatMaster *sm = cls; | 167 | struct StatMaster *sm = cls; |
170 | 168 | ||
171 | fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, | 169 | fprintf(stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, |
172 | name, (unsigned long long) value); | 170 | name, (unsigned long long)value); |
173 | return GNUNET_OK; | 171 | return GNUNET_OK; |
174 | } | 172 | } |
175 | 173 | ||
@@ -178,23 +176,23 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, | |||
178 | * Function that gathers stats from all daemons. | 176 | * Function that gathers stats from all daemons. |
179 | */ | 177 | */ |
180 | static void | 178 | static void |
181 | stat_run (void *cls, | 179 | stat_run(void *cls, |
182 | struct GNUNET_TESTBED_Operation *op, | 180 | struct GNUNET_TESTBED_Operation *op, |
183 | void *ca_result, | 181 | void *ca_result, |
184 | const char *emsg); | 182 | const char *emsg); |
185 | 183 | ||
186 | 184 | ||
187 | /** | 185 | /** |
188 | * Function called when GET operation on stats is done. | 186 | * Function called when GET operation on stats is done. |
189 | */ | 187 | */ |
190 | static void | 188 | static void |
191 | get_done (void *cls, int success) | 189 | get_done(void *cls, int success) |
192 | { | 190 | { |
193 | struct StatMaster *sm = cls; | 191 | struct StatMaster *sm = cls; |
194 | 192 | ||
195 | GNUNET_break (GNUNET_OK == success); | 193 | GNUNET_break(GNUNET_OK == success); |
196 | sm->value++; | 194 | sm->value++; |
197 | stat_run (sm, sm->op, sm->stat, NULL); | 195 | stat_run(sm, sm->op, sm->stat, NULL); |
198 | } | 196 | } |
199 | 197 | ||
200 | 198 | ||
@@ -210,11 +208,11 @@ get_done (void *cls, int success) | |||
210 | * @return service handle to return in 'op_result', NULL on error | 208 | * @return service handle to return in 'op_result', NULL on error |
211 | */ | 209 | */ |
212 | static void * | 210 | static void * |
213 | statistics_connect_adapter (void *cls, | 211 | statistics_connect_adapter(void *cls, |
214 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 212 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
215 | { | 213 | { |
216 | return GNUNET_STATISTICS_create ("<driver>", | 214 | return GNUNET_STATISTICS_create("<driver>", |
217 | cfg); | 215 | cfg); |
218 | } | 216 | } |
219 | 217 | ||
220 | 218 | ||
@@ -226,10 +224,10 @@ statistics_connect_adapter (void *cls, | |||
226 | * @param op_result service handle returned from the connect adapter | 224 | * @param op_result service handle returned from the connect adapter |
227 | */ | 225 | */ |
228 | static void | 226 | static void |
229 | statistics_disconnect_adapter (void *cls, | 227 | statistics_disconnect_adapter(void *cls, |
230 | void *op_result) | 228 | void *op_result) |
231 | { | 229 | { |
232 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); | 230 | GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); |
233 | } | 231 | } |
234 | 232 | ||
235 | 233 | ||
@@ -237,49 +235,49 @@ statistics_disconnect_adapter (void *cls, | |||
237 | * Function that gathers stats from all daemons. | 235 | * Function that gathers stats from all daemons. |
238 | */ | 236 | */ |
239 | static void | 237 | static void |
240 | stat_run (void *cls, | 238 | stat_run(void *cls, |
241 | struct GNUNET_TESTBED_Operation *op, | 239 | struct GNUNET_TESTBED_Operation *op, |
242 | void *ca_result, | 240 | void *ca_result, |
243 | const char *emsg) | 241 | const char *emsg) |
244 | { | 242 | { |
245 | struct StatMaster *sm = cls; | 243 | struct StatMaster *sm = cls; |
246 | 244 | ||
247 | sm->stat = ca_result; | 245 | sm->stat = ca_result; |
248 | GNUNET_assert (NULL != sm->stat); | 246 | GNUNET_assert(NULL != sm->stat); |
249 | if (NULL != stats[sm->value].name) | 247 | if (NULL != stats[sm->value].name) |
250 | { | 248 | { |
251 | GNUNET_STATISTICS_get (sm->stat, | 249 | GNUNET_STATISTICS_get(sm->stat, |
252 | #if 0 | 250 | #if 0 |
253 | NULL, NULL, | 251 | NULL, NULL, |
254 | #else | 252 | #else |
255 | stats[sm->value].subsystem, stats[sm->value].name, | 253 | stats[sm->value].subsystem, stats[sm->value].name, |
256 | #endif | 254 | #endif |
257 | &get_done, &print_stat, | 255 | &get_done, &print_stat, |
258 | sm); | 256 | sm); |
259 | return; | 257 | return; |
260 | } | 258 | } |
261 | GNUNET_TESTBED_operation_done (sm->op); | 259 | GNUNET_TESTBED_operation_done(sm->op); |
262 | sm->value = 0; | 260 | sm->value = 0; |
263 | sm->daemon++; | 261 | sm->daemon++; |
264 | if (NUM_DAEMONS == sm->daemon) | 262 | if (NUM_DAEMONS == sm->daemon) |
265 | { | 263 | { |
266 | GNUNET_free (sm); | 264 | GNUNET_free(sm); |
267 | cleanup (); | 265 | cleanup(); |
268 | return; | 266 | return; |
269 | } | 267 | } |
270 | sm->op = | 268 | sm->op = |
271 | GNUNET_TESTBED_service_connect (NULL, | 269 | GNUNET_TESTBED_service_connect(NULL, |
272 | daemons[sm->daemon], | 270 | daemons[sm->daemon], |
273 | "statistics", | 271 | "statistics", |
274 | &stat_run, sm, | 272 | &stat_run, sm, |
275 | &statistics_connect_adapter, | 273 | &statistics_connect_adapter, |
276 | &statistics_disconnect_adapter, | 274 | &statistics_disconnect_adapter, |
277 | NULL); | 275 | NULL); |
278 | } | 276 | } |
279 | 277 | ||
280 | 278 | ||
281 | static void | 279 | static void |
282 | do_report (void *cls) | 280 | do_report(void *cls) |
283 | { | 281 | { |
284 | static int download_counter; | 282 | static int download_counter; |
285 | const char *type = cls; | 283 | const char *type = cls; |
@@ -288,62 +286,62 @@ do_report (void *cls) | |||
288 | struct StatMaster *sm; | 286 | struct StatMaster *sm; |
289 | 287 | ||
290 | if (0 == | 288 | if (0 == |
291 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, | 289 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, |
292 | TIMEOUT)).rel_value_us) | 290 | TIMEOUT)).rel_value_us) |
293 | { | 291 | { |
294 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 292 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
295 | "Timeout during download for type `%s', shutting down with error\n", | 293 | "Timeout during download for type `%s', shutting down with error\n", |
296 | type); | 294 | type); |
297 | ok = 1; | 295 | ok = 1; |
298 | cleanup (); | 296 | cleanup(); |
299 | return; | 297 | return; |
300 | } | 298 | } |
301 | del = GNUNET_TIME_absolute_get_duration (start_time); | 299 | del = GNUNET_TIME_absolute_get_duration(start_time); |
302 | if (del.rel_value_us == 0) | 300 | if (del.rel_value_us == 0) |
303 | del.rel_value_us = 1; | 301 | del.rel_value_us = 1; |
304 | fancy = | 302 | fancy = |
305 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * | 303 | GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * |
306 | 1000000LL / del.rel_value_us); | 304 | 1000000LL / del.rel_value_us); |
307 | fprintf (stderr, "Download speed of type `%s' was %s/s\n", type, fancy); | 305 | fprintf(stderr, "Download speed of type `%s' was %s/s\n", type, fancy); |
308 | GNUNET_free (fancy); | 306 | GNUNET_free(fancy); |
309 | if (NUM_DAEMONS != ++download_counter) | 307 | if (NUM_DAEMONS != ++download_counter) |
310 | return; /* more downloads to come */ | 308 | return; /* more downloads to come */ |
311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 309 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
312 | "Finished all downloads, getting statistics\n"); | 310 | "Finished all downloads, getting statistics\n"); |
313 | sm = GNUNET_new (struct StatMaster); | 311 | sm = GNUNET_new(struct StatMaster); |
314 | sm->op = | 312 | sm->op = |
315 | GNUNET_TESTBED_service_connect (NULL, | 313 | GNUNET_TESTBED_service_connect(NULL, |
316 | daemons[sm->daemon], | 314 | daemons[sm->daemon], |
317 | "statistics", | 315 | "statistics", |
318 | &stat_run, sm, | 316 | &stat_run, sm, |
319 | &statistics_connect_adapter, | 317 | &statistics_connect_adapter, |
320 | &statistics_disconnect_adapter, | 318 | &statistics_disconnect_adapter, |
321 | NULL); | 319 | NULL); |
322 | } | 320 | } |
323 | 321 | ||
324 | 322 | ||
325 | static void | 323 | static void |
326 | do_downloads (void *cls, const struct GNUNET_FS_Uri *u2, | 324 | do_downloads(void *cls, const struct GNUNET_FS_Uri *u2, |
327 | const char *fn) | 325 | const char *fn) |
328 | { | 326 | { |
329 | int anonymity; | 327 | int anonymity; |
330 | unsigned int i; | 328 | unsigned int i; |
331 | 329 | ||
332 | if (NULL == u2) | 330 | if (NULL == u2) |
333 | { | 331 | { |
334 | cleanup (); | 332 | cleanup(); |
335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 333 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
336 | "Timeout during upload attempt, shutting down with error\n"); | 334 | "Timeout during upload attempt, shutting down with error\n"); |
337 | ok = 1; | 335 | ok = 1; |
338 | return; | 336 | return; |
339 | } | 337 | } |
340 | if (NULL != fn) | 338 | if (NULL != fn) |
341 | fn2 = GNUNET_strdup (fn); | 339 | fn2 = GNUNET_strdup(fn); |
342 | uri2 = GNUNET_FS_uri_dup (u2); | 340 | uri2 = GNUNET_FS_uri_dup(u2); |
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", | 341 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", |
344 | (unsigned long long) FILESIZE); | 342 | (unsigned long long)FILESIZE); |
345 | start_time = GNUNET_TIME_absolute_get (); | 343 | start_time = GNUNET_TIME_absolute_get(); |
346 | if (NULL != strstr (progname, "dht")) | 344 | if (NULL != strstr(progname, "dht")) |
347 | anonymity = 0; | 345 | anonymity = 0; |
348 | else | 346 | else |
349 | anonymity = 1; | 347 | anonymity = 1; |
@@ -351,127 +349,127 @@ do_downloads (void *cls, const struct GNUNET_FS_Uri *u2, | |||
351 | * these peers do participate in sharing, they just | 349 | * these peers do participate in sharing, they just |
352 | * don't have to offer anything *initially*. */ | 350 | * don't have to offer anything *initially*. */ |
353 | for (i = 0; i < NUM_DAEMONS - 2; i++) | 351 | for (i = 0; i < NUM_DAEMONS - 2; i++) |
354 | GNUNET_FS_TEST_download (daemons[i], TIMEOUT, anonymity, | 352 | GNUNET_FS_TEST_download(daemons[i], TIMEOUT, anonymity, |
355 | 0 == (i % 2) ? SEED1 : SEED2, | 353 | 0 == (i % 2) ? SEED1 : SEED2, |
356 | 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report, | 354 | 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report, |
357 | "leach"); | 355 | "leach"); |
358 | /* mutual downloads of (primary) sharing peers */ | 356 | /* mutual downloads of (primary) sharing peers */ |
359 | GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1, | 357 | GNUNET_FS_TEST_download(daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1, |
360 | uri1, VERBOSE, &do_report, "seeder 2"); | 358 | uri1, VERBOSE, &do_report, "seeder 2"); |
361 | GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2, | 359 | GNUNET_FS_TEST_download(daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2, |
362 | uri2, VERBOSE, &do_report, "seeder 1"); | 360 | uri2, VERBOSE, &do_report, "seeder 1"); |
363 | } | 361 | } |
364 | 362 | ||
365 | 363 | ||
366 | static void | 364 | static void |
367 | do_publish2 (void *cls, | 365 | do_publish2(void *cls, |
368 | const struct GNUNET_FS_Uri *u1, | 366 | const struct GNUNET_FS_Uri *u1, |
369 | const char *fn) | 367 | const char *fn) |
370 | { | 368 | { |
371 | int do_index; | 369 | int do_index; |
372 | int anonymity; | 370 | int anonymity; |
373 | 371 | ||
374 | if (NULL == u1) | 372 | if (NULL == u1) |
375 | { | 373 | { |
376 | cleanup (); | 374 | cleanup(); |
377 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 375 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
378 | "Timeout during upload attempt, shutting down with error\n"); | 376 | "Timeout during upload attempt, shutting down with error\n"); |
379 | ok = 1; | 377 | ok = 1; |
380 | return; | 378 | return; |
381 | } | 379 | } |
382 | if (NULL != fn) | 380 | if (NULL != fn) |
383 | fn1 = GNUNET_strdup (fn); | 381 | fn1 = GNUNET_strdup(fn); |
384 | uri1 = GNUNET_FS_uri_dup (u1); | 382 | uri1 = GNUNET_FS_uri_dup(u1); |
385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", | 383 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", |
386 | (unsigned long long) FILESIZE); | 384 | (unsigned long long)FILESIZE); |
387 | if (NULL != strstr (progname, "index")) | 385 | if (NULL != strstr(progname, "index")) |
388 | do_index = GNUNET_YES; | 386 | do_index = GNUNET_YES; |
389 | else | 387 | else |
390 | do_index = GNUNET_NO; | 388 | do_index = GNUNET_NO; |
391 | if (NULL != strstr (progname, "dht")) | 389 | if (NULL != strstr(progname, "dht")) |
392 | anonymity = 0; | 390 | anonymity = 0; |
393 | else | 391 | else |
394 | anonymity = 1; | 392 | anonymity = 1; |
395 | 393 | ||
396 | GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, | 394 | GNUNET_FS_TEST_publish(daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, |
397 | do_index, FILESIZE, SEED2, VERBOSE, &do_downloads, | 395 | do_index, FILESIZE, SEED2, VERBOSE, &do_downloads, |
398 | NULL); | 396 | NULL); |
399 | } | 397 | } |
400 | 398 | ||
401 | 399 | ||
402 | static void | 400 | static void |
403 | do_publish1 (void *cls, | 401 | do_publish1(void *cls, |
404 | struct GNUNET_TESTBED_Operation *op, | 402 | struct GNUNET_TESTBED_Operation *op, |
405 | const char *emsg) | 403 | const char *emsg) |
406 | { | 404 | { |
407 | unsigned int *coco = cls; | 405 | unsigned int *coco = cls; |
408 | int do_index; | 406 | int do_index; |
409 | int anonymity; | 407 | int anonymity; |
410 | 408 | ||
411 | GNUNET_TESTBED_operation_done (op); | 409 | GNUNET_TESTBED_operation_done(op); |
412 | if (NULL != emsg) | 410 | if (NULL != emsg) |
413 | { | 411 | { |
414 | cleanup (); | 412 | cleanup(); |
415 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg); | 413 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg); |
416 | ok = 1; | 414 | ok = 1; |
417 | return; | 415 | return; |
418 | } | 416 | } |
419 | if (0 != (--(*coco))) | 417 | if (0 != (--(*coco))) |
420 | return; /* more connections to be created */ | 418 | return; /* more connections to be created */ |
421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", | 419 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", |
422 | (unsigned long long) FILESIZE); | 420 | (unsigned long long)FILESIZE); |
423 | if (NULL != strstr (progname, "index")) | 421 | if (NULL != strstr(progname, "index")) |
424 | do_index = GNUNET_YES; | 422 | do_index = GNUNET_YES; |
425 | else | 423 | else |
426 | do_index = GNUNET_NO; | 424 | do_index = GNUNET_NO; |
427 | if (NULL != strstr (progname, "dht")) | 425 | if (NULL != strstr(progname, "dht")) |
428 | anonymity = 0; | 426 | anonymity = 0; |
429 | else | 427 | else |
430 | anonymity = 1; | 428 | anonymity = 1; |
431 | GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, | 429 | GNUNET_FS_TEST_publish(daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, |
432 | do_index, FILESIZE, SEED1, VERBOSE, &do_publish2, | 430 | do_index, FILESIZE, SEED1, VERBOSE, &do_publish2, |
433 | NULL); | 431 | NULL); |
434 | } | 432 | } |
435 | 433 | ||
436 | 434 | ||
437 | static void | 435 | static void |
438 | do_connect (void *cls, | 436 | do_connect(void *cls, |
439 | struct GNUNET_TESTBED_RunHandle *h, | 437 | struct GNUNET_TESTBED_RunHandle *h, |
440 | unsigned int num_peers, | 438 | unsigned int num_peers, |
441 | struct GNUNET_TESTBED_Peer **peers, | 439 | struct GNUNET_TESTBED_Peer **peers, |
442 | unsigned int links_succeeded, | 440 | unsigned int links_succeeded, |
443 | unsigned int links_failed) | 441 | unsigned int links_failed) |
444 | { | 442 | { |
445 | static unsigned int coco; | 443 | static unsigned int coco; |
446 | unsigned int i; | 444 | unsigned int i; |
447 | unsigned int j; | 445 | unsigned int j; |
448 | 446 | ||
449 | GNUNET_assert (NUM_DAEMONS == num_peers); | 447 | GNUNET_assert(NUM_DAEMONS == num_peers); |
450 | for (i=0;i<num_peers;i++) | 448 | for (i = 0; i < num_peers; i++) |
451 | daemons[i] = peers[i]; | 449 | daemons[i] = peers[i]; |
452 | for (i=0;i<NUM_DAEMONS;i++) | 450 | for (i = 0; i < NUM_DAEMONS; i++) |
453 | for (j=i+1;j<NUM_DAEMONS;j++) | 451 | for (j = i + 1; j < NUM_DAEMONS; j++) |
454 | { | 452 | { |
455 | coco++; | 453 | coco++; |
456 | GNUNET_TESTBED_overlay_connect (NULL, | 454 | GNUNET_TESTBED_overlay_connect(NULL, |
457 | &do_publish1, | 455 | &do_publish1, |
458 | &coco, | 456 | &coco, |
459 | peers[i], | 457 | peers[i], |
460 | peers[j]); | 458 | peers[j]); |
461 | } | 459 | } |
462 | } | 460 | } |
463 | 461 | ||
464 | 462 | ||
465 | int | 463 | int |
466 | main (int argc, char *argv[]) | 464 | main(int argc, char *argv[]) |
467 | { | 465 | { |
468 | progname = argv[0]; | 466 | progname = argv[0]; |
469 | (void) GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p-respect", | 467 | (void)GNUNET_TESTBED_test_run("perf-gnunet-service-fs-p2p-respect", |
470 | "perf_gnunet_service_fs_p2p.conf", | 468 | "perf_gnunet_service_fs_p2p.conf", |
471 | NUM_DAEMONS, | 469 | NUM_DAEMONS, |
472 | 0, NULL, NULL, | 470 | 0, NULL, NULL, |
473 | &do_connect, NULL); | 471 | &do_connect, NULL); |
474 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | 472 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/"); |
475 | return ok; | 473 | return ok; |
476 | } | 474 | } |
477 | 475 | ||
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c index f0df52c99..8003e3837 100644 --- a/src/fs/plugin_block_fs.c +++ b/src/fs/plugin_block_fs.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/plugin_block_fs.c | 22 | * @file fs/plugin_block_fs.c |
@@ -51,58 +51,61 @@ | |||
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 | { | ||
66 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | ||
67 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
68 | return NULL; | ||
69 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
70 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
71 | return NULL; | ||
72 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
73 | guard = va_arg (va, const char *); | ||
74 | if (0 == strcmp (guard, | ||
75 | "seen-set-size")) | ||
76 | { | ||
77 | size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), | ||
78 | BLOOMFILTER_K); | ||
79 | } | ||
80 | else if (0 == strcmp (guard, | ||
81 | "filter-size")) | ||
82 | { | ||
83 | size = va_arg (va, unsigned int); | ||
84 | } | ||
85 | else | ||
86 | { | 65 | { |
87 | /* va-args invalid! bad bug, complain! */ | 66 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
88 | GNUNET_break (0); | 67 | GNUNET_break(NULL == va_arg(va, const char *)); |
89 | size = 8; | 68 | return NULL; |
69 | |||
70 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
71 | GNUNET_break(NULL == va_arg(va, const char *)); | ||
72 | return NULL; | ||
73 | |||
74 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
75 | guard = va_arg(va, const char *); | ||
76 | if (0 == strcmp(guard, | ||
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 | |||
104 | default: | ||
105 | GNUNET_break(NULL == va_arg(va, const char *)); | ||
106 | GNUNET_break(0); | ||
107 | return NULL; | ||
90 | } | 108 | } |
91 | if (0 == size) | ||
92 | size = raw_data_size; /* not for us to determine, use what we got! */ | ||
93 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
94 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
95 | size, | ||
96 | BLOOMFILTER_K, | ||
97 | type, | ||
98 | nonce, | ||
99 | raw_data, | ||
100 | raw_data_size); | ||
101 | default: | ||
102 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
103 | GNUNET_break (0); | ||
104 | return NULL; | ||
105 | } | ||
106 | } | 109 | } |
107 | 110 | ||
108 | 111 | ||
@@ -126,84 +129,86 @@ block_plugin_fs_create_group (void *cls, | |||
126 | * @return characterization of result | 129 | * @return characterization of result |
127 | */ | 130 | */ |
128 | static enum GNUNET_BLOCK_EvaluationResult | 131 | static enum GNUNET_BLOCK_EvaluationResult |
129 | block_plugin_fs_evaluate (void *cls, | 132 | block_plugin_fs_evaluate(void *cls, |
130 | struct GNUNET_BLOCK_Context *ctx, | 133 | struct GNUNET_BLOCK_Context *ctx, |
131 | enum GNUNET_BLOCK_Type type, | 134 | enum GNUNET_BLOCK_Type type, |
132 | struct GNUNET_BLOCK_Group *bg, | 135 | struct GNUNET_BLOCK_Group *bg, |
133 | enum GNUNET_BLOCK_EvaluationOptions eo, | 136 | enum GNUNET_BLOCK_EvaluationOptions eo, |
134 | const struct GNUNET_HashCode *query, | 137 | const struct GNUNET_HashCode *query, |
135 | const void *xquery, | 138 | const void *xquery, |
136 | size_t xquery_size, | 139 | size_t xquery_size, |
137 | const void *reply_block, | 140 | const void *reply_block, |
138 | size_t reply_block_size) | 141 | size_t reply_block_size) |
139 | { | 142 | { |
140 | const struct UBlock *ub; | 143 | const struct UBlock *ub; |
141 | struct GNUNET_HashCode hc; | 144 | struct GNUNET_HashCode hc; |
142 | struct GNUNET_HashCode chash; | 145 | struct GNUNET_HashCode chash; |
143 | 146 | ||
144 | switch (type) | 147 | switch (type) |
145 | { | ||
146 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | ||
147 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
148 | if (0 != xquery_size) | ||
149 | { | ||
150 | GNUNET_break_op (0); | ||
151 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
152 | } | ||
153 | if (NULL == reply_block) | ||
154 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
155 | return GNUNET_BLOCK_EVALUATION_OK_LAST; | ||
156 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
157 | if (0 != xquery_size) | ||
158 | { | 148 | { |
159 | GNUNET_break_op (0); | 149 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
160 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | 150 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: |
161 | } | 151 | if (0 != xquery_size) |
162 | if (NULL == reply_block) | 152 | { |
163 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 153 | GNUNET_break_op(0); |
154 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
155 | } | ||
156 | if (NULL == reply_block) | ||
157 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
158 | return GNUNET_BLOCK_EVALUATION_OK_LAST; | ||
164 | 159 | ||
165 | if (reply_block_size < sizeof (struct UBlock)) | 160 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
166 | { | 161 | if (0 != xquery_size) |
167 | GNUNET_break_op (0); | 162 | { |
168 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 163 | GNUNET_break_op(0); |
169 | } | 164 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; |
170 | ub = reply_block; | 165 | } |
171 | GNUNET_CRYPTO_hash (&ub->verification_key, | 166 | if (NULL == reply_block) |
172 | sizeof (ub->verification_key), | 167 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
173 | &hc); | 168 | |
174 | if (0 != memcmp (&hc, | 169 | if (reply_block_size < sizeof(struct UBlock)) |
175 | query, | 170 | { |
176 | sizeof (struct GNUNET_HashCode))) | 171 | GNUNET_break_op(0); |
177 | { | 172 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
178 | GNUNET_break_op (0); | 173 | } |
179 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 174 | ub = reply_block; |
180 | } | 175 | GNUNET_CRYPTO_hash(&ub->verification_key, |
181 | if (reply_block_size != ntohl (ub->purpose.size) + sizeof (struct GNUNET_CRYPTO_EcdsaSignature)) | 176 | sizeof(ub->verification_key), |
182 | { | 177 | &hc); |
183 | GNUNET_break_op (0); | 178 | if (0 != memcmp(&hc, |
184 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 179 | query, |
185 | } | 180 | sizeof(struct GNUNET_HashCode))) |
186 | if ( (0 == (eo & GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO)) && | 181 | { |
187 | (GNUNET_OK != | 182 | GNUNET_break_op(0); |
188 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK, | 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, | ||
189 | &ub->purpose, | 193 | &ub->purpose, |
190 | &ub->signature, | 194 | &ub->signature, |
191 | &ub->verification_key)) ) | 195 | &ub->verification_key))) |
192 | { | 196 | { |
193 | GNUNET_break_op (0); | 197 | GNUNET_break_op(0); |
194 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 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 | |||
209 | default: | ||
210 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
195 | } | 211 | } |
196 | GNUNET_CRYPTO_hash (reply_block, | ||
197 | reply_block_size, | ||
198 | &chash); | ||
199 | if (GNUNET_YES == | ||
200 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
201 | &chash)) | ||
202 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
203 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
204 | default: | ||
205 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
206 | } | ||
207 | } | 212 | } |
208 | 213 | ||
209 | 214 | ||
@@ -219,35 +224,37 @@ block_plugin_fs_evaluate (void *cls, | |||
219 | * (or if extracting a key from a block of this type does not work) | 224 | * (or if extracting a key from a block of this type does not work) |
220 | */ | 225 | */ |
221 | static int | 226 | static int |
222 | block_plugin_fs_get_key (void *cls, | 227 | block_plugin_fs_get_key(void *cls, |
223 | enum GNUNET_BLOCK_Type type, | 228 | enum GNUNET_BLOCK_Type type, |
224 | const void *block, | 229 | const void *block, |
225 | size_t block_size, | 230 | size_t block_size, |
226 | struct GNUNET_HashCode *key) | 231 | struct GNUNET_HashCode *key) |
227 | { | 232 | { |
228 | const struct UBlock *ub; | 233 | const struct UBlock *ub; |
229 | 234 | ||
230 | switch (type) | 235 | switch (type) |
231 | { | ||
232 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | ||
233 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
234 | GNUNET_CRYPTO_hash (block, block_size, key); | ||
235 | return GNUNET_OK; | ||
236 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
237 | if (block_size < sizeof (struct UBlock)) | ||
238 | { | 236 | { |
239 | GNUNET_break (0); | 237 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
238 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
239 | GNUNET_CRYPTO_hash(block, block_size, key); | ||
240 | 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 | |||
254 | default: | ||
255 | GNUNET_break(0); | ||
240 | return GNUNET_SYSERR; | 256 | return GNUNET_SYSERR; |
241 | } | 257 | } |
242 | ub = block; | ||
243 | GNUNET_CRYPTO_hash (&ub->verification_key, | ||
244 | sizeof (ub->verification_key), | ||
245 | key); | ||
246 | return GNUNET_OK; | ||
247 | default: | ||
248 | GNUNET_break (0); | ||
249 | return GNUNET_SYSERR; | ||
250 | } | ||
251 | } | 258 | } |
252 | 259 | ||
253 | 260 | ||
@@ -255,7 +262,7 @@ block_plugin_fs_get_key (void *cls, | |||
255 | * Entry point for the plugin. | 262 | * Entry point for the plugin. |
256 | */ | 263 | */ |
257 | void * | 264 | void * |
258 | libgnunet_plugin_block_fs_init (void *cls) | 265 | libgnunet_plugin_block_fs_init(void *cls) |
259 | { | 266 | { |
260 | static enum GNUNET_BLOCK_Type types[] = | 267 | static enum GNUNET_BLOCK_Type types[] = |
261 | { | 268 | { |
@@ -266,7 +273,7 @@ libgnunet_plugin_block_fs_init (void *cls) | |||
266 | }; | 273 | }; |
267 | struct GNUNET_BLOCK_PluginFunctions *api; | 274 | struct GNUNET_BLOCK_PluginFunctions *api; |
268 | 275 | ||
269 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 276 | api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); |
270 | api->evaluate = &block_plugin_fs_evaluate; | 277 | api->evaluate = &block_plugin_fs_evaluate; |
271 | api->get_key = &block_plugin_fs_get_key; | 278 | api->get_key = &block_plugin_fs_get_key; |
272 | api->create_group = &block_plugin_fs_create_group; | 279 | api->create_group = &block_plugin_fs_create_group; |
@@ -279,11 +286,11 @@ libgnunet_plugin_block_fs_init (void *cls) | |||
279 | * Exit point from the plugin. | 286 | * Exit point from the plugin. |
280 | */ | 287 | */ |
281 | void * | 288 | void * |
282 | libgnunet_plugin_block_fs_done (void *cls) | 289 | libgnunet_plugin_block_fs_done(void *cls) |
283 | { | 290 | { |
284 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | 291 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
285 | 292 | ||
286 | GNUNET_free (api); | 293 | GNUNET_free(api); |
287 | return NULL; | 294 | return NULL; |
288 | } | 295 | } |
289 | 296 | ||
diff --git a/src/fs/test_fs.c b/src/fs/test_fs.c index e88c74464..e88bacf59 100644 --- a/src/fs/test_fs.c +++ b/src/fs/test_fs.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_fs.c | 22 | * @file fs/test_fs.c |
@@ -33,16 +33,16 @@ | |||
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); goto FAILURE; } |
34 | 34 | ||
35 | static char * | 35 | static char * |
36 | makeName (unsigned int i) | 36 | makeName(unsigned int i) |
37 | { | 37 | { |
38 | char *fn; | 38 | char *fn; |
39 | 39 | ||
40 | fn = GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + | 40 | fn = GNUNET_malloc(strlen("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + |
41 | 14); | 41 | 14); |
42 | GNUNET_snprintf (fn, | 42 | GNUNET_snprintf(fn, |
43 | strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 14, | 43 | strlen("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 14, |
44 | "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i); | 44 | "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i); |
45 | GNUNET_disk_directory_create_for_file (NULL, fn); | 45 | GNUNET_disk_directory_create_for_file(NULL, fn); |
46 | return fn; | 46 | return fn; |
47 | } | 47 | } |
48 | 48 | ||
@@ -55,42 +55,47 @@ static struct GNUNET_ECRS_URI *search_uri; | |||
55 | static struct GNUNET_FSUI_Context *ctx; | 55 | static struct GNUNET_FSUI_Context *ctx; |
56 | 56 | ||
57 | static void * | 57 | static void * |
58 | eventCallback (void *cls, const GNUNET_FSUI_Event * event) | 58 | eventCallback(void *cls, const GNUNET_FSUI_Event * event) |
59 | { | 59 | { |
60 | static char unused; | 60 | static char unused; |
61 | 61 | ||
62 | switch (event->type) | 62 | switch (event->type) |
63 | { | 63 | { |
64 | case GNUNET_FSUI_search_resumed: | 64 | case GNUNET_FSUI_search_resumed: |
65 | case GNUNET_FSUI_download_resumed: | 65 | case GNUNET_FSUI_download_resumed: |
66 | case GNUNET_FSUI_upload_resumed: | 66 | case GNUNET_FSUI_upload_resumed: |
67 | case GNUNET_FSUI_unindex_resumed: | 67 | case GNUNET_FSUI_unindex_resumed: |
68 | return &unused; | 68 | return &unused; |
69 | case GNUNET_FSUI_search_result: | 69 | |
70 | case GNUNET_FSUI_search_result: | ||
70 | #if DEBUG_VERBOSE | 71 | #if DEBUG_VERBOSE |
71 | printf ("Received search result\n"); | 72 | printf("Received search result\n"); |
72 | #endif | 73 | #endif |
73 | search_uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri); | 74 | search_uri = GNUNET_ECRS_uri_duplicate(event->data.SearchResult.fi.uri); |
74 | search_meta = GNUNET_meta_data_duplicate (event->data.SearchResult.fi.meta); | 75 | search_meta = GNUNET_meta_data_duplicate(event->data.SearchResult.fi.meta); |
75 | break; | 76 | break; |
76 | case GNUNET_FSUI_upload_completed: | 77 | |
78 | case GNUNET_FSUI_upload_completed: | ||
77 | #if DEBUG_VERBOSE | 79 | #if DEBUG_VERBOSE |
78 | printf ("Upload complete.\n"); | 80 | printf("Upload complete.\n"); |
79 | #endif | 81 | #endif |
80 | break; | 82 | break; |
81 | case GNUNET_FSUI_download_completed: | 83 | |
84 | case GNUNET_FSUI_download_completed: | ||
82 | #if DEBUG_VERBOSE | 85 | #if DEBUG_VERBOSE |
83 | printf ("Download complete.\n"); | 86 | printf("Download complete.\n"); |
84 | #endif | 87 | #endif |
85 | break; | 88 | break; |
86 | case GNUNET_FSUI_unindex_completed: | 89 | |
90 | case GNUNET_FSUI_unindex_completed: | ||
87 | #if DEBUG_VERBOSE | 91 | #if DEBUG_VERBOSE |
88 | printf ("Unindex complete.\n"); | 92 | printf("Unindex complete.\n"); |
89 | #endif | 93 | #endif |
90 | break; | 94 | break; |
91 | default: | 95 | |
92 | break; | 96 | default: |
93 | } | 97 | break; |
98 | } | ||
94 | lastEvent = event->type; | 99 | lastEvent = event->type; |
95 | return NULL; | 100 | return NULL; |
96 | } | 101 | } |
@@ -98,7 +103,7 @@ eventCallback (void *cls, const GNUNET_FSUI_Event * event) | |||
98 | #define START_DAEMON 1 | 103 | #define START_DAEMON 1 |
99 | 104 | ||
100 | int | 105 | int |
101 | main (int argc, char *argv[]) | 106 | main(int argc, char *argv[]) |
102 | { | 107 | { |
103 | #if START_DAEMON | 108 | #if START_DAEMON |
104 | struct GNUNET_OS_Process *daemon; | 109 | struct GNUNET_OS_Process *daemon; |
@@ -122,128 +127,128 @@ main (int argc, char *argv[]) | |||
122 | struct GNUNET_FSUI_UnindexList *unindex = NULL; | 127 | struct GNUNET_FSUI_UnindexList *unindex = NULL; |
123 | struct GNUNET_FSUI_DownloadList *download = NULL; | 128 | struct GNUNET_FSUI_DownloadList *download = NULL; |
124 | 129 | ||
125 | cfg = GNUNET_GC_create (); | 130 | cfg = GNUNET_GC_create(); |
126 | if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) | 131 | if (-1 == GNUNET_GC_parse_configuration(cfg, "check.conf")) |
127 | { | 132 | { |
128 | GNUNET_GC_free (cfg); | 133 | GNUNET_GC_free(cfg); |
129 | return -1; | 134 | return -1; |
130 | } | 135 | } |
131 | #if START_DAEMON | 136 | #if START_DAEMON |
132 | daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); | 137 | daemon = GNUNET_daemon_start(NULL, cfg, "peer.conf", GNUNET_NO); |
133 | GNUNET_GE_ASSERT (NULL, daemon != NULL); | 138 | GNUNET_GE_ASSERT(NULL, daemon != NULL); |
134 | CHECK (GNUNET_OK == | 139 | CHECK(GNUNET_OK == |
135 | GNUNET_wait_for_daemon_running (NULL, cfg, 60 * GNUNET_CRON_SECONDS)); | 140 | GNUNET_wait_for_daemon_running(NULL, cfg, 60 * GNUNET_CRON_SECONDS)); |
136 | #endif | 141 | #endif |
137 | GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ | 142 | GNUNET_thread_sleep(5 * GNUNET_CRON_SECONDS); /* give apps time to start */ |
138 | ok = GNUNET_YES; | 143 | ok = GNUNET_YES; |
139 | 144 | ||
140 | /* ACTUAL TEST CODE */ | 145 | /* ACTUAL TEST CODE */ |
141 | ctx = GNUNET_FSUI_start (NULL, cfg, "basic_fsui_test", 32, /* thread pool size */ | 146 | ctx = GNUNET_FSUI_start(NULL, cfg, "basic_fsui_test", 32, /* thread pool size */ |
142 | GNUNET_NO, /* no resume */ | 147 | GNUNET_NO, /* no resume */ |
143 | &eventCallback, NULL); | 148 | &eventCallback, NULL); |
144 | CHECK (ctx != NULL); | 149 | CHECK(ctx != NULL); |
145 | filename = makeName (42); | 150 | filename = makeName(42); |
146 | GNUNET_disk_file_write (NULL, filename, "foo bar test!", | 151 | GNUNET_disk_file_write(NULL, filename, "foo bar test!", |
147 | strlen ("foo bar test!"), "600"); | 152 | strlen("foo bar test!"), "600"); |
148 | meta = GNUNET_meta_data_create (); | 153 | meta = GNUNET_meta_data_create(); |
149 | kuri = | 154 | kuri = |
150 | GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2, | 155 | GNUNET_ECRS_keyword_command_line_to_uri(NULL, 2, |
151 | (const char **) keywords); | 156 | (const char **)keywords); |
152 | /* upload */ | 157 | /* upload */ |
153 | upload = GNUNET_FSUI_upload_start (ctx, filename, (GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0, /* anonymity */ | 158 | upload = GNUNET_FSUI_upload_start(ctx, filename, (GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0, /* anonymity */ |
154 | 0, /* priority */ | 159 | 0, /* priority */ |
155 | GNUNET_YES, GNUNET_NO, GNUNET_NO, | 160 | GNUNET_YES, GNUNET_NO, GNUNET_NO, |
156 | GNUNET_get_time () + 5 * GNUNET_CRON_HOURS, | 161 | GNUNET_get_time() + 5 * GNUNET_CRON_HOURS, |
157 | meta, kuri, kuri); | 162 | meta, kuri, kuri); |
158 | CHECK (upload != NULL); | 163 | CHECK(upload != NULL); |
159 | GNUNET_ECRS_uri_destroy (kuri); | 164 | GNUNET_ECRS_uri_destroy(kuri); |
160 | GNUNET_meta_data_destroy (meta); | 165 | GNUNET_meta_data_destroy(meta); |
161 | prog = 0; | 166 | prog = 0; |
162 | while (lastEvent != GNUNET_FSUI_upload_completed) | 167 | while (lastEvent != GNUNET_FSUI_upload_completed) |
163 | { | 168 | { |
164 | prog++; | 169 | prog++; |
165 | CHECK (prog < 10000) GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); | 170 | CHECK(prog < 10000) GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS); |
166 | if (GNUNET_shutdown_test () == GNUNET_YES) | 171 | if (GNUNET_shutdown_test() == GNUNET_YES) |
167 | break; | 172 | break; |
168 | } | 173 | } |
169 | 174 | ||
170 | /* search */ | 175 | /* search */ |
171 | GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]); | 176 | GNUNET_snprintf(keyword, 40, "+%s +%s", keywords[0], keywords[1]); |
172 | uri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword); | 177 | uri = GNUNET_ECRS_keyword_string_to_uri(NULL, keyword); |
173 | search = GNUNET_FSUI_search_start (ctx, 0, uri); | 178 | search = GNUNET_FSUI_search_start(ctx, 0, uri); |
174 | GNUNET_ECRS_uri_destroy (uri); | 179 | GNUNET_ECRS_uri_destroy(uri); |
175 | CHECK (search != NULL); | 180 | CHECK(search != NULL); |
176 | prog = 0; | 181 | prog = 0; |
177 | while (lastEvent != GNUNET_FSUI_search_result) | 182 | while (lastEvent != GNUNET_FSUI_search_result) |
178 | { | 183 | { |
179 | prog++; | 184 | prog++; |
180 | CHECK (prog < 10000); | 185 | CHECK(prog < 10000); |
181 | GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); | 186 | GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS); |
182 | if (GNUNET_shutdown_test () == GNUNET_YES) | 187 | if (GNUNET_shutdown_test() == GNUNET_YES) |
183 | break; | 188 | break; |
184 | } | 189 | } |
185 | GNUNET_FSUI_search_abort (search); | 190 | GNUNET_FSUI_search_abort(search); |
186 | GNUNET_FSUI_search_stop (search); | 191 | GNUNET_FSUI_search_stop(search); |
187 | 192 | ||
188 | /* download */ | 193 | /* download */ |
189 | fn = makeName (43); | 194 | fn = makeName(43); |
190 | download = | 195 | download = |
191 | GNUNET_FSUI_download_start (ctx, 0, GNUNET_NO, search_uri, search_meta, | 196 | GNUNET_FSUI_download_start(ctx, 0, GNUNET_NO, search_uri, search_meta, |
192 | fn, NULL, NULL); | 197 | fn, NULL, NULL); |
193 | GNUNET_free (fn); | 198 | GNUNET_free(fn); |
194 | prog = 0; | 199 | prog = 0; |
195 | while (lastEvent != GNUNET_FSUI_download_completed) | 200 | while (lastEvent != GNUNET_FSUI_download_completed) |
196 | { | 201 | { |
197 | prog++; | 202 | prog++; |
198 | CHECK (prog < 10000); | 203 | CHECK(prog < 10000); |
199 | GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); | 204 | GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS); |
200 | if (GNUNET_shutdown_test () == GNUNET_YES) | 205 | if (GNUNET_shutdown_test() == GNUNET_YES) |
201 | break; | 206 | break; |
202 | } | 207 | } |
203 | GNUNET_FSUI_download_stop (download); | 208 | GNUNET_FSUI_download_stop(download); |
204 | download = NULL; | 209 | download = NULL; |
205 | GNUNET_ECRS_uri_destroy (search_uri); | 210 | GNUNET_ECRS_uri_destroy(search_uri); |
206 | GNUNET_meta_data_destroy (search_meta); | 211 | GNUNET_meta_data_destroy(search_meta); |
207 | /* unindex */ | 212 | /* unindex */ |
208 | unindex = GNUNET_FSUI_unindex_start (ctx, filename); | 213 | unindex = GNUNET_FSUI_unindex_start(ctx, filename); |
209 | prog = 0; | 214 | prog = 0; |
210 | while (lastEvent != GNUNET_FSUI_unindex_completed) | 215 | while (lastEvent != GNUNET_FSUI_unindex_completed) |
211 | { | 216 | { |
212 | prog++; | 217 | prog++; |
213 | CHECK (prog < 10000); | 218 | CHECK(prog < 10000); |
214 | GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); | 219 | GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS); |
215 | if (GNUNET_shutdown_test () == GNUNET_YES) | 220 | if (GNUNET_shutdown_test() == GNUNET_YES) |
216 | break; | 221 | break; |
217 | } | 222 | } |
218 | if (lastEvent != GNUNET_FSUI_unindex_completed) | 223 | if (lastEvent != GNUNET_FSUI_unindex_completed) |
219 | GNUNET_FSUI_unindex_abort (unindex); | 224 | GNUNET_FSUI_unindex_abort(unindex); |
220 | GNUNET_FSUI_unindex_stop (unindex); | 225 | GNUNET_FSUI_unindex_stop(unindex); |
221 | 226 | ||
222 | 227 | ||
223 | /* END OF TEST CODE */ | 228 | /* END OF TEST CODE */ |
224 | FAILURE: | 229 | FAILURE: |
225 | if (ctx != NULL) | 230 | if (ctx != NULL) |
226 | GNUNET_FSUI_stop (ctx); | 231 | GNUNET_FSUI_stop(ctx); |
227 | if (filename != NULL) | 232 | if (filename != NULL) |
228 | { | 233 | { |
229 | unlink (filename); | 234 | unlink(filename); |
230 | GNUNET_free (filename); | 235 | GNUNET_free(filename); |
231 | } | 236 | } |
232 | if (download != NULL) | 237 | if (download != NULL) |
233 | { | 238 | { |
234 | GNUNET_FSUI_download_abort (download); | 239 | GNUNET_FSUI_download_abort(download); |
235 | GNUNET_FSUI_download_stop (download); | 240 | GNUNET_FSUI_download_stop(download); |
236 | } | 241 | } |
237 | filename = makeName (43); | 242 | filename = makeName(43); |
238 | /* TODO: verify file 'filename(42)' == file 'filename(43)' */ | 243 | /* TODO: verify file 'filename(42)' == file 'filename(43)' */ |
239 | unlink (filename); | 244 | unlink(filename); |
240 | GNUNET_free (filename); | 245 | GNUNET_free(filename); |
241 | 246 | ||
242 | #if START_DAEMON | 247 | #if START_DAEMON |
243 | GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon)); | 248 | GNUNET_GE_ASSERT(NULL, GNUNET_OK == GNUNET_daemon_stop(NULL, daemon)); |
244 | GNUNET_OS_process_destroy (daemon); | 249 | GNUNET_OS_process_destroy(daemon); |
245 | #endif | 250 | #endif |
246 | GNUNET_GC_free (cfg); | 251 | GNUNET_GC_free(cfg); |
247 | 252 | ||
248 | return (ok == GNUNET_YES) ? 0 : 1; | 253 | return (ok == GNUNET_YES) ? 0 : 1; |
249 | } | 254 | } |
diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c index 5cdbd9d07..936c3bed4 100644 --- a/src/fs/test_fs_directory.c +++ b/src/fs/test_fs_directory.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/test_fs_directory.c | 21 | * @file fs/test_fs_directory.c |
22 | * @brief Test for fs_directory.c | 22 | * @brief Test for fs_directory.c |
@@ -32,8 +32,7 @@ | |||
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__); return 1; } |
34 | 34 | ||
35 | struct PCLS | 35 | struct PCLS { |
36 | { | ||
37 | struct GNUNET_FS_Uri **uri; | 36 | struct GNUNET_FS_Uri **uri; |
38 | struct GNUNET_CONTAINER_MetaData **md; | 37 | struct GNUNET_CONTAINER_MetaData **md; |
39 | unsigned int pos; | 38 | unsigned int pos; |
@@ -41,9 +40,9 @@ struct PCLS | |||
41 | }; | 40 | }; |
42 | 41 | ||
43 | static void | 42 | static void |
44 | processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, | 43 | processor(void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, |
45 | const struct GNUNET_CONTAINER_MetaData *md, size_t length, | 44 | const struct GNUNET_CONTAINER_MetaData *md, size_t length, |
46 | const void *data) | 45 | const void *data) |
47 | { | 46 | { |
48 | struct PCLS *p = cls; | 47 | struct PCLS *p = cls; |
49 | int i; | 48 | int i; |
@@ -51,19 +50,19 @@ processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, | |||
51 | if (NULL == uri) | 50 | if (NULL == uri) |
52 | return; /* ignore directory's meta data */ | 51 | return; /* ignore directory's meta data */ |
53 | for (i = 0; i < p->max; i++) | 52 | for (i = 0; i < p->max; i++) |
54 | { | ||
55 | if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], md) && | ||
56 | GNUNET_FS_uri_test_equal (p->uri[i], uri)) | ||
57 | { | 53 | { |
58 | p->pos++; | 54 | if (GNUNET_CONTAINER_meta_data_test_equal(p->md[i], md) && |
59 | return; | 55 | GNUNET_FS_uri_test_equal(p->uri[i], uri)) |
56 | { | ||
57 | p->pos++; | ||
58 | return; | ||
59 | } | ||
60 | } | 60 | } |
61 | } | 61 | fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); |
62 | fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__); | ||
63 | } | 62 | } |
64 | 63 | ||
65 | static int | 64 | static int |
66 | testDirectory (unsigned int i) | 65 | testDirectory(unsigned int i) |
67 | { | 66 | { |
68 | struct GNUNET_FS_DirectoryBuilder *db; | 67 | struct GNUNET_FS_DirectoryBuilder *db; |
69 | char *data; | 68 | char *data; |
@@ -82,99 +81,99 @@ testDirectory (unsigned int i) | |||
82 | const char *s; | 81 | const char *s; |
83 | 82 | ||
84 | cls.max = i; | 83 | cls.max = i; |
85 | uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i); | 84 | uris = GNUNET_malloc(sizeof(struct GNUNET_FS_Uri *) * i); |
86 | mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData *) * i); | 85 | mds = GNUNET_malloc(sizeof(struct GNUNET_CONTAINER_MetaData *) * i); |
87 | meta = GNUNET_CONTAINER_meta_data_create (); | 86 | meta = GNUNET_CONTAINER_meta_data_create(); |
88 | GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, | 87 | GNUNET_CONTAINER_meta_data_insert(meta, "<test>", EXTRACTOR_METATYPE_TITLE, |
89 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 88 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
90 | "A title", strlen ("A title") + 1); | 89 | "A title", strlen("A title") + 1); |
91 | GNUNET_CONTAINER_meta_data_insert (meta, "<test>", | 90 | GNUNET_CONTAINER_meta_data_insert(meta, "<test>", |
92 | EXTRACTOR_METATYPE_AUTHOR_NAME, | 91 | EXTRACTOR_METATYPE_AUTHOR_NAME, |
93 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 92 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
94 | "An author", strlen ("An author") + 1); | 93 | "An author", strlen("An author") + 1); |
95 | for (p = 0; p < i; p++) | 94 | for (p = 0; p < i; p++) |
96 | { | ||
97 | mds[p] = GNUNET_CONTAINER_meta_data_create (); | ||
98 | for (q = 0; q <= p; q++) | ||
99 | { | 95 | { |
100 | GNUNET_snprintf (txt, sizeof (txt), "%u -- %u\n", p, q); | 96 | mds[p] = GNUNET_CONTAINER_meta_data_create(); |
101 | GNUNET_CONTAINER_meta_data_insert (mds[p], "<test>", | 97 | for (q = 0; q <= p; q++) |
98 | { | ||
99 | GNUNET_snprintf(txt, sizeof(txt), "%u -- %u\n", p, q); | ||
100 | GNUNET_CONTAINER_meta_data_insert(mds[p], "<test>", | ||
102 | #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR | 101 | #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR |
103 | q % EXTRACTOR_metatype_get_max (), | 102 | q % EXTRACTOR_metatype_get_max(), |
104 | #else | 103 | #else |
105 | q % 128, | 104 | q % 128, |
106 | #endif | 105 | #endif |
107 | EXTRACTOR_METAFORMAT_UTF8, | 106 | EXTRACTOR_METAFORMAT_UTF8, |
108 | "text/plain", txt, strlen (txt) + 1); | 107 | "text/plain", txt, strlen(txt) + 1); |
109 | } | 108 | } |
110 | GNUNET_snprintf (uri, sizeof (uri), | 109 | GNUNET_snprintf(uri, sizeof(uri), |
111 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", | 110 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", |
112 | p); | 111 | p); |
113 | emsg = NULL; | 112 | emsg = NULL; |
114 | uris[p] = GNUNET_FS_uri_parse (uri, &emsg); | 113 | uris[p] = GNUNET_FS_uri_parse(uri, &emsg); |
115 | if (uris[p] == NULL) | 114 | if (uris[p] == NULL) |
116 | { | 115 | { |
117 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); | 116 | GNUNET_CONTAINER_meta_data_destroy(mds[p]); |
118 | while (--p > 0) | 117 | while (--p > 0) |
119 | { | 118 | { |
120 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); | 119 | GNUNET_CONTAINER_meta_data_destroy(mds[p]); |
121 | GNUNET_FS_uri_destroy (uris[p]); | 120 | GNUNET_FS_uri_destroy(uris[p]); |
122 | } | 121 | } |
123 | GNUNET_free (mds); | 122 | GNUNET_free(mds); |
124 | GNUNET_free (uris); | 123 | GNUNET_free(uris); |
125 | GNUNET_free (emsg); | 124 | GNUNET_free(emsg); |
126 | GNUNET_CONTAINER_meta_data_destroy (meta); | 125 | GNUNET_CONTAINER_meta_data_destroy(meta); |
127 | ABORT (); /* error in testcase */ | 126 | ABORT(); /* error in testcase */ |
127 | } | ||
128 | GNUNET_assert(emsg == NULL); | ||
128 | } | 129 | } |
129 | GNUNET_assert (emsg == NULL); | 130 | start = GNUNET_TIME_absolute_get(); |
130 | } | 131 | db = GNUNET_FS_directory_builder_create(meta); |
131 | start = GNUNET_TIME_absolute_get (); | ||
132 | db = GNUNET_FS_directory_builder_create (meta); | ||
133 | for (p = 0; p < i; p++) | 132 | for (p = 0; p < i; p++) |
134 | GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL); | 133 | GNUNET_FS_directory_builder_add(db, uris[p], mds[p], NULL); |
135 | GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data); | 134 | GNUNET_FS_directory_builder_finish(db, &dlen, (void **)&data); |
136 | s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration | 135 | s = GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration |
137 | (start), | 136 | (start), |
138 | GNUNET_YES); | 137 | GNUNET_YES); |
139 | fprintf (stdout, | 138 | fprintf(stdout, |
140 | "Creating directory with %u entires and total size %llu took %s\n", | 139 | "Creating directory with %u entires and total size %llu took %s\n", |
141 | i, (unsigned long long) dlen, s); | 140 | i, (unsigned long long)dlen, s); |
142 | if (i < 100) | 141 | if (i < 100) |
143 | { | 142 | { |
144 | cls.pos = 0; | 143 | cls.pos = 0; |
145 | cls.uri = uris; | 144 | cls.uri = uris; |
146 | cls.md = mds; | 145 | cls.md = mds; |
147 | GNUNET_FS_directory_list_contents (dlen, data, 0, &processor, &cls); | 146 | GNUNET_FS_directory_list_contents(dlen, data, 0, &processor, &cls); |
148 | GNUNET_assert (cls.pos == i); | 147 | GNUNET_assert(cls.pos == i); |
149 | } | 148 | } |
150 | GNUNET_free (data); | 149 | GNUNET_free(data); |
151 | GNUNET_CONTAINER_meta_data_destroy (meta); | 150 | GNUNET_CONTAINER_meta_data_destroy(meta); |
152 | for (p = 0; p < i; p++) | 151 | for (p = 0; p < i; p++) |
153 | { | 152 | { |
154 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); | 153 | GNUNET_CONTAINER_meta_data_destroy(mds[p]); |
155 | GNUNET_FS_uri_destroy (uris[p]); | 154 | GNUNET_FS_uri_destroy(uris[p]); |
156 | } | 155 | } |
157 | GNUNET_free (uris); | 156 | GNUNET_free(uris); |
158 | GNUNET_free (mds); | 157 | GNUNET_free(mds); |
159 | return ret; | 158 | return ret; |
160 | } | 159 | } |
161 | 160 | ||
162 | 161 | ||
163 | int | 162 | int |
164 | main (int argc, char *argv[]) | 163 | main(int argc, char *argv[]) |
165 | { | 164 | { |
166 | int failureCount = 0; | 165 | int failureCount = 0; |
167 | int i; | 166 | int i; |
168 | 167 | ||
169 | GNUNET_log_setup ("test_fs_directory", | 168 | GNUNET_log_setup("test_fs_directory", |
170 | #if VERBOSE | 169 | #if VERBOSE |
171 | "DEBUG", | 170 | "DEBUG", |
172 | #else | 171 | #else |
173 | "WARNING", | 172 | "WARNING", |
174 | #endif | 173 | #endif |
175 | NULL); | 174 | NULL); |
176 | for (i = 17; i < 1000; i *= 2) | 175 | for (i = 17; i < 1000; i *= 2) |
177 | failureCount += testDirectory (i); | 176 | failureCount += testDirectory(i); |
178 | if (failureCount != 0) | 177 | if (failureCount != 0) |
179 | return 1; | 178 | return 1; |
180 | return 0; | 179 | return 0; |
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index 242e6f1aa..f7c35a680 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_fs_download.c | 22 | * @file 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 | ||
@@ -67,187 +67,198 @@ 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, GNUNET_NO)); |
118 | GNUNET_assert (size == FILESIZE); | 118 | GNUNET_assert(size == FILESIZE); |
119 | GNUNET_DISK_directory_remove (fn); | 119 | GNUNET_DISK_directory_remove(fn); |
120 | GNUNET_free (fn); | 120 | GNUNET_free(fn); |
121 | fn = NULL; | 121 | fn = NULL; |
122 | GNUNET_SCHEDULER_cancel (timeout_kill); | 122 | GNUNET_SCHEDULER_cancel(timeout_kill); |
123 | timeout_kill = NULL; | 123 | timeout_kill = NULL; |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | static void * | 127 | static void * |
128 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | 128 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) |
129 | { | 129 | { |
130 | |||
131 | switch (event->status) | 130 | switch (event->status) |
132 | { | 131 | { |
133 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 132 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 133 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
135 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 134 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
136 | (unsigned long long) event->value.publish.completed, | 135 | (unsigned long long)event->value.publish.completed, |
137 | (unsigned long long) event->value.publish.size, | 136 | (unsigned long long)event->value.publish.size, |
138 | event->value.publish.specifics.progress.depth, | 137 | event->value.publish.specifics.progress.depth, |
139 | (unsigned long long) event->value.publish.specifics. | 138 | (unsigned long long)event->value.publish.specifics. |
140 | progress.offset); | 139 | progress.offset); |
141 | break; | 140 | break; |
142 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 141 | |
143 | break; | 142 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
144 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 143 | break; |
145 | fprintf (stdout, | 144 | |
146 | "Publishing complete, %llu kb/s.\n", | 145 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
147 | (unsigned long long) (FILESIZE * 1000000LL / | 146 | fprintf(stdout, |
148 | (1 + | 147 | "Publishing complete, %llu kb/s.\n", |
149 | GNUNET_TIME_absolute_get_duration | 148 | (unsigned long long)(FILESIZE * 1000000LL / |
150 | (start).rel_value_us) / 1024LL)); | 149 | (1 + |
151 | GAUGER ("FS", | 150 | GNUNET_TIME_absolute_get_duration |
152 | (GNUNET_YES == indexed) | 151 | (start).rel_value_us) / 1024LL)); |
153 | ? "Publishing speed (indexing)" | 152 | GAUGER("FS", |
154 | : "Publishing speed (insertion)", | 153 | (GNUNET_YES == indexed) |
155 | (unsigned long long) (FILESIZE * 1000000LL / | 154 | ? "Publishing speed (indexing)" |
156 | (1 + | 155 | : "Publishing speed (insertion)", |
157 | GNUNET_TIME_absolute_get_duration | 156 | (unsigned long long)(FILESIZE * 1000000LL / |
158 | (start).rel_value_us) / 1024LL), "kb/s"); | 157 | (1 + |
159 | fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); | 158 | GNUNET_TIME_absolute_get_duration |
160 | start = GNUNET_TIME_absolute_get (); | 159 | (start).rel_value_us) / 1024LL), "kb/s"); |
161 | download = | 160 | fn = GNUNET_DISK_mktemp("gnunet-download-test-dst"); |
162 | GNUNET_FS_download_start (fs, | 161 | start = GNUNET_TIME_absolute_get(); |
163 | event->value.publish.specifics. | 162 | download = |
164 | completed.chk_uri, NULL, fn, NULL, 0, | 163 | GNUNET_FS_download_start(fs, |
165 | FILESIZE, anonymity_level, | 164 | event->value.publish.specifics. |
166 | GNUNET_FS_DOWNLOAD_OPTION_NONE, | 165 | completed.chk_uri, NULL, fn, NULL, 0, |
167 | "download", NULL); | 166 | FILESIZE, anonymity_level, |
168 | GNUNET_assert (download != NULL); | 167 | GNUNET_FS_DOWNLOAD_OPTION_NONE, |
169 | break; | 168 | "download", NULL); |
170 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 169 | GNUNET_assert(download != NULL); |
171 | fprintf (stdout, | 170 | break; |
172 | "Download complete, %llu kb/s.\n", | 171 | |
173 | (unsigned long long) (FILESIZE * 1000000LL / | 172 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
174 | (1 + | 173 | fprintf(stdout, |
175 | GNUNET_TIME_absolute_get_duration | 174 | "Download complete, %llu kb/s.\n", |
176 | (start).rel_value_us) / 1024LL)); | 175 | (unsigned long long)(FILESIZE * 1000000LL / |
177 | GAUGER ("FS", | 176 | (1 + |
178 | (GNUNET_YES == indexed) | 177 | GNUNET_TIME_absolute_get_duration |
179 | ? "Local download speed (indexed)" | 178 | (start).rel_value_us) / 1024LL)); |
180 | : "Local download speed (inserted)", | 179 | GAUGER("FS", |
181 | (unsigned long long) (FILESIZE * 1000000LL / | 180 | (GNUNET_YES == indexed) |
181 | ? "Local download speed (indexed)" | ||
182 | : "Local download speed (inserted)", | ||
183 | (unsigned long long)(FILESIZE * 1000000LL / | ||
182 | (1 + | 184 | (1 + |
183 | GNUNET_TIME_absolute_get_duration | 185 | GNUNET_TIME_absolute_get_duration |
184 | (start).rel_value_us) / 1024LL), "kb/s"); | 186 | (start).rel_value_us) / 1024LL), "kb/s"); |
185 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); | 187 | GNUNET_SCHEDULER_add_now(&abort_download_task, NULL); |
186 | break; | 188 | break; |
187 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 189 | |
188 | GNUNET_assert (download == event->value.download.dc); | 190 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 191 | GNUNET_assert(download == event->value.download.dc); |
190 | "Download is progressing (%llu/%llu at level %u off %llu)...\n", | 192 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
191 | (unsigned long long) event->value.download.completed, | 193 | "Download is progressing (%llu/%llu at level %u off %llu)...\n", |
192 | (unsigned long long) event->value.download.size, | 194 | (unsigned long long)event->value.download.completed, |
193 | event->value.download.specifics.progress.depth, | 195 | (unsigned long long)event->value.download.size, |
194 | (unsigned long long) event->value.download.specifics. | 196 | event->value.download.specifics.progress.depth, |
195 | progress.offset); | 197 | (unsigned long long)event->value.download.specifics. |
196 | break; | 198 | progress.offset); |
197 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 199 | break; |
198 | fprintf (stderr, "Error publishing file: %s\n", | 200 | |
199 | event->value.publish.specifics.error.message); | 201 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
200 | GNUNET_break (0); | 202 | fprintf(stderr, "Error publishing file: %s\n", |
201 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 203 | event->value.publish.specifics.error.message); |
202 | GNUNET_SCHEDULER_shutdown (); | 204 | GNUNET_break(0); |
203 | break; | 205 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); |
204 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 206 | GNUNET_SCHEDULER_shutdown(); |
205 | fprintf (stderr, "Error downloading file: %s\n", | 207 | break; |
206 | event->value.download.specifics.error.message); | 208 | |
207 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); | 209 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: |
208 | GNUNET_SCHEDULER_shutdown (); | 210 | fprintf(stderr, "Error downloading file: %s\n", |
209 | break; | 211 | event->value.download.specifics.error.message); |
210 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | 212 | GNUNET_SCHEDULER_add_now(&abort_download_task, NULL); |
211 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | 213 | GNUNET_SCHEDULER_shutdown(); |
212 | break; | 214 | break; |
213 | case GNUNET_FS_STATUS_PUBLISH_START: | 215 | |
214 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | 216 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: |
215 | GNUNET_assert (NULL == event->value.publish.pctx); | 217 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: |
216 | GNUNET_assert (FILESIZE == event->value.publish.size); | 218 | break; |
217 | GNUNET_assert (0 == event->value.publish.completed); | 219 | |
218 | GNUNET_assert (1 == event->value.publish.anonymity); | 220 | case GNUNET_FS_STATUS_PUBLISH_START: |
219 | break; | 221 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); |
220 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 222 | GNUNET_assert(NULL == event->value.publish.pctx); |
221 | GNUNET_assert (publish == event->value.publish.pc); | 223 | GNUNET_assert(FILESIZE == event->value.publish.size); |
222 | GNUNET_assert (FILESIZE == event->value.publish.size); | 224 | GNUNET_assert(0 == event->value.publish.completed); |
223 | GNUNET_assert (1 == event->value.publish.anonymity); | 225 | GNUNET_assert(1 == event->value.publish.anonymity); |
224 | GNUNET_SCHEDULER_add_now (&stop_fs_task, NULL); | 226 | break; |
225 | break; | 227 | |
226 | case GNUNET_FS_STATUS_DOWNLOAD_START: | 228 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
227 | GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); | 229 | GNUNET_assert(publish == event->value.publish.pc); |
228 | GNUNET_assert (NULL == event->value.download.pctx); | 230 | GNUNET_assert(FILESIZE == event->value.publish.size); |
229 | GNUNET_assert (NULL != event->value.download.uri); | 231 | GNUNET_assert(1 == event->value.publish.anonymity); |
230 | GNUNET_assert (0 == strcmp (fn, event->value.download.filename)); | 232 | GNUNET_SCHEDULER_add_now(&stop_fs_task, NULL); |
231 | GNUNET_assert (FILESIZE == event->value.download.size); | 233 | break; |
232 | GNUNET_assert (0 == event->value.download.completed); | 234 | |
233 | GNUNET_assert (1 == event->value.download.anonymity); | 235 | case GNUNET_FS_STATUS_DOWNLOAD_START: |
234 | break; | 236 | GNUNET_assert(0 == strcmp("download", event->value.download.cctx)); |
235 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | 237 | GNUNET_assert(NULL == event->value.download.pctx); |
236 | GNUNET_assert (download == event->value.download.dc); | 238 | GNUNET_assert(NULL != event->value.download.uri); |
237 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 239 | GNUNET_assert(0 == strcmp(fn, event->value.download.filename)); |
238 | break; | 240 | GNUNET_assert(FILESIZE == event->value.download.size); |
239 | default: | 241 | GNUNET_assert(0 == event->value.download.completed); |
240 | printf ("Unexpected event: %d\n", event->status); | 242 | GNUNET_assert(1 == event->value.download.anonymity); |
241 | break; | 243 | break; |
242 | } | 244 | |
245 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
246 | GNUNET_assert(download == event->value.download.dc); | ||
247 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
248 | break; | ||
249 | |||
250 | default: | ||
251 | printf("Unexpected event: %d\n", event->status); | ||
252 | break; | ||
253 | } | ||
243 | return NULL; | 254 | return NULL; |
244 | } | 255 | } |
245 | 256 | ||
246 | 257 | ||
247 | static void | 258 | static void |
248 | run (void *cls, | 259 | run(void *cls, |
249 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 260 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
250 | struct GNUNET_TESTING_Peer *peer) | 261 | struct GNUNET_TESTING_Peer *peer) |
251 | { | 262 | { |
252 | const char *binary_name = cls; | 263 | const char *binary_name = cls; |
253 | const char *keywords[] = { | 264 | const char *keywords[] = { |
@@ -262,89 +273,89 @@ run (void *cls, | |||
262 | struct GNUNET_FS_BlockOptions bo; | 273 | struct GNUNET_FS_BlockOptions bo; |
263 | 274 | ||
264 | if (GNUNET_YES == | 275 | if (GNUNET_YES == |
265 | GNUNET_CONFIGURATION_get_value_yesno (cfg, | 276 | GNUNET_CONFIGURATION_get_value_yesno(cfg, |
266 | "download-test", | 277 | "download-test", |
267 | "USE_STREAM")) | 278 | "USE_STREAM")) |
268 | anonymity_level = 0; | 279 | anonymity_level = 0; |
269 | else | 280 | else |
270 | anonymity_level = 1; | 281 | anonymity_level = 1; |
271 | fs = GNUNET_FS_start (cfg, binary_name, &progress_cb, NULL, | 282 | fs = GNUNET_FS_start(cfg, binary_name, &progress_cb, NULL, |
272 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 283 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
273 | GNUNET_assert (NULL != fs); | 284 | GNUNET_assert(NULL != fs); |
274 | buf = GNUNET_malloc (FILESIZE); | 285 | buf = GNUNET_malloc(FILESIZE); |
275 | for (i = 0; i < FILESIZE; i++) | 286 | for (i = 0; i < FILESIZE; i++) |
276 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 287 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
277 | meta = GNUNET_CONTAINER_meta_data_create (); | 288 | meta = GNUNET_CONTAINER_meta_data_create(); |
278 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 289 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); |
279 | bo.content_priority = 42; | 290 | bo.content_priority = 42; |
280 | bo.anonymity_level = anonymity_level; | 291 | bo.anonymity_level = anonymity_level; |
281 | bo.replication_level = 0; | 292 | bo.replication_level = 0; |
282 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 293 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); |
283 | 294 | ||
284 | if (GNUNET_YES == | 295 | if (GNUNET_YES == |
285 | GNUNET_CONFIGURATION_get_value_yesno (cfg, | 296 | GNUNET_CONFIGURATION_get_value_yesno(cfg, |
286 | "download-test", | 297 | "download-test", |
287 | "USE_INDEX")) | 298 | "USE_INDEX")) |
288 | { | 299 | { |
289 | fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test"); | 300 | fn1 = GNUNET_DISK_mktemp("gnunet-download-indexed-test"); |
290 | GNUNET_assert (FILESIZE == | 301 | GNUNET_assert(FILESIZE == |
291 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | 302 | GNUNET_DISK_fn_write(fn1, buf, FILESIZE, |
292 | GNUNET_DISK_PERM_USER_READ | | 303 | GNUNET_DISK_PERM_USER_READ | |
293 | GNUNET_DISK_PERM_USER_WRITE)); | 304 | GNUNET_DISK_PERM_USER_WRITE)); |
294 | GNUNET_free (buf); | 305 | GNUNET_free(buf); |
295 | fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn1, | 306 | fi = GNUNET_FS_file_information_create_from_file(fs, "publish-context", fn1, |
296 | kuri, meta, GNUNET_YES, | 307 | kuri, meta, GNUNET_YES, |
297 | &bo); | 308 | &bo); |
298 | indexed = GNUNET_YES; | 309 | indexed = GNUNET_YES; |
299 | } | 310 | } |
300 | else | 311 | else |
301 | { | 312 | { |
302 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", | 313 | fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", |
303 | FILESIZE, buf, kuri, meta, | 314 | FILESIZE, buf, kuri, meta, |
304 | GNUNET_NO, &bo); | 315 | GNUNET_NO, &bo); |
305 | /* note: buf will be free'd as part of 'fi' now */ | 316 | /* note: buf will be free'd as part of 'fi' now */ |
306 | indexed = GNUNET_NO; | 317 | indexed = GNUNET_NO; |
307 | } | 318 | } |
308 | GNUNET_FS_uri_destroy (kuri); | 319 | GNUNET_FS_uri_destroy(kuri); |
309 | GNUNET_CONTAINER_meta_data_destroy (meta); | 320 | GNUNET_CONTAINER_meta_data_destroy(meta); |
310 | GNUNET_assert (NULL != fi); | 321 | GNUNET_assert(NULL != fi); |
311 | timeout_kill = | 322 | timeout_kill = |
312 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill_task, NULL); | 323 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_kill_task, NULL); |
313 | start = GNUNET_TIME_absolute_get (); | 324 | start = GNUNET_TIME_absolute_get(); |
314 | publish = | 325 | publish = |
315 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, | 326 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, |
316 | GNUNET_FS_PUBLISH_OPTION_NONE); | 327 | GNUNET_FS_PUBLISH_OPTION_NONE); |
317 | GNUNET_assert (publish != NULL); | 328 | GNUNET_assert(publish != NULL); |
318 | } | 329 | } |
319 | 330 | ||
320 | 331 | ||
321 | int | 332 | int |
322 | main (int argc, char *argv[]) | 333 | main(int argc, char *argv[]) |
323 | { | 334 | { |
324 | const char *binary_name; | 335 | const char *binary_name; |
325 | const char *config_name; | 336 | const char *config_name; |
326 | 337 | ||
327 | binary_name = "test-fs-download"; | 338 | binary_name = "test-fs-download"; |
328 | config_name = "test_fs_download_data.conf"; | 339 | config_name = "test_fs_download_data.conf"; |
329 | if (NULL != strstr (argv[0], "indexed")) | 340 | if (NULL != strstr(argv[0], "indexed")) |
330 | { | 341 | { |
331 | binary_name = "test-fs-download-indexed"; | 342 | binary_name = "test-fs-download-indexed"; |
332 | config_name = "test_fs_download_indexed.conf"; | 343 | config_name = "test_fs_download_indexed.conf"; |
333 | } | 344 | } |
334 | if (NULL != strstr (argv[0], "cadet")) | 345 | if (NULL != strstr(argv[0], "cadet")) |
335 | { | 346 | { |
336 | binary_name = "test-fs-download-cadet"; | 347 | binary_name = "test-fs-download-cadet"; |
337 | config_name = "test_fs_download_cadet.conf"; | 348 | config_name = "test_fs_download_cadet.conf"; |
338 | } | 349 | } |
339 | if (0 != GNUNET_TESTING_peer_run (binary_name, | 350 | if (0 != GNUNET_TESTING_peer_run(binary_name, |
340 | config_name, | 351 | config_name, |
341 | &run, (void *) binary_name)) | 352 | &run, (void *)binary_name)) |
342 | return 1; | 353 | return 1; |
343 | if (NULL != fn1) | 354 | if (NULL != fn1) |
344 | { | 355 | { |
345 | unlink (fn1); | 356 | unlink(fn1); |
346 | GNUNET_free (fn1); | 357 | GNUNET_free(fn1); |
347 | } | 358 | } |
348 | return err; | 359 | return err; |
349 | } | 360 | } |
350 | 361 | ||
diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c index 97c2a338c..78dbe821e 100644 --- a/src/fs/test_fs_download_persistence.c +++ b/src/fs/test_fs_download_persistence.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_fs_download_persistence.c | 22 | * @file 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; |
@@ -62,66 +62,66 @@ 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, GNUNET_NO)); |
105 | GNUNET_assert (size == FILESIZE); | 105 | GNUNET_assert(size == FILESIZE); |
106 | GNUNET_DISK_directory_remove (fn); | 106 | GNUNET_DISK_directory_remove(fn); |
107 | GNUNET_free (fn); | 107 | GNUNET_free(fn); |
108 | fn = NULL; | 108 | fn = NULL; |
109 | GNUNET_SCHEDULER_cancel (timeout_kill); | 109 | GNUNET_SCHEDULER_cancel(timeout_kill); |
110 | timeout_kill = NULL; | 110 | timeout_kill = NULL; |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | static void * | 114 | static void * |
115 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event); | 115 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event); |
116 | 116 | ||
117 | 117 | ||
118 | static void | 118 | static void |
119 | restart_fs_task (void *cls) | 119 | restart_fs_task(void *cls) |
120 | { | 120 | { |
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting FS.\n"); | 121 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Restarting FS.\n"); |
122 | GNUNET_FS_stop (fs); | 122 | GNUNET_FS_stop(fs); |
123 | fs = GNUNET_FS_start (cfg, "test-fs-download-persistence", &progress_cb, NULL, | 123 | fs = GNUNET_FS_start(cfg, "test-fs-download-persistence", &progress_cb, NULL, |
124 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 124 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
@@ -133,7 +133,7 @@ restart_fs_task (void *cls) | |||
133 | * @param ev type of the event to consider | 133 | * @param ev type of the event to consider |
134 | */ | 134 | */ |
135 | static void | 135 | static void |
136 | consider_restart (int ev) | 136 | consider_restart(int ev) |
137 | { | 137 | { |
138 | static int prev[32]; | 138 | static int prev[32]; |
139 | static int off; | 139 | static int off; |
@@ -143,141 +143,158 @@ consider_restart (int ev) | |||
143 | if (prev[i] == ev) | 143 | if (prev[i] == ev) |
144 | return; | 144 | return; |
145 | prev[off++] = ev; | 145 | prev[off++] = ev; |
146 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, | 146 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_URGENT, |
147 | &restart_fs_task, NULL); | 147 | &restart_fs_task, NULL); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | static void * | 151 | static void * |
152 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | 152 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) |
153 | { | 153 | { |
154 | switch (event->status) | 154 | switch (event->status) |
155 | { | 155 | { |
156 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 156 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 157 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
158 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 158 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
159 | (unsigned long long) event->value.publish.completed, | 159 | (unsigned long long)event->value.publish.completed, |
160 | (unsigned long long) event->value.publish.size, | 160 | (unsigned long long)event->value.publish.size, |
161 | event->value.publish.specifics.progress.depth, | 161 | event->value.publish.specifics.progress.depth, |
162 | (unsigned long long) event->value.publish.specifics. | 162 | (unsigned long long)event->value.publish.specifics. |
163 | progress.offset); | 163 | progress.offset); |
164 | break; | 164 | break; |
165 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 165 | |
166 | break; | 166 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
167 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 167 | break; |
168 | printf ("Publishing complete, %llu kbps.\n", | 168 | |
169 | (unsigned long long) (FILESIZE * 1000000LL / | 169 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
170 | printf("Publishing complete, %llu kbps.\n", | ||
171 | (unsigned long long)(FILESIZE * 1000000LL / | ||
170 | (1 + | 172 | (1 + |
171 | GNUNET_TIME_absolute_get_duration | 173 | GNUNET_TIME_absolute_get_duration |
172 | (start).rel_value_us) / 1024LL)); | 174 | (start).rel_value_us) / 1024LL)); |
173 | fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); | 175 | fn = GNUNET_DISK_mktemp("gnunet-download-test-dst"); |
174 | start = GNUNET_TIME_absolute_get (); | 176 | start = GNUNET_TIME_absolute_get(); |
175 | GNUNET_assert (download == NULL); | 177 | GNUNET_assert(download == NULL); |
176 | GNUNET_FS_download_start (fs, | 178 | GNUNET_FS_download_start(fs, |
177 | event->value.publish.specifics.completed.chk_uri, | 179 | event->value.publish.specifics.completed.chk_uri, |
178 | NULL, fn, NULL, 0, FILESIZE, 1, | 180 | NULL, fn, NULL, 0, FILESIZE, 1, |
179 | GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL); | 181 | GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL); |
180 | break; | 182 | break; |
181 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 183 | |
182 | printf ("Download complete, %llu kbps.\n", | 184 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
183 | (unsigned long long) (FILESIZE * 1000000LL / | 185 | printf("Download complete, %llu kbps.\n", |
186 | (unsigned long long)(FILESIZE * 1000000LL / | ||
184 | (1 + | 187 | (1 + |
185 | GNUNET_TIME_absolute_get_duration | 188 | GNUNET_TIME_absolute_get_duration |
186 | (start).rel_value_us) / 1024LL)); | 189 | (start).rel_value_us) / 1024LL)); |
187 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); | 190 | GNUNET_SCHEDULER_add_now(&abort_download_task, NULL); |
188 | break; | 191 | break; |
189 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 192 | |
190 | consider_restart (event->status); | 193 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
191 | GNUNET_assert (download == event->value.download.dc); | 194 | consider_restart(event->status); |
192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 195 | GNUNET_assert(download == event->value.download.dc); |
193 | "Download is progressing (%llu/%llu at level %u off %llu)...\n", | 196 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
194 | (unsigned long long) event->value.download.completed, | 197 | "Download is progressing (%llu/%llu at level %u off %llu)...\n", |
195 | (unsigned long long) event->value.download.size, | 198 | (unsigned long long)event->value.download.completed, |
196 | event->value.download.specifics.progress.depth, | 199 | (unsigned long long)event->value.download.size, |
197 | (unsigned long long) event->value.download.specifics. | 200 | event->value.download.specifics.progress.depth, |
198 | progress.offset); | 201 | (unsigned long long)event->value.download.specifics. |
199 | break; | 202 | progress.offset); |
200 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 203 | break; |
201 | fprintf (stderr, "Error publishing file: %s\n", | 204 | |
202 | event->value.publish.specifics.error.message); | 205 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
203 | GNUNET_break (0); | 206 | fprintf(stderr, "Error publishing file: %s\n", |
204 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 207 | event->value.publish.specifics.error.message); |
205 | break; | 208 | GNUNET_break(0); |
206 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 209 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); |
207 | fprintf (stderr, "Error downloading file: %s\n", | 210 | break; |
208 | event->value.download.specifics.error.message); | 211 | |
209 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); | 212 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: |
210 | break; | 213 | fprintf(stderr, "Error downloading file: %s\n", |
211 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: | 214 | event->value.download.specifics.error.message); |
212 | GNUNET_assert (event->value.publish.pc == publish); | 215 | GNUNET_SCHEDULER_add_now(&abort_download_task, NULL); |
213 | publish = NULL; | 216 | break; |
214 | break; | 217 | |
215 | case GNUNET_FS_STATUS_PUBLISH_RESUME: | 218 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: |
216 | GNUNET_assert (NULL == publish); | 219 | GNUNET_assert(event->value.publish.pc == publish); |
217 | publish = event->value.publish.pc; | 220 | publish = NULL; |
218 | break; | 221 | break; |
219 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: | 222 | |
220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download suspended.\n"); | 223 | case GNUNET_FS_STATUS_PUBLISH_RESUME: |
221 | GNUNET_assert (event->value.download.dc == download); | 224 | GNUNET_assert(NULL == publish); |
222 | download = NULL; | 225 | publish = event->value.publish.pc; |
223 | break; | 226 | break; |
224 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: | 227 | |
225 | GNUNET_assert (NULL == download); | 228 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: |
226 | download = event->value.download.dc; | 229 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download suspended.\n"); |
227 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download resumed.\n"); | 230 | GNUNET_assert(event->value.download.dc == download); |
228 | break; | 231 | download = NULL; |
229 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | 232 | break; |
230 | consider_restart (event->status); | 233 | |
231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download active.\n"); | 234 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: |
232 | break; | 235 | GNUNET_assert(NULL == download); |
233 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | 236 | download = event->value.download.dc; |
234 | consider_restart (event->status); | 237 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download resumed.\n"); |
235 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download inactive.\n"); | 238 | break; |
236 | break; | 239 | |
237 | case GNUNET_FS_STATUS_PUBLISH_START: | 240 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: |
238 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | 241 | consider_restart(event->status); |
239 | GNUNET_assert (NULL == event->value.publish.pctx); | 242 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download active.\n"); |
240 | GNUNET_assert (FILESIZE == event->value.publish.size); | 243 | break; |
241 | GNUNET_assert (0 == event->value.publish.completed); | 244 | |
242 | GNUNET_assert (1 == event->value.publish.anonymity); | 245 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: |
243 | break; | 246 | consider_restart(event->status); |
244 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 247 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download inactive.\n"); |
245 | GNUNET_assert (publish == event->value.publish.pc); | 248 | break; |
246 | GNUNET_assert (FILESIZE == event->value.publish.size); | 249 | |
247 | GNUNET_assert (1 == event->value.publish.anonymity); | 250 | case GNUNET_FS_STATUS_PUBLISH_START: |
248 | GNUNET_FS_stop (fs); | 251 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); |
249 | fs = NULL; | 252 | GNUNET_assert(NULL == event->value.publish.pctx); |
250 | break; | 253 | GNUNET_assert(FILESIZE == event->value.publish.size); |
251 | case GNUNET_FS_STATUS_DOWNLOAD_START: | 254 | GNUNET_assert(0 == event->value.publish.completed); |
252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download started.\n"); | 255 | GNUNET_assert(1 == event->value.publish.anonymity); |
253 | consider_restart (event->status); | 256 | break; |
254 | GNUNET_assert (download == NULL); | 257 | |
255 | download = event->value.download.dc; | 258 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
256 | GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); | 259 | GNUNET_assert(publish == event->value.publish.pc); |
257 | GNUNET_assert (NULL == event->value.download.pctx); | 260 | GNUNET_assert(FILESIZE == event->value.publish.size); |
258 | GNUNET_assert (NULL != event->value.download.uri); | 261 | GNUNET_assert(1 == event->value.publish.anonymity); |
259 | GNUNET_assert (0 == strcmp (fn, event->value.download.filename)); | 262 | GNUNET_FS_stop(fs); |
260 | GNUNET_assert (FILESIZE == event->value.download.size); | 263 | fs = NULL; |
261 | GNUNET_assert (0 == event->value.download.completed); | 264 | break; |
262 | GNUNET_assert (1 == event->value.download.anonymity); | 265 | |
263 | break; | 266 | case GNUNET_FS_STATUS_DOWNLOAD_START: |
264 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | 267 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download started.\n"); |
265 | GNUNET_assert (download == event->value.download.dc); | 268 | consider_restart(event->status); |
266 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 269 | GNUNET_assert(download == NULL); |
267 | download = NULL; | 270 | download = event->value.download.dc; |
268 | break; | 271 | GNUNET_assert(0 == strcmp("download", event->value.download.cctx)); |
269 | default: | 272 | GNUNET_assert(NULL == event->value.download.pctx); |
270 | printf ("Unexpected event: %d\n", event->status); | 273 | GNUNET_assert(NULL != event->value.download.uri); |
271 | break; | 274 | GNUNET_assert(0 == strcmp(fn, event->value.download.filename)); |
272 | } | 275 | GNUNET_assert(FILESIZE == event->value.download.size); |
276 | GNUNET_assert(0 == event->value.download.completed); | ||
277 | GNUNET_assert(1 == event->value.download.anonymity); | ||
278 | break; | ||
279 | |||
280 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
281 | GNUNET_assert(download == event->value.download.dc); | ||
282 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
283 | download = NULL; | ||
284 | break; | ||
285 | |||
286 | default: | ||
287 | printf("Unexpected event: %d\n", event->status); | ||
288 | break; | ||
289 | } | ||
273 | return NULL; | 290 | return NULL; |
274 | } | 291 | } |
275 | 292 | ||
276 | 293 | ||
277 | static void | 294 | static void |
278 | run (void *cls, | 295 | run(void *cls, |
279 | const struct GNUNET_CONFIGURATION_Handle *c, | 296 | const struct GNUNET_CONFIGURATION_Handle *c, |
280 | struct GNUNET_TESTING_Peer *peer) | 297 | struct GNUNET_TESTING_Peer *peer) |
281 | { | 298 | { |
282 | const char *keywords[] = { | 299 | const char *keywords[] = { |
283 | "down_foo", | 300 | "down_foo", |
@@ -291,40 +308,40 @@ run (void *cls, | |||
291 | struct GNUNET_FS_BlockOptions bo; | 308 | struct GNUNET_FS_BlockOptions bo; |
292 | 309 | ||
293 | cfg = c; | 310 | cfg = c; |
294 | fs = GNUNET_FS_start (cfg, "test-fs-download-persistence", &progress_cb, NULL, | 311 | fs = GNUNET_FS_start(cfg, "test-fs-download-persistence", &progress_cb, NULL, |
295 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 312 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
296 | GNUNET_assert (NULL != fs); | 313 | GNUNET_assert(NULL != fs); |
297 | buf = GNUNET_malloc (FILESIZE); | 314 | buf = GNUNET_malloc(FILESIZE); |
298 | for (i = 0; i < FILESIZE; i++) | 315 | for (i = 0; i < FILESIZE; i++) |
299 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 316 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
300 | meta = GNUNET_CONTAINER_meta_data_create (); | 317 | meta = GNUNET_CONTAINER_meta_data_create(); |
301 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 318 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); |
302 | bo.content_priority = 42; | 319 | bo.content_priority = 42; |
303 | bo.anonymity_level = 1; | 320 | bo.anonymity_level = 1; |
304 | bo.replication_level = 0; | 321 | bo.replication_level = 0; |
305 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 322 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); |
306 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", | 323 | fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", |
307 | FILESIZE, buf, kuri, meta, | 324 | FILESIZE, buf, kuri, meta, |
308 | GNUNET_NO, &bo); | 325 | GNUNET_NO, &bo); |
309 | GNUNET_FS_uri_destroy (kuri); | 326 | GNUNET_FS_uri_destroy(kuri); |
310 | GNUNET_CONTAINER_meta_data_destroy (meta); | 327 | GNUNET_CONTAINER_meta_data_destroy(meta); |
311 | GNUNET_assert (NULL != fi); | 328 | GNUNET_assert(NULL != fi); |
312 | timeout_kill = | 329 | timeout_kill = |
313 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill_task, NULL); | 330 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_kill_task, NULL); |
314 | start = GNUNET_TIME_absolute_get (); | 331 | start = GNUNET_TIME_absolute_get(); |
315 | publish = | 332 | publish = |
316 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, | 333 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, |
317 | GNUNET_FS_PUBLISH_OPTION_NONE); | 334 | GNUNET_FS_PUBLISH_OPTION_NONE); |
318 | GNUNET_assert (publish != NULL); | 335 | GNUNET_assert(publish != NULL); |
319 | } | 336 | } |
320 | 337 | ||
321 | 338 | ||
322 | int | 339 | int |
323 | main (int argc, char *argv[]) | 340 | main(int argc, char *argv[]) |
324 | { | 341 | { |
325 | if (0 != GNUNET_TESTING_peer_run ("test-fs-download-persistence", | 342 | if (0 != GNUNET_TESTING_peer_run("test-fs-download-persistence", |
326 | "test_fs_download_data.conf", | 343 | "test_fs_download_data.conf", |
327 | &run, NULL)) | 344 | &run, NULL)) |
328 | return 1; | 345 | return 1; |
329 | return err; | 346 | return err; |
330 | } | 347 | } |
diff --git a/src/fs/test_fs_file_information.c b/src/fs/test_fs_file_information.c index 06682043a..1f008997f 100644 --- a/src/fs/test_fs_file_information.c +++ b/src/fs/test_fs_file_information.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_fs_file_information.c | 22 | * @file 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 3562069e1..48777b0e0 100644 --- a/src/fs/test_fs_getopt.c +++ b/src/fs/test_fs_getopt.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/test_fs_getopt.c | 21 | * @file fs/test_fs_getopt.c |
22 | * @brief test for fs_getopt.c | 22 | * @brief test for 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 a4e7eb53f..b5e5982d0 100644 --- a/src/fs/test_fs_list_indexed.c +++ b/src/fs/test_fs_list_indexed.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_fs_list_indexed.c | 22 | * @file 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,115 +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 | { | 92 | { |
93 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 93 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
94 | ret = event->value.publish.cctx; | 94 | ret = event->value.publish.cctx; |
95 | printf ("Publish complete, %llu kbps.\n", | 95 | printf("Publish complete, %llu kbps.\n", |
96 | (unsigned long long) (FILESIZE * 1000000LL / | 96 | (unsigned long long)(FILESIZE * 1000000LL / |
97 | (1 + | 97 | (1 + |
98 | GNUNET_TIME_absolute_get_duration | 98 | GNUNET_TIME_absolute_get_duration |
99 | (start).rel_value_us) / 1024)); | 99 | (start).rel_value_us) / 1024)); |
100 | if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | 100 | if (0 == strcmp("list_indexed-context-dir", event->value.publish.cctx)) |
101 | GNUNET_SCHEDULER_add_now (&list_indexed_task, NULL); | 101 | GNUNET_SCHEDULER_add_now(&list_indexed_task, NULL); |
102 | 102 | ||
103 | break; | 103 | break; |
104 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 104 | |
105 | ret = event->value.publish.cctx; | 105 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
106 | GNUNET_assert (publish == event->value.publish.pc); | 106 | ret = event->value.publish.cctx; |
107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 107 | GNUNET_assert(publish == event->value.publish.pc); |
108 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 108 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
109 | (unsigned long long) event->value.publish.completed, | 109 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
110 | (unsigned long long) event->value.publish.size, | 110 | (unsigned long long)event->value.publish.completed, |
111 | event->value.publish.specifics.progress.depth, | 111 | (unsigned long long)event->value.publish.size, |
112 | (unsigned long long) event->value.publish.specifics. | 112 | event->value.publish.specifics.progress.depth, |
113 | progress.offset); | 113 | (unsigned long long)event->value.publish.specifics. |
114 | break; | 114 | progress.offset); |
115 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 115 | break; |
116 | ret = event->value.publish.cctx; | 116 | |
117 | break; | 117 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
118 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 118 | ret = event->value.publish.cctx; |
119 | ret = event->value.publish.cctx; | 119 | break; |
120 | fprintf (stderr, "Error publishing file: %s\n", | 120 | |
121 | event->value.publish.specifics.error.message); | 121 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
122 | err = 1; | 122 | ret = event->value.publish.cctx; |
123 | if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | 123 | fprintf(stderr, "Error publishing file: %s\n", |
124 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 124 | event->value.publish.specifics.error.message); |
125 | break; | 125 | err = 1; |
126 | case GNUNET_FS_STATUS_PUBLISH_START: | 126 | if (0 == strcmp("list_indexed-context-dir", event->value.publish.cctx)) |
127 | ret = event->value.publish.cctx; | 127 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); |
128 | if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx)) | 128 | break; |
129 | { | 129 | |
130 | GNUNET_assert (0 == | 130 | case GNUNET_FS_STATUS_PUBLISH_START: |
131 | strcmp ("list_indexed-context-dir", | 131 | ret = event->value.publish.cctx; |
132 | event->value.publish.pctx)); | 132 | if (0 == strcmp("list_indexed-context1", event->value.publish.cctx)) |
133 | GNUNET_assert (FILESIZE == event->value.publish.size); | 133 | { |
134 | GNUNET_assert (0 == event->value.publish.completed); | 134 | GNUNET_assert(0 == |
135 | GNUNET_assert (1 == event->value.publish.anonymity); | 135 | strcmp("list_indexed-context-dir", |
136 | } | 136 | event->value.publish.pctx)); |
137 | else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx)) | 137 | GNUNET_assert(FILESIZE == event->value.publish.size); |
138 | { | 138 | GNUNET_assert(0 == event->value.publish.completed); |
139 | GNUNET_assert (0 == | 139 | GNUNET_assert(1 == event->value.publish.anonymity); |
140 | strcmp ("list_indexed-context-dir", | 140 | } |
141 | event->value.publish.pctx)); | 141 | else if (0 == strcmp("list_indexed-context2", event->value.publish.cctx)) |
142 | GNUNET_assert (FILESIZE == event->value.publish.size); | 142 | { |
143 | GNUNET_assert (0 == event->value.publish.completed); | 143 | GNUNET_assert(0 == |
144 | GNUNET_assert (2 == event->value.publish.anonymity); | 144 | strcmp("list_indexed-context-dir", |
145 | } | 145 | event->value.publish.pctx)); |
146 | else if (0 == | 146 | GNUNET_assert(FILESIZE == event->value.publish.size); |
147 | strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | 147 | GNUNET_assert(0 == event->value.publish.completed); |
148 | { | 148 | GNUNET_assert(2 == event->value.publish.anonymity); |
149 | GNUNET_assert (0 == event->value.publish.completed); | 149 | } |
150 | GNUNET_assert (3 == event->value.publish.anonymity); | 150 | else if (0 == |
151 | } | 151 | strcmp("list_indexed-context-dir", event->value.publish.cctx)) |
152 | else | 152 | { |
153 | GNUNET_assert (0); | 153 | GNUNET_assert(0 == event->value.publish.completed); |
154 | break; | 154 | GNUNET_assert(3 == event->value.publish.anonymity); |
155 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 155 | } |
156 | if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | 156 | else |
157 | { | 157 | GNUNET_assert(0); |
158 | GNUNET_assert (publish == event->value.publish.pc); | 158 | break; |
159 | publish = NULL; | 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; | ||
160 | } | 171 | } |
161 | break; | ||
162 | default: | ||
163 | printf ("Unexpected event: %d\n", event->status); | ||
164 | break; | ||
165 | } | ||
166 | return ret; | 172 | return ret; |
167 | } | 173 | } |
168 | 174 | ||
169 | 175 | ||
170 | static void | 176 | static void |
171 | run (void *cls, | 177 | run(void *cls, |
172 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 178 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
173 | struct GNUNET_TESTING_Peer *peer) | 179 | struct GNUNET_TESTING_Peer *peer) |
174 | { | 180 | { |
175 | const char *keywords[] = { | 181 | const char *keywords[] = { |
176 | "down_foo", | 182 | "down_foo", |
@@ -185,70 +191,70 @@ run (void *cls, | |||
185 | size_t i; | 191 | size_t i; |
186 | struct GNUNET_FS_BlockOptions bo; | 192 | struct GNUNET_FS_BlockOptions bo; |
187 | 193 | ||
188 | 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, |
189 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 195 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
190 | GNUNET_assert (NULL != fs); | 196 | GNUNET_assert(NULL != fs); |
191 | fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); | 197 | fn1 = GNUNET_DISK_mktemp("gnunet-list_indexed-test-dst"); |
192 | buf = GNUNET_malloc (FILESIZE); | 198 | buf = GNUNET_malloc(FILESIZE); |
193 | for (i = 0; i < FILESIZE; i++) | 199 | for (i = 0; i < FILESIZE; i++) |
194 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 200 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
195 | GNUNET_assert (FILESIZE == | 201 | GNUNET_assert(FILESIZE == |
196 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | 202 | GNUNET_DISK_fn_write(fn1, buf, FILESIZE, |
197 | GNUNET_DISK_PERM_USER_READ | | 203 | GNUNET_DISK_PERM_USER_READ | |
198 | GNUNET_DISK_PERM_USER_WRITE)); | 204 | GNUNET_DISK_PERM_USER_WRITE)); |
199 | GNUNET_free (buf); | 205 | GNUNET_free(buf); |
200 | 206 | ||
201 | fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); | 207 | fn2 = GNUNET_DISK_mktemp("gnunet-list_indexed-test-dst"); |
202 | buf = GNUNET_malloc (FILESIZE); | 208 | buf = GNUNET_malloc(FILESIZE); |
203 | for (i = 0; i < FILESIZE; i++) | 209 | for (i = 0; i < FILESIZE; i++) |
204 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 210 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
205 | GNUNET_assert (FILESIZE == | 211 | GNUNET_assert(FILESIZE == |
206 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, | 212 | GNUNET_DISK_fn_write(fn2, buf, FILESIZE, |
207 | GNUNET_DISK_PERM_USER_READ | | 213 | GNUNET_DISK_PERM_USER_READ | |
208 | GNUNET_DISK_PERM_USER_WRITE)); | 214 | GNUNET_DISK_PERM_USER_WRITE)); |
209 | GNUNET_free (buf); | 215 | GNUNET_free(buf); |
210 | 216 | ||
211 | meta = GNUNET_CONTAINER_meta_data_create (); | 217 | meta = GNUNET_CONTAINER_meta_data_create(); |
212 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 218 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); |
213 | bo.content_priority = 42; | 219 | bo.content_priority = 42; |
214 | bo.anonymity_level = 1; | 220 | bo.anonymity_level = 1; |
215 | bo.replication_level = 0; | 221 | bo.replication_level = 0; |
216 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 222 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); |
217 | fi1 = | 223 | fi1 = |
218 | GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context1", | 224 | GNUNET_FS_file_information_create_from_file(fs, "list_indexed-context1", |
219 | fn1, kuri, meta, GNUNET_YES, | 225 | fn1, kuri, meta, GNUNET_YES, |
220 | &bo); | 226 | &bo); |
221 | GNUNET_assert (NULL != fi1); | 227 | GNUNET_assert(NULL != fi1); |
222 | bo.anonymity_level = 2; | 228 | bo.anonymity_level = 2; |
223 | fi2 = | 229 | fi2 = |
224 | GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context2", | 230 | GNUNET_FS_file_information_create_from_file(fs, "list_indexed-context2", |
225 | fn2, kuri, meta, GNUNET_YES, | 231 | fn2, kuri, meta, GNUNET_YES, |
226 | &bo); | 232 | &bo); |
227 | GNUNET_assert (NULL != fi2); | 233 | GNUNET_assert(NULL != fi2); |
228 | bo.anonymity_level = 3; | 234 | bo.anonymity_level = 3; |
229 | fidir = | 235 | fidir = |
230 | GNUNET_FS_file_information_create_empty_directory (fs, | 236 | GNUNET_FS_file_information_create_empty_directory(fs, |
231 | "list_indexed-context-dir", | 237 | "list_indexed-context-dir", |
232 | kuri, meta, &bo, NULL); | 238 | kuri, meta, &bo, NULL); |
233 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); | 239 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1)); |
234 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); | 240 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2)); |
235 | GNUNET_FS_uri_destroy (kuri); | 241 | GNUNET_FS_uri_destroy(kuri); |
236 | GNUNET_CONTAINER_meta_data_destroy (meta); | 242 | GNUNET_CONTAINER_meta_data_destroy(meta); |
237 | GNUNET_assert (NULL != fidir); | 243 | GNUNET_assert(NULL != fidir); |
238 | start = GNUNET_TIME_absolute_get (); | 244 | start = GNUNET_TIME_absolute_get(); |
239 | publish = | 245 | publish = |
240 | GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, | 246 | GNUNET_FS_publish_start(fs, fidir, NULL, NULL, NULL, |
241 | GNUNET_FS_PUBLISH_OPTION_NONE); | 247 | GNUNET_FS_PUBLISH_OPTION_NONE); |
242 | GNUNET_assert (publish != NULL); | 248 | GNUNET_assert(publish != NULL); |
243 | } | 249 | } |
244 | 250 | ||
245 | 251 | ||
246 | int | 252 | int |
247 | main (int argc, char *argv[]) | 253 | main(int argc, char *argv[]) |
248 | { | 254 | { |
249 | if (0 != GNUNET_TESTING_peer_run ("test-fs-list-indexed", | 255 | if (0 != GNUNET_TESTING_peer_run("test-fs-list-indexed", |
250 | "test_fs_list_indexed_data.conf", | 256 | "test_fs_list_indexed_data.conf", |
251 | &run, NULL)) | 257 | &run, NULL)) |
252 | return 1; | 258 | return 1; |
253 | return 0; | 259 | return 0; |
254 | } | 260 | } |
diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c index 43c899b72..3abbd5063 100644 --- a/src/fs/test_fs_namespace.c +++ b/src/fs/test_fs_namespace.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_fs_namespace.c | 22 | * @file fs/test_fs_namespace.c |
@@ -49,118 +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) | ||
59 | { | 55 | { |
60 | GNUNET_FS_stop (fs); | 56 | GNUNET_FS_search_stop(ksk_search); |
61 | if (NULL != kill_task) | 57 | ksk_search = NULL; |
62 | GNUNET_SCHEDULER_cancel (kill_task); | 58 | if (sks_search == NULL) |
59 | { | ||
60 | GNUNET_FS_stop(fs); | ||
61 | if (NULL != kill_task) | ||
62 | GNUNET_SCHEDULER_cancel(kill_task); | ||
63 | } | ||
63 | } | 64 | } |
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) | ||
102 | { | ||
103 | if (!GNUNET_FS_uri_test_equal | ||
104 | (sks_expect_uri, event->value.search.specifics.result.uri)) | ||
105 | { | ||
106 | fprintf (stderr, "%s", "Wrong result for sks search!\n"); | ||
107 | err = 1; | ||
108 | } | ||
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 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
130 | fprintf (stderr, "Error searching file: %s\n", | ||
131 | event->value.search.specifics.error.message); | ||
132 | if (sks_search == event->value.search.sc) | ||
133 | GNUNET_SCHEDULER_add_now (&abort_sks_search_task, NULL); | ||
134 | else if (ksk_search == event->value.search.sc) | ||
135 | GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL); | ||
136 | else | ||
137 | GNUNET_break (0); | ||
138 | break; | ||
139 | case GNUNET_FS_STATUS_SEARCH_START: | ||
140 | GNUNET_assert ((NULL == event->value.search.cctx) || | ||
141 | (0 == strcmp ("sks_search", event->value.search.cctx)) || | ||
142 | (0 == strcmp ("ksk_search", event->value.search.cctx))); | ||
143 | if (NULL == event->value.search.cctx) | ||
144 | { | 99 | { |
145 | GNUNET_assert (0 == strcmp ("sks_search", event->value.search.pctx)); | 100 | case GNUNET_FS_STATUS_SEARCH_RESULT: |
146 | update_started = GNUNET_YES; | 101 | if (sks_search == event->value.search.sc) |
102 | { | ||
103 | if (!GNUNET_FS_uri_test_equal | ||
104 | (sks_expect_uri, event->value.search.specifics.result.uri)) | ||
105 | { | ||
106 | fprintf(stderr, "%s", "Wrong result for sks search!\n"); | ||
107 | err = 1; | ||
108 | } | ||
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; | ||
147 | } | 162 | } |
148 | GNUNET_assert (1 == event->value.search.anonymity); | ||
149 | break; | ||
150 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
151 | return NULL; | ||
152 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
153 | return NULL; | ||
154 | default: | ||
155 | fprintf (stderr, "Unexpected event: %d\n", event->status); | ||
156 | break; | ||
157 | } | ||
158 | return event->value.search.cctx; | 163 | return event->value.search.cctx; |
159 | } | 164 | } |
160 | 165 | ||
161 | 166 | ||
162 | static void | 167 | static void |
163 | 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) |
164 | { | 169 | { |
165 | char *msg; | 170 | char *msg; |
166 | struct GNUNET_FS_Uri *sks_uri; | 171 | struct GNUNET_FS_Uri *sks_uri; |
@@ -169,37 +174,37 @@ publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) | |||
169 | char *ret; | 174 | char *ret; |
170 | 175 | ||
171 | if (NULL != emsg) | 176 | if (NULL != emsg) |
172 | { | 177 | { |
173 | fprintf (stderr, "Error publishing: %s\n", emsg); | 178 | fprintf(stderr, "Error publishing: %s\n", emsg); |
174 | err = 1; | 179 | err = 1; |
175 | GNUNET_FS_stop (fs); | 180 | GNUNET_FS_stop(fs); |
176 | return; | 181 | return; |
177 | } | 182 | } |
178 | 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)); |
179 | GNUNET_assert (NULL != ret); | 184 | GNUNET_assert(NULL != ret); |
180 | ret[0] = '\0'; | 185 | ret[0] = '\0'; |
181 | GNUNET_snprintf (sbuf, sizeof (sbuf), "gnunet://fs/sks/%s/this", buf); | 186 | GNUNET_snprintf(sbuf, sizeof(sbuf), "gnunet://fs/sks/%s/this", buf); |
182 | sks_uri = GNUNET_FS_uri_parse (sbuf, &msg); | 187 | sks_uri = GNUNET_FS_uri_parse(sbuf, &msg); |
183 | if (NULL == sks_uri) | 188 | if (NULL == sks_uri) |
184 | { | 189 | { |
185 | fprintf (stderr, "failed to parse URI `%s': %s\n", sbuf, msg); | 190 | fprintf(stderr, "failed to parse URI `%s': %s\n", sbuf, msg); |
186 | err = 1; | 191 | err = 1; |
187 | GNUNET_FS_stop (fs); | 192 | GNUNET_FS_stop(fs); |
188 | GNUNET_free_non_null (msg); | 193 | GNUNET_free_non_null(msg); |
189 | return; | 194 | return; |
190 | } | 195 | } |
191 | ksk_search = | 196 | ksk_search = |
192 | 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, |
193 | "ksk_search"); | 198 | "ksk_search"); |
194 | sks_search = | 199 | sks_search = |
195 | 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, |
196 | "sks_search"); | 201 | "sks_search"); |
197 | GNUNET_FS_uri_destroy (sks_uri); | 202 | GNUNET_FS_uri_destroy(sks_uri); |
198 | } | 203 | } |
199 | 204 | ||
200 | 205 | ||
201 | static void | 206 | static void |
202 | 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) |
203 | { | 208 | { |
204 | struct GNUNET_CONTAINER_MetaData *meta; | 209 | struct GNUNET_CONTAINER_MetaData *meta; |
205 | struct GNUNET_FS_Uri *ksk_uri; | 210 | struct GNUNET_FS_Uri *ksk_uri; |
@@ -207,61 +212,61 @@ sks_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | |||
207 | struct GNUNET_FS_BlockOptions bo; | 212 | struct GNUNET_FS_BlockOptions bo; |
208 | 213 | ||
209 | if (NULL == uri) | 214 | if (NULL == uri) |
210 | { | 215 | { |
211 | fprintf (stderr, "Error publishing: %s\n", emsg); | 216 | fprintf(stderr, "Error publishing: %s\n", emsg); |
212 | err = 1; | 217 | err = 1; |
213 | GNUNET_FS_stop (fs); | 218 | GNUNET_FS_stop(fs); |
214 | return; | 219 | return; |
215 | } | 220 | } |
216 | meta = GNUNET_CONTAINER_meta_data_create (); | 221 | meta = GNUNET_CONTAINER_meta_data_create(); |
217 | msg = NULL; | 222 | msg = NULL; |
218 | 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); |
219 | GNUNET_assert (NULL == msg); | 224 | GNUNET_assert(NULL == msg); |
220 | ksk_expect_uri = GNUNET_FS_uri_dup (uri); | 225 | ksk_expect_uri = GNUNET_FS_uri_dup(uri); |
221 | bo.content_priority = 1; | 226 | bo.content_priority = 1; |
222 | bo.anonymity_level = 1; | 227 | bo.anonymity_level = 1; |
223 | bo.replication_level = 0; | 228 | bo.replication_level = 0; |
224 | bo.expiration_time = | 229 | bo.expiration_time = |
225 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); | 230 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); |
226 | GNUNET_FS_publish_ksk (fs, ksk_uri, meta, uri, &bo, | 231 | GNUNET_FS_publish_ksk(fs, ksk_uri, meta, uri, &bo, |
227 | GNUNET_FS_PUBLISH_OPTION_NONE, &publish_cont, NULL); | 232 | GNUNET_FS_PUBLISH_OPTION_NONE, &publish_cont, NULL); |
228 | GNUNET_FS_uri_destroy (ksk_uri); | 233 | GNUNET_FS_uri_destroy(ksk_uri); |
229 | GNUNET_CONTAINER_meta_data_destroy (meta); | 234 | GNUNET_CONTAINER_meta_data_destroy(meta); |
230 | } | 235 | } |
231 | 236 | ||
232 | 237 | ||
233 | static void | 238 | static void |
234 | 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) |
235 | { | 240 | { |
236 | struct GNUNET_CONTAINER_MetaData *meta; | 241 | struct GNUNET_CONTAINER_MetaData *meta; |
237 | struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; | 242 | struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; |
238 | struct GNUNET_FS_BlockOptions bo; | 243 | struct GNUNET_FS_BlockOptions bo; |
239 | 244 | ||
240 | if (NULL != emsg) | 245 | if (NULL != emsg) |
241 | { | 246 | { |
242 | fprintf (stderr, "Error publishing: %s\n", emsg); | 247 | fprintf(stderr, "Error publishing: %s\n", emsg); |
243 | err = 1; | 248 | err = 1; |
244 | GNUNET_FS_stop (fs); | 249 | GNUNET_FS_stop(fs); |
245 | return; | 250 | return; |
246 | } | 251 | } |
247 | ns = GNUNET_CRYPTO_ecdsa_key_create (); | 252 | ns = GNUNET_CRYPTO_ecdsa_key_create(); |
248 | meta = GNUNET_CONTAINER_meta_data_create (); | 253 | meta = GNUNET_CONTAINER_meta_data_create(); |
249 | sks_expect_uri = GNUNET_FS_uri_dup (uri); | 254 | sks_expect_uri = GNUNET_FS_uri_dup(uri); |
250 | bo.content_priority = 1; | 255 | bo.content_priority = 1; |
251 | bo.anonymity_level = 1; | 256 | bo.anonymity_level = 1; |
252 | bo.replication_level = 0; | 257 | bo.replication_level = 0; |
253 | bo.expiration_time = | 258 | bo.expiration_time = |
254 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); | 259 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); |
255 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, &nsid); | 260 | GNUNET_CRYPTO_ecdsa_key_get_public(ns, &nsid); |
256 | GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri, | 261 | GNUNET_FS_publish_sks(fs, ns, "this", "next", meta, uri, |
257 | &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL); | 262 | &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL); |
258 | GNUNET_CONTAINER_meta_data_destroy (meta); | 263 | GNUNET_CONTAINER_meta_data_destroy(meta); |
259 | GNUNET_free (ns); | 264 | GNUNET_free(ns); |
260 | } | 265 | } |
261 | 266 | ||
262 | 267 | ||
263 | static void | 268 | static void |
264 | testNamespace () | 269 | testNamespace() |
265 | { | 270 | { |
266 | struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; | 271 | struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; |
267 | struct GNUNET_FS_BlockOptions bo; | 272 | struct GNUNET_FS_BlockOptions bo; |
@@ -269,46 +274,46 @@ testNamespace () | |||
269 | struct GNUNET_FS_Uri *ksk_uri; | 274 | struct GNUNET_FS_Uri *ksk_uri; |
270 | struct GNUNET_FS_Uri *sks_uri; | 275 | struct GNUNET_FS_Uri *sks_uri; |
271 | 276 | ||
272 | ns = GNUNET_CRYPTO_ecdsa_key_create (); | 277 | ns = GNUNET_CRYPTO_ecdsa_key_create(); |
273 | meta = GNUNET_CONTAINER_meta_data_create (); | 278 | meta = GNUNET_CONTAINER_meta_data_create(); |
274 | ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/testnsa", NULL); | 279 | ksk_uri = GNUNET_FS_uri_parse("gnunet://fs/ksk/testnsa", NULL); |
275 | bo.content_priority = 1; | 280 | bo.content_priority = 1; |
276 | bo.anonymity_level = 1; | 281 | bo.anonymity_level = 1; |
277 | bo.replication_level = 0; | 282 | bo.replication_level = 0; |
278 | bo.expiration_time = | 283 | bo.expiration_time = |
279 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); | 284 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); |
280 | sks_uri = GNUNET_FS_uri_sks_create (&nsid, "root"); | 285 | sks_uri = GNUNET_FS_uri_sks_create(&nsid, "root"); |
281 | GNUNET_FS_publish_ksk (fs, | 286 | GNUNET_FS_publish_ksk(fs, |
282 | ksk_uri, meta, sks_uri, | 287 | ksk_uri, meta, sks_uri, |
283 | &bo, GNUNET_FS_PUBLISH_OPTION_NONE, | 288 | &bo, GNUNET_FS_PUBLISH_OPTION_NONE, |
284 | &adv_cont, NULL); | 289 | &adv_cont, NULL); |
285 | GNUNET_FS_uri_destroy (sks_uri); | 290 | GNUNET_FS_uri_destroy(sks_uri); |
286 | kill_task = | 291 | kill_task = |
287 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &do_timeout, | 292 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, &do_timeout, |
288 | NULL); | 293 | NULL); |
289 | GNUNET_FS_uri_destroy (ksk_uri); | 294 | GNUNET_FS_uri_destroy(ksk_uri); |
290 | GNUNET_CONTAINER_meta_data_destroy (meta); | 295 | GNUNET_CONTAINER_meta_data_destroy(meta); |
291 | GNUNET_free (ns); | 296 | GNUNET_free(ns); |
292 | } | 297 | } |
293 | 298 | ||
294 | 299 | ||
295 | static void | 300 | static void |
296 | run (void *cls, | 301 | run(void *cls, |
297 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 302 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
298 | struct GNUNET_TESTING_Peer *peer) | 303 | struct GNUNET_TESTING_Peer *peer) |
299 | { | 304 | { |
300 | fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL, | 305 | fs = GNUNET_FS_start(cfg, "test-fs-namespace", &progress_cb, NULL, |
301 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 306 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
302 | testNamespace (); | 307 | testNamespace(); |
303 | } | 308 | } |
304 | 309 | ||
305 | 310 | ||
306 | int | 311 | int |
307 | main (int argc, char *argv[]) | 312 | main(int argc, char *argv[]) |
308 | { | 313 | { |
309 | if (0 != GNUNET_TESTING_peer_run ("test-fs-namespace", | 314 | if (0 != GNUNET_TESTING_peer_run("test-fs-namespace", |
310 | "test_fs_namespace_data.conf", | 315 | "test_fs_namespace_data.conf", |
311 | &run, NULL)) | 316 | &run, NULL)) |
312 | return 1; | 317 | return 1; |
313 | return err; | 318 | return err; |
314 | } | 319 | } |
diff --git a/src/fs/test_fs_namespace_list_updateable.c b/src/fs/test_fs_namespace_list_updateable.c index 99c0967b8..9a28fcb1b 100644 --- a/src/fs/test_fs_namespace_list_updateable.c +++ b/src/fs/test_fs_namespace_list_updateable.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_fs_namespace_list_updateable.c | 22 | * @file fs/test_fs_namespace_list_updateable.c |
@@ -45,129 +45,128 @@ 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 | |||
124 | } | 123 | } |
125 | 124 | ||
126 | 125 | ||
127 | static void | 126 | static void |
128 | testNamespace () | 127 | testNamespace() |
129 | { | 128 | { |
130 | ns = GNUNET_CRYPTO_ecdsa_key_create (); | 129 | ns = GNUNET_CRYPTO_ecdsa_key_create(); |
131 | GNUNET_assert (NULL != ns); | 130 | GNUNET_assert(NULL != ns); |
132 | bo.content_priority = 1; | 131 | bo.content_priority = 1; |
133 | bo.anonymity_level = 1; | 132 | bo.anonymity_level = 1; |
134 | bo.replication_level = 0; | 133 | bo.replication_level = 0; |
135 | bo.expiration_time = | 134 | bo.expiration_time = |
136 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); | 135 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); |
137 | meta = GNUNET_CONTAINER_meta_data_create (); | 136 | meta = GNUNET_CONTAINER_meta_data_create(); |
138 | 137 | ||
139 | uri_this = | 138 | uri_this = |
140 | GNUNET_FS_uri_parse | 139 | GNUNET_FS_uri_parse |
141 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", | 140 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", |
142 | NULL); | 141 | NULL); |
143 | uri_next = | 142 | uri_next = |
144 | GNUNET_FS_uri_parse | 143 | GNUNET_FS_uri_parse |
145 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43", | 144 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43", |
146 | NULL); | 145 | NULL); |
147 | GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri_this, &bo, | 146 | GNUNET_FS_publish_sks(fs, ns, "this", "next", meta, uri_this, &bo, |
148 | GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL); | 147 | GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL); |
149 | } | 148 | } |
150 | 149 | ||
151 | 150 | ||
152 | static void | 151 | static void |
153 | run (void *cls, | 152 | run(void *cls, |
154 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 153 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
155 | struct GNUNET_TESTING_Peer *peer) | 154 | struct GNUNET_TESTING_Peer *peer) |
156 | { | 155 | { |
157 | fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL, | 156 | fs = GNUNET_FS_start(cfg, "test-fs-namespace", &progress_cb, NULL, |
158 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 157 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
159 | testNamespace (); | 158 | testNamespace(); |
160 | } | 159 | } |
161 | 160 | ||
162 | 161 | ||
163 | int | 162 | int |
164 | main (int argc, char *argv[]) | 163 | main(int argc, char *argv[]) |
165 | { | 164 | { |
166 | if (0 != GNUNET_TESTING_peer_run ("test-fs-namespace-list-updateable", | 165 | if (0 != GNUNET_TESTING_peer_run("test-fs-namespace-list-updateable", |
167 | "test_fs_namespace_data.conf", | 166 | "test_fs_namespace_data.conf", |
168 | &run, NULL)) | 167 | &run, NULL)) |
169 | return 1; | 168 | return 1; |
170 | do_shutdown (); | 169 | do_shutdown(); |
171 | return err; | 170 | return err; |
172 | } | 171 | } |
173 | 172 | ||
diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c index fe54bb552..02c1587d2 100644 --- a/src/fs/test_fs_publish.c +++ b/src/fs/test_fs_publish.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/test_fs_publish.c | 21 | * @file fs/test_fs_publish.c |
22 | * @brief simple testcase for publish operation (indexing, listing | 22 | * @brief simple testcase for publish operation (indexing, listing |
@@ -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,105 +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 | { | 81 | { |
82 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 82 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
83 | ret = event->value.publish.cctx; | 83 | ret = event->value.publish.cctx; |
84 | printf ("Publish complete, %llu kbps.\n", | 84 | printf("Publish complete, %llu kbps.\n", |
85 | (unsigned long long) (FILESIZE * 1000000LL / | 85 | (unsigned long long)(FILESIZE * 1000000LL / |
86 | (1 + | 86 | (1 + |
87 | GNUNET_TIME_absolute_get_duration | 87 | GNUNET_TIME_absolute_get_duration |
88 | (start).rel_value_us) / 1024)); | 88 | (start).rel_value_us) / 1024)); |
89 | if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | 89 | if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) |
90 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 90 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); |
91 | break; | 91 | break; |
92 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 92 | |
93 | ret = event->value.publish.cctx; | 93 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
94 | GNUNET_assert (publish == event->value.publish.pc); | 94 | ret = event->value.publish.cctx; |
95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 95 | GNUNET_assert(publish == event->value.publish.pc); |
96 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 96 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
97 | (unsigned long long) event->value.publish.completed, | 97 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
98 | (unsigned long long) event->value.publish.size, | 98 | (unsigned long long)event->value.publish.completed, |
99 | event->value.publish.specifics.progress.depth, | 99 | (unsigned long long)event->value.publish.size, |
100 | (unsigned long long) event->value.publish.specifics. | 100 | event->value.publish.specifics.progress.depth, |
101 | progress.offset); | 101 | (unsigned long long)event->value.publish.specifics. |
102 | break; | 102 | progress.offset); |
103 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 103 | break; |
104 | ret = event->value.publish.cctx; | 104 | |
105 | break; | 105 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
106 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 106 | ret = event->value.publish.cctx; |
107 | ret = event->value.publish.cctx; | 107 | break; |
108 | fprintf (stderr, "Error publishing file: %s\n", | 108 | |
109 | event->value.publish.specifics.error.message); | 109 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
110 | err = 1; | 110 | ret = event->value.publish.cctx; |
111 | if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | 111 | fprintf(stderr, "Error publishing file: %s\n", |
112 | { | 112 | event->value.publish.specifics.error.message); |
113 | fprintf (stderr, "Scheduling abort task for error on `%s'\n", | 113 | err = 1; |
114 | (const char *) event->value.publish.cctx); | 114 | if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) |
115 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 115 | { |
116 | } | 116 | fprintf(stderr, "Scheduling abort task for error on `%s'\n", |
117 | break; | 117 | (const char *)event->value.publish.cctx); |
118 | case GNUNET_FS_STATUS_PUBLISH_START: | 118 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); |
119 | ret = event->value.publish.cctx; | 119 | } |
120 | if (0 == strcmp ("publish-context1", event->value.publish.cctx)) | 120 | break; |
121 | { | 121 | |
122 | GNUNET_assert (0 == | 122 | case GNUNET_FS_STATUS_PUBLISH_START: |
123 | strcmp ("publish-context-dir", event->value.publish.pctx)); | 123 | ret = event->value.publish.cctx; |
124 | GNUNET_assert (FILESIZE == event->value.publish.size); | 124 | if (0 == strcmp("publish-context1", event->value.publish.cctx)) |
125 | GNUNET_assert (0 == event->value.publish.completed); | 125 | { |
126 | GNUNET_assert (1 == event->value.publish.anonymity); | 126 | GNUNET_assert(0 == |
127 | } | 127 | strcmp("publish-context-dir", event->value.publish.pctx)); |
128 | else if (0 == strcmp ("publish-context2", event->value.publish.cctx)) | 128 | GNUNET_assert(FILESIZE == event->value.publish.size); |
129 | { | 129 | GNUNET_assert(0 == event->value.publish.completed); |
130 | GNUNET_assert (0 == | 130 | GNUNET_assert(1 == event->value.publish.anonymity); |
131 | strcmp ("publish-context-dir", event->value.publish.pctx)); | 131 | } |
132 | GNUNET_assert (FILESIZE == event->value.publish.size); | 132 | else if (0 == strcmp("publish-context2", event->value.publish.cctx)) |
133 | GNUNET_assert (0 == event->value.publish.completed); | 133 | { |
134 | GNUNET_assert (2 == event->value.publish.anonymity); | 134 | GNUNET_assert(0 == |
135 | } | 135 | strcmp("publish-context-dir", event->value.publish.pctx)); |
136 | else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | 136 | GNUNET_assert(FILESIZE == event->value.publish.size); |
137 | { | 137 | GNUNET_assert(0 == event->value.publish.completed); |
138 | GNUNET_assert (0 == event->value.publish.completed); | 138 | GNUNET_assert(2 == event->value.publish.anonymity); |
139 | GNUNET_assert (3 == 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; | ||
140 | } | 157 | } |
141 | else | ||
142 | GNUNET_assert (0); | ||
143 | break; | ||
144 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
145 | if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | ||
146 | GNUNET_assert (publish == event->value.publish.pc); | ||
147 | break; | ||
148 | default: | ||
149 | printf ("Unexpected event: %d\n", event->status); | ||
150 | break; | ||
151 | } | ||
152 | return ret; | 158 | return ret; |
153 | } | 159 | } |
154 | 160 | ||
155 | 161 | ||
156 | static void | 162 | static void |
157 | run (void *cls, | 163 | run(void *cls, |
158 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 164 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
159 | struct GNUNET_TESTING_Peer *peer) | 165 | struct GNUNET_TESTING_Peer *peer) |
160 | { | 166 | { |
161 | const char *keywords[] = { | 167 | const char *keywords[] = { |
162 | "down_foo", | 168 | "down_foo", |
@@ -171,70 +177,70 @@ run (void *cls, | |||
171 | size_t i; | 177 | size_t i; |
172 | struct GNUNET_FS_BlockOptions bo; | 178 | struct GNUNET_FS_BlockOptions bo; |
173 | 179 | ||
174 | fs = GNUNET_FS_start (cfg, "test-fs-publish", &progress_cb, NULL, | 180 | fs = GNUNET_FS_start(cfg, "test-fs-publish", &progress_cb, NULL, |
175 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 181 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
176 | GNUNET_assert (NULL != fs); | 182 | GNUNET_assert(NULL != fs); |
177 | fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); | 183 | fn1 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); |
178 | buf = GNUNET_malloc (FILESIZE); | 184 | buf = GNUNET_malloc(FILESIZE); |
179 | for (i = 0; i < FILESIZE; i++) | 185 | for (i = 0; i < FILESIZE; i++) |
180 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 186 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
181 | GNUNET_assert (FILESIZE == | 187 | GNUNET_assert(FILESIZE == |
182 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | 188 | GNUNET_DISK_fn_write(fn1, buf, FILESIZE, |
183 | GNUNET_DISK_PERM_USER_READ | | 189 | GNUNET_DISK_PERM_USER_READ | |
184 | GNUNET_DISK_PERM_USER_WRITE)); | 190 | GNUNET_DISK_PERM_USER_WRITE)); |
185 | GNUNET_free (buf); | 191 | GNUNET_free(buf); |
186 | 192 | ||
187 | fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); | 193 | fn2 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); |
188 | buf = GNUNET_malloc (FILESIZE); | 194 | buf = GNUNET_malloc(FILESIZE); |
189 | for (i = 0; i < FILESIZE; i++) | 195 | for (i = 0; i < FILESIZE; i++) |
190 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 196 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
191 | GNUNET_assert (FILESIZE == | 197 | GNUNET_assert(FILESIZE == |
192 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, | 198 | GNUNET_DISK_fn_write(fn2, buf, FILESIZE, |
193 | GNUNET_DISK_PERM_USER_READ | | 199 | GNUNET_DISK_PERM_USER_READ | |
194 | GNUNET_DISK_PERM_USER_WRITE)); | 200 | GNUNET_DISK_PERM_USER_WRITE)); |
195 | GNUNET_free (buf); | 201 | GNUNET_free(buf); |
196 | 202 | ||
197 | meta = GNUNET_CONTAINER_meta_data_create (); | 203 | meta = GNUNET_CONTAINER_meta_data_create(); |
198 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 204 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); |
199 | bo.content_priority = 42; | 205 | bo.content_priority = 42; |
200 | bo.anonymity_level = 1; | 206 | bo.anonymity_level = 1; |
201 | bo.replication_level = 0; | 207 | bo.replication_level = 0; |
202 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 208 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); |
203 | 209 | ||
204 | fi1 = | 210 | fi1 = |
205 | GNUNET_FS_file_information_create_from_file (fs, "publish-context1", fn1, | 211 | GNUNET_FS_file_information_create_from_file(fs, "publish-context1", fn1, |
206 | kuri, meta, GNUNET_YES, &bo); | 212 | kuri, meta, GNUNET_YES, &bo); |
207 | 213 | ||
208 | GNUNET_assert (NULL != fi1); | 214 | GNUNET_assert(NULL != fi1); |
209 | bo.anonymity_level = 2; | 215 | bo.anonymity_level = 2; |
210 | fi2 = | 216 | fi2 = |
211 | GNUNET_FS_file_information_create_from_file (fs, "publish-context2", fn2, | 217 | GNUNET_FS_file_information_create_from_file(fs, "publish-context2", fn2, |
212 | kuri, meta, GNUNET_YES, &bo); | 218 | kuri, meta, GNUNET_YES, &bo); |
213 | GNUNET_assert (NULL != fi2); | 219 | GNUNET_assert(NULL != fi2); |
214 | bo.anonymity_level = 3; | 220 | bo.anonymity_level = 3; |
215 | fidir = | 221 | fidir = |
216 | GNUNET_FS_file_information_create_empty_directory (fs, | 222 | GNUNET_FS_file_information_create_empty_directory(fs, |
217 | "publish-context-dir", | 223 | "publish-context-dir", |
218 | kuri, meta, &bo, NULL); | 224 | kuri, meta, &bo, NULL); |
219 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); | 225 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1)); |
220 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); | 226 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2)); |
221 | GNUNET_FS_uri_destroy (kuri); | 227 | GNUNET_FS_uri_destroy(kuri); |
222 | GNUNET_CONTAINER_meta_data_destroy (meta); | 228 | GNUNET_CONTAINER_meta_data_destroy(meta); |
223 | GNUNET_assert (NULL != fidir); | 229 | GNUNET_assert(NULL != fidir); |
224 | start = GNUNET_TIME_absolute_get (); | 230 | start = GNUNET_TIME_absolute_get(); |
225 | publish = | 231 | publish = |
226 | GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, | 232 | GNUNET_FS_publish_start(fs, fidir, NULL, NULL, NULL, |
227 | GNUNET_FS_PUBLISH_OPTION_NONE); | 233 | GNUNET_FS_PUBLISH_OPTION_NONE); |
228 | GNUNET_assert (publish != NULL); | 234 | GNUNET_assert(publish != NULL); |
229 | } | 235 | } |
230 | 236 | ||
231 | 237 | ||
232 | int | 238 | int |
233 | main (int argc, char *argv[]) | 239 | main(int argc, char *argv[]) |
234 | { | 240 | { |
235 | if (0 != GNUNET_TESTING_peer_run ("test-fs-publish", | 241 | if (0 != GNUNET_TESTING_peer_run("test-fs-publish", |
236 | "test_fs_publish_data.conf", | 242 | "test_fs_publish_data.conf", |
237 | &run, NULL)) | 243 | &run, NULL)) |
238 | return 1; | 244 | return 1; |
239 | return err; | 245 | return err; |
240 | } | 246 | } |
diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c index 6242e66f8..7cba55179 100644 --- a/src/fs/test_fs_publish_persistence.c +++ b/src/fs/test_fs_publish_persistence.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/test_fs_publish_persistence.c | 21 | * @file fs/test_fs_publish_persistence.c |
22 | * @brief simple testcase for persistence of simple publish operation | 22 | * @brief simple testcase for persistence of simple publish operation |
@@ -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,115 +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 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 147 | |
148 | ret = event->value.publish.cctx; | 148 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
149 | return ret; | 149 | ret = event->value.publish.cctx; |
150 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 150 | return ret; |
151 | consider_restart (event->status); | 151 | |
152 | ret = event->value.publish.cctx; | 152 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
153 | GNUNET_assert (publish == event->value.publish.pc); | 153 | consider_restart(event->status); |
154 | ret = event->value.publish.cctx; | ||
155 | GNUNET_assert(publish == event->value.publish.pc); | ||
154 | #if VERBOSE | 156 | #if VERBOSE |
155 | 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", |
156 | (unsigned long long) event->value.publish.completed, | 158 | (unsigned long long)event->value.publish.completed, |
157 | (unsigned long long) event->value.publish.size, | 159 | (unsigned long long)event->value.publish.size, |
158 | event->value.publish.specifics.progress.depth, | 160 | event->value.publish.specifics.progress.depth, |
159 | (unsigned long long) event->value.publish.specifics. | 161 | (unsigned long long)event->value.publish.specifics. |
160 | progress.offset); | 162 | progress.offset); |
161 | #endif | 163 | #endif |
162 | break; | 164 | break; |
163 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: | 165 | |
164 | if (event->value.publish.pc == publish) | 166 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: |
165 | publish = NULL; | 167 | if (event->value.publish.pc == publish) |
166 | break; | 168 | publish = NULL; |
167 | case GNUNET_FS_STATUS_PUBLISH_RESUME: | 169 | break; |
168 | if (NULL == publish) | 170 | |
169 | { | 171 | case GNUNET_FS_STATUS_PUBLISH_RESUME: |
170 | GNUNET_assert (GNUNET_YES == | 172 | if (NULL == publish) |
171 | GNUNET_FS_file_information_is_directory (event-> | 173 | { |
172 | value.publish. | 174 | GNUNET_assert(GNUNET_YES == |
173 | fi)); | 175 | GNUNET_FS_file_information_is_directory(event-> |
176 | value.publish. | ||
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); | ||
174 | publish = event->value.publish.pc; | 193 | publish = event->value.publish.pc; |
175 | return "publish-context-dir"; | 194 | ret = event->value.publish.cctx; |
176 | } | 195 | if (0 == strcmp("publish-context1", event->value.publish.cctx)) |
177 | break; | 196 | { |
178 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 197 | GNUNET_assert(0 == |
179 | ret = event->value.publish.cctx; | 198 | strcmp("publish-context-dir", event->value.publish.pctx)); |
180 | fprintf (stderr, "Error publishing file: %s\n", | 199 | GNUNET_assert(FILESIZE == event->value.publish.size); |
181 | event->value.publish.specifics.error.message); | 200 | GNUNET_assert(0 == event->value.publish.completed); |
182 | err = 1; | 201 | GNUNET_assert(1 == event->value.publish.anonymity); |
183 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 202 | } |
184 | break; | 203 | else if (0 == strcmp("publish-context2", event->value.publish.cctx)) |
185 | case GNUNET_FS_STATUS_PUBLISH_START: | 204 | { |
186 | consider_restart (event->status); | 205 | GNUNET_assert(0 == |
187 | publish = event->value.publish.pc; | 206 | strcmp("publish-context-dir", event->value.publish.pctx)); |
188 | ret = event->value.publish.cctx; | 207 | GNUNET_assert(FILESIZE == event->value.publish.size); |
189 | if (0 == strcmp ("publish-context1", event->value.publish.cctx)) | 208 | GNUNET_assert(0 == event->value.publish.completed); |
190 | { | 209 | GNUNET_assert(2 == event->value.publish.anonymity); |
191 | GNUNET_assert (0 == | 210 | } |
192 | strcmp ("publish-context-dir", event->value.publish.pctx)); | 211 | else if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) |
193 | GNUNET_assert (FILESIZE == event->value.publish.size); | 212 | { |
194 | GNUNET_assert (0 == event->value.publish.completed); | 213 | GNUNET_assert(0 == event->value.publish.completed); |
195 | GNUNET_assert (1 == event->value.publish.anonymity); | 214 | GNUNET_assert(3 == event->value.publish.anonymity); |
196 | } | 215 | } |
197 | else if (0 == strcmp ("publish-context2", event->value.publish.cctx)) | 216 | else |
198 | { | 217 | GNUNET_assert(0); |
199 | GNUNET_assert (0 == | 218 | break; |
200 | strcmp ("publish-context-dir", event->value.publish.pctx)); | 219 | |
201 | GNUNET_assert (FILESIZE == event->value.publish.size); | 220 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
202 | GNUNET_assert (0 == event->value.publish.completed); | 221 | consider_restart(event->status); |
203 | GNUNET_assert (2 == event->value.publish.anonymity); | 222 | if ((NULL != event->value.publish.cctx) && |
204 | } | 223 | (0 == strcmp("publish-context-dir", event->value.publish.cctx))) |
205 | else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | 224 | GNUNET_assert(publish == event->value.publish.pc); |
206 | { | 225 | break; |
207 | GNUNET_assert (0 == event->value.publish.completed); | 226 | |
208 | GNUNET_assert (3 == event->value.publish.anonymity); | 227 | default: |
228 | printf("Unexpected event: %d\n", event->status); | ||
229 | break; | ||
209 | } | 230 | } |
210 | else | ||
211 | GNUNET_assert (0); | ||
212 | break; | ||
213 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
214 | consider_restart (event->status); | ||
215 | if ( (NULL != event->value.publish.cctx) && | ||
216 | (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) ) | ||
217 | GNUNET_assert (publish == event->value.publish.pc); | ||
218 | break; | ||
219 | default: | ||
220 | printf ("Unexpected event: %d\n", event->status); | ||
221 | break; | ||
222 | } | ||
223 | return ret; | 231 | return ret; |
224 | } | 232 | } |
225 | 233 | ||
226 | 234 | ||
227 | static void | 235 | static void |
228 | run (void *cls, | 236 | run(void *cls, |
229 | const struct GNUNET_CONFIGURATION_Handle *c, | 237 | const struct GNUNET_CONFIGURATION_Handle *c, |
230 | struct GNUNET_TESTING_Peer *peer) | 238 | struct GNUNET_TESTING_Peer *peer) |
231 | { | 239 | { |
232 | const char *keywords[] = { | 240 | const char *keywords[] = { |
233 | "down_foo", | 241 | "down_foo", |
@@ -243,67 +251,67 @@ run (void *cls, | |||
243 | struct GNUNET_FS_BlockOptions bo; | 251 | struct GNUNET_FS_BlockOptions bo; |
244 | 252 | ||
245 | cfg = c; | 253 | cfg = c; |
246 | 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, |
247 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 255 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
248 | GNUNET_assert (NULL != fs); | 256 | GNUNET_assert(NULL != fs); |
249 | fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); | 257 | fn1 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); |
250 | buf = GNUNET_malloc (FILESIZE); | 258 | buf = GNUNET_malloc(FILESIZE); |
251 | for (i = 0; i < FILESIZE; i++) | 259 | for (i = 0; i < FILESIZE; i++) |
252 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 260 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
253 | GNUNET_assert (FILESIZE == | 261 | GNUNET_assert(FILESIZE == |
254 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | 262 | GNUNET_DISK_fn_write(fn1, buf, FILESIZE, |
255 | GNUNET_DISK_PERM_USER_READ | | 263 | GNUNET_DISK_PERM_USER_READ | |
256 | GNUNET_DISK_PERM_USER_WRITE)); | 264 | GNUNET_DISK_PERM_USER_WRITE)); |
257 | GNUNET_free (buf); | 265 | GNUNET_free(buf); |
258 | 266 | ||
259 | fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); | 267 | fn2 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); |
260 | buf = GNUNET_malloc (FILESIZE); | 268 | buf = GNUNET_malloc(FILESIZE); |
261 | for (i = 0; i < FILESIZE; i++) | 269 | for (i = 0; i < FILESIZE; i++) |
262 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 270 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
263 | GNUNET_assert (FILESIZE == | 271 | GNUNET_assert(FILESIZE == |
264 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, | 272 | GNUNET_DISK_fn_write(fn2, buf, FILESIZE, |
265 | GNUNET_DISK_PERM_USER_READ | | 273 | GNUNET_DISK_PERM_USER_READ | |
266 | GNUNET_DISK_PERM_USER_WRITE)); | 274 | GNUNET_DISK_PERM_USER_WRITE)); |
267 | GNUNET_free (buf); | 275 | GNUNET_free(buf); |
268 | 276 | ||
269 | meta = GNUNET_CONTAINER_meta_data_create (); | 277 | meta = GNUNET_CONTAINER_meta_data_create(); |
270 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 278 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); |
271 | bo.content_priority = 42; | 279 | bo.content_priority = 42; |
272 | bo.anonymity_level = 1; | 280 | bo.anonymity_level = 1; |
273 | bo.replication_level = 0; | 281 | bo.replication_level = 0; |
274 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 282 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); |
275 | fi1 = | 283 | fi1 = |
276 | GNUNET_FS_file_information_create_from_file (fs, "publish-context1", fn1, | 284 | GNUNET_FS_file_information_create_from_file(fs, "publish-context1", fn1, |
277 | kuri, meta, GNUNET_YES, &bo); | 285 | kuri, meta, GNUNET_YES, &bo); |
278 | GNUNET_assert (NULL != fi1); | 286 | GNUNET_assert(NULL != fi1); |
279 | bo.anonymity_level = 2; | 287 | bo.anonymity_level = 2; |
280 | fi2 = | 288 | fi2 = |
281 | GNUNET_FS_file_information_create_from_file (fs, "publish-context2", fn2, | 289 | GNUNET_FS_file_information_create_from_file(fs, "publish-context2", fn2, |
282 | kuri, meta, GNUNET_YES, &bo); | 290 | kuri, meta, GNUNET_YES, &bo); |
283 | GNUNET_assert (NULL != fi2); | 291 | GNUNET_assert(NULL != fi2); |
284 | bo.anonymity_level = 3; | 292 | bo.anonymity_level = 3; |
285 | fidir = | 293 | fidir = |
286 | GNUNET_FS_file_information_create_empty_directory (fs, | 294 | GNUNET_FS_file_information_create_empty_directory(fs, |
287 | "publish-context-dir", | 295 | "publish-context-dir", |
288 | kuri, meta, &bo, NULL); | 296 | kuri, meta, &bo, NULL); |
289 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); | 297 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1)); |
290 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); | 298 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2)); |
291 | GNUNET_FS_uri_destroy (kuri); | 299 | GNUNET_FS_uri_destroy(kuri); |
292 | GNUNET_CONTAINER_meta_data_destroy (meta); | 300 | GNUNET_CONTAINER_meta_data_destroy(meta); |
293 | GNUNET_assert (NULL != fidir); | 301 | GNUNET_assert(NULL != fidir); |
294 | start = GNUNET_TIME_absolute_get (); | 302 | start = GNUNET_TIME_absolute_get(); |
295 | GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, | 303 | GNUNET_FS_publish_start(fs, fidir, NULL, NULL, NULL, |
296 | GNUNET_FS_PUBLISH_OPTION_NONE); | 304 | GNUNET_FS_PUBLISH_OPTION_NONE); |
297 | GNUNET_assert (publish != NULL); | 305 | GNUNET_assert(publish != NULL); |
298 | } | 306 | } |
299 | 307 | ||
300 | 308 | ||
301 | int | 309 | int |
302 | main (int argc, char *argv[]) | 310 | main(int argc, char *argv[]) |
303 | { | 311 | { |
304 | if (0 != GNUNET_TESTING_peer_run ("test-fs-publish-persistence", | 312 | if (0 != GNUNET_TESTING_peer_run("test-fs-publish-persistence", |
305 | "test_fs_publish_data.conf", | 313 | "test_fs_publish_data.conf", |
306 | &run, NULL)) | 314 | &run, NULL)) |
307 | return 1; | 315 | return 1; |
308 | return err; | 316 | return err; |
309 | } | 317 | } |
diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c index 2a7f4b1dd..7906a4163 100644 --- a/src/fs/test_fs_search.c +++ b/src/fs/test_fs_search.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/test_fs_search.c | 21 | * @file fs/test_fs_search.c |
22 | * @brief simple testcase for simple publish + search operation | 22 | * @brief simple testcase for simple publish + search operation |
@@ -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,54 +58,54 @@ 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,80 +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 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 126 | |
127 | break; | 127 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
128 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 128 | break; |
129 | kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); | 129 | |
130 | start = GNUNET_TIME_absolute_get (); | 130 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
131 | search = | 131 | kuri = GNUNET_FS_uri_ksk_create_from_args(1, keywords); |
132 | GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, | 132 | start = GNUNET_TIME_absolute_get(); |
133 | "search"); | 133 | search = |
134 | GNUNET_FS_uri_destroy (kuri); | 134 | GNUNET_FS_search_start(fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, |
135 | GNUNET_assert (search != NULL); | 135 | "search"); |
136 | break; | 136 | GNUNET_FS_uri_destroy(kuri); |
137 | case GNUNET_FS_STATUS_SEARCH_RESULT: | 137 | GNUNET_assert(search != NULL); |
138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 138 | break; |
139 | "Search complete.\n"); | 139 | |
140 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 140 | case GNUNET_FS_STATUS_SEARCH_RESULT: |
141 | break; | 141 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
142 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 142 | "Search complete.\n"); |
143 | fprintf (stderr, "Error publishing file: %s\n", | 143 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); |
144 | event->value.publish.specifics.error.message); | 144 | break; |
145 | GNUNET_break (0); | 145 | |
146 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 146 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
147 | break; | 147 | fprintf(stderr, "Error publishing file: %s\n", |
148 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 148 | event->value.publish.specifics.error.message); |
149 | fprintf (stderr, "Error searching file: %s\n", | 149 | GNUNET_break(0); |
150 | event->value.search.specifics.error.message); | 150 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); |
151 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 151 | break; |
152 | break; | 152 | |
153 | case GNUNET_FS_STATUS_PUBLISH_START: | 153 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
154 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | 154 | fprintf(stderr, "Error searching file: %s\n", |
155 | GNUNET_assert (NULL == event->value.publish.pctx); | 155 | event->value.search.specifics.error.message); |
156 | GNUNET_assert (FILESIZE == event->value.publish.size); | 156 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); |
157 | GNUNET_assert (0 == event->value.publish.completed); | 157 | break; |
158 | GNUNET_assert (1 == event->value.publish.anonymity); | 158 | |
159 | break; | 159 | case GNUNET_FS_STATUS_PUBLISH_START: |
160 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 160 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); |
161 | GNUNET_assert (publish == event->value.publish.pc); | 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 (1 == event->value.publish.anonymity); | 163 | GNUNET_assert(0 == event->value.publish.completed); |
164 | GNUNET_FS_stop (fs); | 164 | GNUNET_assert(1 == event->value.publish.anonymity); |
165 | fs = NULL; | 165 | break; |
166 | break; | 166 | |
167 | case GNUNET_FS_STATUS_SEARCH_START: | 167 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
168 | GNUNET_assert (search == NULL); | 168 | GNUNET_assert(publish == event->value.publish.pc); |
169 | GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); | 169 | GNUNET_assert(FILESIZE == event->value.publish.size); |
170 | GNUNET_assert (1 == event->value.search.anonymity); | 170 | GNUNET_assert(1 == event->value.publish.anonymity); |
171 | break; | 171 | GNUNET_FS_stop(fs); |
172 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | 172 | fs = NULL; |
173 | break; | 173 | break; |
174 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | 174 | |
175 | GNUNET_assert (search == event->value.search.sc); | 175 | case GNUNET_FS_STATUS_SEARCH_START: |
176 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 176 | GNUNET_assert(search == NULL); |
177 | break; | 177 | GNUNET_assert(0 == strcmp("search", event->value.search.cctx)); |
178 | default: | 178 | GNUNET_assert(1 == event->value.search.anonymity); |
179 | fprintf (stderr, "Unexpected event: %d\n", event->status); | 179 | break; |
180 | break; | 180 | |
181 | } | 181 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: |
182 | break; | ||
183 | |||
184 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
185 | GNUNET_assert(search == event->value.search.sc); | ||
186 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
187 | break; | ||
188 | |||
189 | default: | ||
190 | fprintf(stderr, "Unexpected event: %d\n", event->status); | ||
191 | break; | ||
192 | } | ||
182 | return NULL; | 193 | return NULL; |
183 | } | 194 | } |
184 | 195 | ||
185 | 196 | ||
186 | static void | 197 | static void |
187 | run (void *cls, | 198 | run(void *cls, |
188 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 199 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
189 | struct GNUNET_TESTING_Peer *peer) | 200 | struct GNUNET_TESTING_Peer *peer) |
190 | { | 201 | { |
191 | const char *keywords[] = { | 202 | const char *keywords[] = { |
192 | "down_foo", | 203 | "down_foo", |
@@ -199,40 +210,40 @@ run (void *cls, | |||
199 | struct GNUNET_FS_FileInformation *fi; | 210 | struct GNUNET_FS_FileInformation *fi; |
200 | size_t i; | 211 | size_t i; |
201 | 212 | ||
202 | fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, | 213 | fs = GNUNET_FS_start(cfg, "test-fs-search", &progress_cb, NULL, |
203 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 214 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
204 | GNUNET_assert (NULL != fs); | 215 | GNUNET_assert(NULL != fs); |
205 | buf = GNUNET_malloc (FILESIZE); | 216 | buf = GNUNET_malloc(FILESIZE); |
206 | for (i = 0; i < FILESIZE; i++) | 217 | for (i = 0; i < FILESIZE; i++) |
207 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 218 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
208 | meta = GNUNET_CONTAINER_meta_data_create (); | 219 | meta = GNUNET_CONTAINER_meta_data_create(); |
209 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 220 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); |
210 | bo.content_priority = 42; | 221 | bo.content_priority = 42; |
211 | bo.anonymity_level = 1; | 222 | bo.anonymity_level = 1; |
212 | bo.replication_level = 0; | 223 | bo.replication_level = 0; |
213 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 224 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); |
214 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", | 225 | fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", |
215 | FILESIZE, buf, kuri, meta, | 226 | FILESIZE, buf, kuri, meta, |
216 | GNUNET_NO, &bo); | 227 | GNUNET_NO, &bo); |
217 | GNUNET_FS_uri_destroy (kuri); | 228 | GNUNET_FS_uri_destroy(kuri); |
218 | GNUNET_CONTAINER_meta_data_destroy (meta); | 229 | GNUNET_CONTAINER_meta_data_destroy(meta); |
219 | GNUNET_assert (NULL != fi); | 230 | GNUNET_assert(NULL != fi); |
220 | start = GNUNET_TIME_absolute_get (); | 231 | start = GNUNET_TIME_absolute_get(); |
221 | publish = | 232 | publish = |
222 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, | 233 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, |
223 | GNUNET_FS_PUBLISH_OPTION_NONE); | 234 | GNUNET_FS_PUBLISH_OPTION_NONE); |
224 | GNUNET_assert (publish != NULL); | 235 | GNUNET_assert(publish != NULL); |
225 | timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, | 236 | timeout_task = GNUNET_SCHEDULER_add_delayed(LIFETIME, |
226 | &abort_error, NULL); | 237 | &abort_error, NULL); |
227 | } | 238 | } |
228 | 239 | ||
229 | 240 | ||
230 | int | 241 | int |
231 | main (int argc, char *argv[]) | 242 | main(int argc, char *argv[]) |
232 | { | 243 | { |
233 | if (0 != GNUNET_TESTING_peer_run ("test-fs-search", | 244 | if (0 != GNUNET_TESTING_peer_run("test-fs-search", |
234 | "test_fs_search_data.conf", | 245 | "test_fs_search_data.conf", |
235 | &run, NULL)) | 246 | &run, NULL)) |
236 | return 1; | 247 | return 1; |
237 | return err; | 248 | return err; |
238 | } | 249 | } |
diff --git a/src/fs/test_fs_search_persistence.c b/src/fs/test_fs_search_persistence.c index 68e3a4a62..b01abe75f 100644 --- a/src/fs/test_fs_search_persistence.c +++ b/src/fs/test_fs_search_persistence.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/test_fs_search_persistence.c | 21 | * @file fs/test_fs_search_persistence.c |
22 | * @brief simple testcase for persistence of search operation | 22 | * @brief simple testcase for persistence of search operation |
@@ -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; |
@@ -60,62 +60,62 @@ 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,103 +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 | { | ||
155 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
157 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | ||
158 | (unsigned long long) event->value.publish.completed, | ||
159 | (unsigned long long) event->value.publish.size, | ||
160 | event->value.publish.specifics.progress.depth, | ||
161 | (unsigned long long) event->value.publish.specifics. | ||
162 | progress.offset); | ||
163 | break; | ||
164 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
165 | break; | ||
166 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
167 | kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); | ||
168 | start = GNUNET_TIME_absolute_get (); | ||
169 | GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, | ||
170 | "search"); | ||
171 | GNUNET_FS_uri_destroy (kuri); | ||
172 | GNUNET_assert (search != NULL); | ||
173 | break; | ||
174 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: | ||
175 | if (event->value.publish.pc == publish) | ||
176 | publish = NULL; | ||
177 | break; | ||
178 | case GNUNET_FS_STATUS_PUBLISH_RESUME: | ||
179 | if (NULL == publish) | ||
180 | publish = event->value.publish.pc; | ||
181 | break; | ||
182 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
183 | /* FIXME: consider_restart (event->status); cannot be tested with | ||
184 | * search result since we exit here after the first one... */ | ||
185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
186 | "Search complete.\n"); | ||
187 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | ||
188 | break; | ||
189 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
190 | fprintf (stderr, "Error publishing file: %s\n", | ||
191 | event->value.publish.specifics.error.message); | ||
192 | GNUNET_break (0); | ||
193 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
194 | break; | ||
195 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
196 | fprintf (stderr, "Error searching file: %s\n", | ||
197 | event->value.search.specifics.error.message); | ||
198 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | ||
199 | break; | ||
200 | case GNUNET_FS_STATUS_SEARCH_SUSPEND: | ||
201 | if (event->value.search.sc == search) | ||
202 | search = NULL; | ||
203 | break; | ||
204 | case GNUNET_FS_STATUS_SEARCH_RESUME: | ||
205 | if (NULL == search) | ||
206 | { | 154 | { |
155 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
156 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
157 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | ||
158 | (unsigned long long)event->value.publish.completed, | ||
159 | (unsigned long long)event->value.publish.size, | ||
160 | event->value.publish.specifics.progress.depth, | ||
161 | (unsigned long long)event->value.publish.specifics. | ||
162 | progress.offset); | ||
163 | break; | ||
164 | |||
165 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
166 | break; | ||
167 | |||
168 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
169 | kuri = GNUNET_FS_uri_ksk_create_from_args(1, keywords); | ||
170 | start = GNUNET_TIME_absolute_get(); | ||
171 | GNUNET_FS_search_start(fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, | ||
172 | "search"); | ||
173 | GNUNET_FS_uri_destroy(kuri); | ||
174 | GNUNET_assert(search != NULL); | ||
175 | break; | ||
176 | |||
177 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: | ||
178 | if (event->value.publish.pc == publish) | ||
179 | publish = NULL; | ||
180 | break; | ||
181 | |||
182 | case GNUNET_FS_STATUS_PUBLISH_RESUME: | ||
183 | if (NULL == publish) | ||
184 | publish = event->value.publish.pc; | ||
185 | break; | ||
186 | |||
187 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
188 | /* FIXME: consider_restart (event->status); cannot be tested with | ||
189 | * search result since we exit here after the first one... */ | ||
190 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
191 | "Search complete.\n"); | ||
192 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); | ||
193 | break; | ||
194 | |||
195 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
196 | fprintf(stderr, "Error publishing file: %s\n", | ||
197 | event->value.publish.specifics.error.message); | ||
198 | GNUNET_break(0); | ||
199 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
200 | break; | ||
201 | |||
202 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
203 | fprintf(stderr, "Error searching file: %s\n", | ||
204 | event->value.search.specifics.error.message); | ||
205 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); | ||
206 | break; | ||
207 | |||
208 | case GNUNET_FS_STATUS_SEARCH_SUSPEND: | ||
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); | ||
207 | search = event->value.search.sc; | 240 | search = event->value.search.sc; |
208 | return "search"; | 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; | ||
209 | } | 257 | } |
210 | break; | ||
211 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
212 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | ||
213 | GNUNET_assert (NULL == event->value.publish.pctx); | ||
214 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
215 | GNUNET_assert (0 == event->value.publish.completed); | ||
216 | GNUNET_assert (1 == event->value.publish.anonymity); | ||
217 | break; | ||
218 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
219 | GNUNET_assert (publish == event->value.publish.pc); | ||
220 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
221 | GNUNET_assert (1 == event->value.publish.anonymity); | ||
222 | GNUNET_FS_stop (fs); | ||
223 | fs = NULL; | ||
224 | break; | ||
225 | case GNUNET_FS_STATUS_SEARCH_START: | ||
226 | consider_restart (event->status); | ||
227 | GNUNET_assert (search == NULL); | ||
228 | search = event->value.search.sc; | ||
229 | GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); | ||
230 | GNUNET_assert (1 == event->value.search.anonymity); | ||
231 | break; | ||
232 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
233 | break; | ||
234 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
235 | GNUNET_assert (search == event->value.search.sc); | ||
236 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
237 | search = NULL; | ||
238 | break; | ||
239 | default: | ||
240 | fprintf (stderr, "Unexpected event: %d\n", event->status); | ||
241 | break; | ||
242 | } | ||
243 | return NULL; | 258 | return NULL; |
244 | } | 259 | } |
245 | 260 | ||
246 | 261 | ||
247 | static void | 262 | static void |
248 | run (void *cls, | 263 | run(void *cls, |
249 | const struct GNUNET_CONFIGURATION_Handle *c, | 264 | const struct GNUNET_CONFIGURATION_Handle *c, |
250 | struct GNUNET_TESTING_Peer *peer) | 265 | struct GNUNET_TESTING_Peer *peer) |
251 | { | 266 | { |
252 | const char *keywords[] = { | 267 | const char *keywords[] = { |
253 | "down_foo", | 268 | "down_foo", |
@@ -261,40 +276,40 @@ run (void *cls, | |||
261 | struct GNUNET_FS_BlockOptions bo; | 276 | struct GNUNET_FS_BlockOptions bo; |
262 | 277 | ||
263 | cfg = c; | 278 | cfg = c; |
264 | 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, |
265 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 280 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
266 | GNUNET_assert (NULL != fs); | 281 | GNUNET_assert(NULL != fs); |
267 | buf = GNUNET_malloc (FILESIZE); | 282 | buf = GNUNET_malloc(FILESIZE); |
268 | for (i = 0; i < FILESIZE; i++) | 283 | for (i = 0; i < FILESIZE; i++) |
269 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 284 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
270 | meta = GNUNET_CONTAINER_meta_data_create (); | 285 | meta = GNUNET_CONTAINER_meta_data_create(); |
271 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 286 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); |
272 | bo.content_priority = 42; | 287 | bo.content_priority = 42; |
273 | bo.anonymity_level = 1; | 288 | bo.anonymity_level = 1; |
274 | bo.replication_level = 0; | 289 | bo.replication_level = 0; |
275 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 290 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); |
276 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", | 291 | fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", |
277 | FILESIZE, buf, kuri, meta, | 292 | FILESIZE, buf, kuri, meta, |
278 | GNUNET_NO, &bo); | 293 | GNUNET_NO, &bo); |
279 | GNUNET_FS_uri_destroy (kuri); | 294 | GNUNET_FS_uri_destroy(kuri); |
280 | GNUNET_CONTAINER_meta_data_destroy (meta); | 295 | GNUNET_CONTAINER_meta_data_destroy(meta); |
281 | GNUNET_assert (NULL != fi); | 296 | GNUNET_assert(NULL != fi); |
282 | start = GNUNET_TIME_absolute_get (); | 297 | start = GNUNET_TIME_absolute_get(); |
283 | publish = | 298 | publish = |
284 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, | 299 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, |
285 | GNUNET_FS_PUBLISH_OPTION_NONE); | 300 | GNUNET_FS_PUBLISH_OPTION_NONE); |
286 | GNUNET_assert (publish != NULL); | 301 | GNUNET_assert(publish != NULL); |
287 | timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, | 302 | timeout_task = GNUNET_SCHEDULER_add_delayed(LIFETIME, |
288 | &abort_error, NULL); | 303 | &abort_error, NULL); |
289 | } | 304 | } |
290 | 305 | ||
291 | 306 | ||
292 | int | 307 | int |
293 | main (int argc, char *argv[]) | 308 | main(int argc, char *argv[]) |
294 | { | 309 | { |
295 | if (0 != GNUNET_TESTING_peer_run ("test-fs-search-persistence", | 310 | if (0 != GNUNET_TESTING_peer_run("test-fs-search-persistence", |
296 | "test_fs_search_data.conf", | 311 | "test_fs_search_data.conf", |
297 | &run, NULL)) | 312 | &run, NULL)) |
298 | return 1; | 313 | return 1; |
299 | return err; | 314 | return err; |
300 | } | 315 | } |
diff --git a/src/fs/test_fs_search_probes.c b/src/fs/test_fs_search_probes.c index c65649108..5584efca7 100644 --- a/src/fs/test_fs_search_probes.c +++ b/src/fs/test_fs_search_probes.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_fs_search_probes.c | 22 | * @file 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; |
@@ -59,52 +59,52 @@ 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,85 +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 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 125 | |
126 | break; | 126 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
127 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 127 | break; |
128 | kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); | 128 | |
129 | start = GNUNET_TIME_absolute_get (); | 129 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
130 | search = | 130 | kuri = GNUNET_FS_uri_ksk_create_from_args(1, keywords); |
131 | GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, | 131 | start = GNUNET_TIME_absolute_get(); |
132 | "search"); | 132 | search = |
133 | GNUNET_FS_uri_destroy (kuri); | 133 | GNUNET_FS_search_start(fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, |
134 | GNUNET_assert (search != NULL); | 134 | "search"); |
135 | break; | 135 | GNUNET_FS_uri_destroy(kuri); |
136 | case GNUNET_FS_STATUS_SEARCH_RESULT: | 136 | GNUNET_assert(search != NULL); |
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Search complete.\n"); | 137 | break; |
138 | break; | 138 | |
139 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 139 | case GNUNET_FS_STATUS_SEARCH_RESULT: |
140 | fprintf (stderr, "Error publishing file: %s\n", | 140 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Search complete.\n"); |
141 | event->value.publish.specifics.error.message); | 141 | break; |
142 | GNUNET_break (0); | 142 | |
143 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 143 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
144 | break; | 144 | fprintf(stderr, "Error publishing file: %s\n", |
145 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 145 | event->value.publish.specifics.error.message); |
146 | fprintf (stderr, "Error searching file: %s\n", | 146 | GNUNET_break(0); |
147 | event->value.search.specifics.error.message); | 147 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); |
148 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 148 | break; |
149 | break; | 149 | |
150 | case GNUNET_FS_STATUS_PUBLISH_START: | 150 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
151 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | 151 | fprintf(stderr, "Error searching file: %s\n", |
152 | GNUNET_assert (NULL == event->value.publish.pctx); | 152 | event->value.search.specifics.error.message); |
153 | GNUNET_assert (FILESIZE == event->value.publish.size); | 153 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); |
154 | GNUNET_assert (0 == event->value.publish.completed); | 154 | break; |
155 | GNUNET_assert (1 == event->value.publish.anonymity); | 155 | |
156 | break; | 156 | case GNUNET_FS_STATUS_PUBLISH_START: |
157 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 157 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); |
158 | GNUNET_assert (publish == event->value.publish.pc); | 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 (1 == event->value.publish.anonymity); | 160 | GNUNET_assert(0 == event->value.publish.completed); |
161 | GNUNET_FS_stop (fs); | 161 | GNUNET_assert(1 == event->value.publish.anonymity); |
162 | fs = NULL; | 162 | break; |
163 | break; | 163 | |
164 | case GNUNET_FS_STATUS_SEARCH_UPDATE: | 164 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
165 | if ( (0 < event->value.search.specifics.update.availability_rank) && | 165 | GNUNET_assert(publish == event->value.publish.pc); |
166 | (0 < event->value.search.specifics.update.availability_certainty) ) | 166 | GNUNET_assert(FILESIZE == event->value.publish.size); |
167 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 167 | GNUNET_assert(1 == event->value.publish.anonymity); |
168 | break; | 168 | GNUNET_FS_stop(fs); |
169 | case GNUNET_FS_STATUS_SEARCH_START: | 169 | fs = NULL; |
170 | GNUNET_assert (search == NULL); | 170 | break; |
171 | GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); | 171 | |
172 | GNUNET_assert (1 == event->value.search.anonymity); | 172 | case GNUNET_FS_STATUS_SEARCH_UPDATE: |
173 | break; | 173 | if ((0 < event->value.search.specifics.update.availability_rank) && |
174 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | 174 | (0 < event->value.search.specifics.update.availability_certainty)) |
175 | break; | 175 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); |
176 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | 176 | break; |
177 | GNUNET_assert (search == event->value.search.sc); | 177 | |
178 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 178 | case GNUNET_FS_STATUS_SEARCH_START: |
179 | break; | 179 | GNUNET_assert(search == NULL); |
180 | default: | 180 | GNUNET_assert(0 == strcmp("search", event->value.search.cctx)); |
181 | fprintf (stderr, | 181 | GNUNET_assert(1 == event->value.search.anonymity); |
182 | "Unexpected event: %d\n", | 182 | break; |
183 | event->status); | 183 | |
184 | break; | 184 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: |
185 | } | 185 | break; |
186 | |||
187 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
188 | GNUNET_assert(search == event->value.search.sc); | ||
189 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
190 | break; | ||
191 | |||
192 | default: | ||
193 | fprintf(stderr, | ||
194 | "Unexpected event: %d\n", | ||
195 | event->status); | ||
196 | break; | ||
197 | } | ||
186 | return NULL; | 198 | return NULL; |
187 | } | 199 | } |
188 | 200 | ||
189 | 201 | ||
190 | static void | 202 | static void |
191 | run (void *cls, | 203 | run(void *cls, |
192 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 204 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
193 | struct GNUNET_TESTING_Peer *peer) | 205 | struct GNUNET_TESTING_Peer *peer) |
194 | { | 206 | { |
195 | const char *keywords[] = { | 207 | const char *keywords[] = { |
196 | "down_foo", | 208 | "down_foo", |
@@ -203,41 +215,41 @@ run (void *cls, | |||
203 | struct GNUNET_FS_FileInformation *fi; | 215 | struct GNUNET_FS_FileInformation *fi; |
204 | size_t i; | 216 | size_t i; |
205 | 217 | ||
206 | fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, | 218 | fs = GNUNET_FS_start(cfg, "test-fs-search", &progress_cb, NULL, |
207 | GNUNET_FS_FLAGS_DO_PROBES, | 219 | GNUNET_FS_FLAGS_DO_PROBES, |
208 | GNUNET_FS_OPTIONS_END); | 220 | GNUNET_FS_OPTIONS_END); |
209 | GNUNET_assert (NULL != fs); | 221 | GNUNET_assert(NULL != fs); |
210 | buf = GNUNET_malloc (FILESIZE); | 222 | buf = GNUNET_malloc(FILESIZE); |
211 | for (i = 0; i < FILESIZE; i++) | 223 | for (i = 0; i < FILESIZE; i++) |
212 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 224 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
213 | meta = GNUNET_CONTAINER_meta_data_create (); | 225 | meta = GNUNET_CONTAINER_meta_data_create(); |
214 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 226 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); |
215 | bo.content_priority = 42; | 227 | bo.content_priority = 42; |
216 | bo.anonymity_level = 1; | 228 | bo.anonymity_level = 1; |
217 | bo.replication_level = 0; | 229 | bo.replication_level = 0; |
218 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 230 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); |
219 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", | 231 | fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", |
220 | FILESIZE, buf, kuri, meta, | 232 | FILESIZE, buf, kuri, meta, |
221 | GNUNET_NO, &bo); | 233 | GNUNET_NO, &bo); |
222 | GNUNET_FS_uri_destroy (kuri); | 234 | GNUNET_FS_uri_destroy(kuri); |
223 | GNUNET_CONTAINER_meta_data_destroy (meta); | 235 | GNUNET_CONTAINER_meta_data_destroy(meta); |
224 | GNUNET_assert (NULL != fi); | 236 | GNUNET_assert(NULL != fi); |
225 | start = GNUNET_TIME_absolute_get (); | 237 | start = GNUNET_TIME_absolute_get(); |
226 | publish = | 238 | publish = |
227 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, | 239 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, |
228 | GNUNET_FS_PUBLISH_OPTION_NONE); | 240 | GNUNET_FS_PUBLISH_OPTION_NONE); |
229 | GNUNET_assert (publish != NULL); | 241 | GNUNET_assert(publish != NULL); |
230 | timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, | 242 | timeout_task = GNUNET_SCHEDULER_add_delayed(LIFETIME, |
231 | &abort_error, NULL); | 243 | &abort_error, NULL); |
232 | } | 244 | } |
233 | 245 | ||
234 | 246 | ||
235 | int | 247 | int |
236 | main (int argc, char *argv[]) | 248 | main(int argc, char *argv[]) |
237 | { | 249 | { |
238 | if (0 != GNUNET_TESTING_peer_run ("test-fs-search-probes", | 250 | if (0 != GNUNET_TESTING_peer_run("test-fs-search-probes", |
239 | "test_fs_search_data.conf", | 251 | "test_fs_search_data.conf", |
240 | &run, NULL)) | 252 | &run, NULL)) |
241 | return 1; | 253 | return 1; |
242 | return err; | 254 | return err; |
243 | } | 255 | } |
diff --git a/src/fs/test_fs_search_with_and.c b/src/fs/test_fs_search_with_and.c index f1072a4a1..e43b8e25a 100644 --- a/src/fs/test_fs_search_with_and.c +++ b/src/fs/test_fs_search_with_and.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/test_fs_search_with_and.c | 21 | * @file fs/test_fs_search_with_and.c |
22 | * @brief testcase for publishing multiple files and search with a and operator | 22 | * @brief testcase for publishing multiple files and search with a and operator |
@@ -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; |
@@ -66,140 +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 | |||
119 | struct GNUNET_FS_Uri *kuri; | 118 | struct GNUNET_FS_Uri *kuri; |
120 | 119 | ||
121 | switch (event->status) | 120 | switch (event->status) |
122 | { | 121 | { |
123 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 122 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 123 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
125 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 124 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
126 | (unsigned long long) event->value.publish.completed, | 125 | (unsigned long long)event->value.publish.completed, |
127 | (unsigned long long) event->value.publish.size, | 126 | (unsigned long long)event->value.publish.size, |
128 | event->value.publish.specifics.progress.depth, | 127 | event->value.publish.specifics.progress.depth, |
129 | (unsigned long long) event->value.publish.specifics. | 128 | (unsigned long long)event->value.publish.specifics. |
130 | progress.offset); | 129 | progress.offset); |
131 | break; | 130 | break; |
132 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 131 | |
133 | break; | 132 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
134 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 133 | break; |
135 | processed_files++; | 134 | |
136 | if(processed_files == NUM_FILES) | 135 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
137 | { | 136 | processed_files++; |
138 | char *emsg = NULL; | 137 | if (processed_files == NUM_FILES) |
139 | kuri = GNUNET_FS_uri_ksk_create ("+down_foo +down_bar", &emsg); | 138 | { |
140 | GNUNET_assert (kuri != NULL); | 139 | char *emsg = NULL; |
141 | 140 | kuri = GNUNET_FS_uri_ksk_create("+down_foo +down_bar", &emsg); | |
142 | start = GNUNET_TIME_absolute_get (); | 141 | GNUNET_assert(kuri != NULL); |
143 | search = | 142 | |
144 | GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, | 143 | start = GNUNET_TIME_absolute_get(); |
145 | "search"); | 144 | search = |
146 | GNUNET_FS_uri_destroy (kuri); | 145 | GNUNET_FS_search_start(fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, |
147 | GNUNET_assert (search != NULL); | 146 | "search"); |
148 | } | 147 | GNUNET_FS_uri_destroy(kuri); |
149 | break; | 148 | GNUNET_assert(search != NULL); |
150 | case GNUNET_FS_STATUS_SEARCH_RESULT: | 149 | } |
151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 150 | break; |
152 | "Search complete.\n"); | 151 | |
153 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 152 | case GNUNET_FS_STATUS_SEARCH_RESULT: |
154 | break; | 153 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
155 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 154 | "Search complete.\n"); |
156 | fprintf (stderr, "Error publishing file: %s\n", | 155 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); |
157 | event->value.publish.specifics.error.message); | 156 | break; |
158 | GNUNET_break (0); | 157 | |
159 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 158 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
160 | break; | 159 | fprintf(stderr, "Error publishing file: %s\n", |
161 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 160 | event->value.publish.specifics.error.message); |
162 | fprintf (stderr, "Error searching file: %s\n", | 161 | GNUNET_break(0); |
163 | event->value.search.specifics.error.message); | 162 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); |
164 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 163 | break; |
165 | break; | 164 | |
166 | case GNUNET_FS_STATUS_PUBLISH_START: | 165 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
167 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | 166 | fprintf(stderr, "Error searching file: %s\n", |
168 | GNUNET_assert (NULL == event->value.publish.pctx); | 167 | event->value.search.specifics.error.message); |
169 | GNUNET_assert (FILESIZE == event->value.publish.size); | 168 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); |
170 | GNUNET_assert (0 == event->value.publish.completed); | 169 | break; |
171 | GNUNET_assert (1 == event->value.publish.anonymity); | 170 | |
172 | break; | 171 | case GNUNET_FS_STATUS_PUBLISH_START: |
173 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 172 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); |
174 | GNUNET_assert (publish == event->value.publish.pc); | 173 | GNUNET_assert(NULL == event->value.publish.pctx); |
175 | GNUNET_assert (FILESIZE == event->value.publish.size); | 174 | GNUNET_assert(FILESIZE == event->value.publish.size); |
176 | GNUNET_assert (1 == event->value.publish.anonymity); | 175 | GNUNET_assert(0 == event->value.publish.completed); |
177 | GNUNET_FS_stop (fs); | 176 | GNUNET_assert(1 == event->value.publish.anonymity); |
178 | fs = NULL; | 177 | break; |
179 | break; | 178 | |
180 | case GNUNET_FS_STATUS_SEARCH_START: | 179 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
181 | GNUNET_assert (search == NULL); | 180 | GNUNET_assert(publish == event->value.publish.pc); |
182 | GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); | 181 | GNUNET_assert(FILESIZE == event->value.publish.size); |
183 | GNUNET_assert (1 == event->value.search.anonymity); | 182 | GNUNET_assert(1 == event->value.publish.anonymity); |
184 | break; | 183 | GNUNET_FS_stop(fs); |
185 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | 184 | fs = NULL; |
186 | break; | 185 | break; |
187 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | 186 | |
188 | GNUNET_assert (search == event->value.search.sc); | 187 | case GNUNET_FS_STATUS_SEARCH_START: |
189 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 188 | GNUNET_assert(search == NULL); |
190 | break; | 189 | GNUNET_assert(0 == strcmp("search", event->value.search.cctx)); |
191 | default: | 190 | GNUNET_assert(1 == event->value.search.anonymity); |
192 | fprintf (stderr, "Unexpected event: %d\n", event->status); | 191 | break; |
193 | break; | 192 | |
194 | } | 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 | } | ||
195 | return NULL; | 205 | return NULL; |
196 | } | 206 | } |
197 | 207 | ||
198 | 208 | ||
199 | static void | 209 | static void |
200 | run (void *cls, | 210 | run(void *cls, |
201 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 211 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
202 | struct GNUNET_TESTING_Peer *peer) | 212 | struct GNUNET_TESTING_Peer *peer) |
203 | { | 213 | { |
204 | const char *keywords[] = { | 214 | const char *keywords[] = { |
205 | "down_foo", | 215 | "down_foo", |
@@ -213,46 +223,47 @@ run (void *cls, | |||
213 | size_t i; | 223 | size_t i; |
214 | size_t j; | 224 | size_t j; |
215 | 225 | ||
216 | fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, | 226 | fs = GNUNET_FS_start(cfg, "test-fs-search", &progress_cb, NULL, |
217 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 227 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
218 | GNUNET_assert (NULL != fs); | 228 | GNUNET_assert(NULL != fs); |
219 | 229 | ||
220 | processed_files = 0; | 230 | processed_files = 0; |
221 | for(j = 0; j < NUM_FILES; j++){ | 231 | for (j = 0; j < NUM_FILES; j++) |
222 | buf = GNUNET_malloc (FILESIZE); | 232 | { |
223 | for (i = 0; i < FILESIZE; i++) | 233 | buf = GNUNET_malloc(FILESIZE); |
224 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 234 | for (i = 0; i < FILESIZE; i++) |
225 | meta = GNUNET_CONTAINER_meta_data_create (); | 235 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
226 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 236 | meta = GNUNET_CONTAINER_meta_data_create(); |
227 | bo.content_priority = 42; | 237 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); |
228 | bo.anonymity_level = 1; | 238 | bo.content_priority = 42; |
229 | bo.replication_level = 0; | 239 | bo.anonymity_level = 1; |
230 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 240 | bo.replication_level = 0; |
231 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", | 241 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); |
232 | FILESIZE, buf, kuri, meta, | 242 | fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", |
233 | GNUNET_NO, &bo); | 243 | FILESIZE, buf, kuri, meta, |
234 | GNUNET_FS_uri_destroy (kuri); | 244 | GNUNET_NO, &bo); |
235 | GNUNET_CONTAINER_meta_data_destroy (meta); | 245 | GNUNET_FS_uri_destroy(kuri); |
236 | GNUNET_assert (NULL != fi); | 246 | GNUNET_CONTAINER_meta_data_destroy(meta); |
237 | start = GNUNET_TIME_absolute_get (); | 247 | GNUNET_assert(NULL != fi); |
238 | publish = | 248 | start = GNUNET_TIME_absolute_get(); |
239 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, | 249 | publish = |
250 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, | ||
240 | GNUNET_FS_PUBLISH_OPTION_NONE); | 251 | GNUNET_FS_PUBLISH_OPTION_NONE); |
241 | GNUNET_assert (publish != NULL); | 252 | GNUNET_assert(publish != NULL); |
242 | } | 253 | } |
243 | 254 | ||
244 | 255 | ||
245 | timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, | 256 | timeout_task = GNUNET_SCHEDULER_add_delayed(LIFETIME, |
246 | &abort_error, NULL); | 257 | &abort_error, NULL); |
247 | } | 258 | } |
248 | 259 | ||
249 | 260 | ||
250 | int | 261 | int |
251 | main (int argc, char *argv[]) | 262 | main(int argc, char *argv[]) |
252 | { | 263 | { |
253 | if (0 != GNUNET_TESTING_peer_run ("test-fs-search-with-and", | 264 | if (0 != GNUNET_TESTING_peer_run("test-fs-search-with-and", |
254 | "test_fs_search_data.conf", | 265 | "test_fs_search_data.conf", |
255 | &run, NULL)) | 266 | &run, NULL)) |
256 | return 1; | 267 | return 1; |
257 | return err; | 268 | return err; |
258 | } | 269 | } |
diff --git a/src/fs/test_fs_start_stop.c b/src/fs/test_fs_start_stop.c index e20e00996..4e3c17db0 100644 --- a/src/fs/test_fs_start_stop.c +++ b/src/fs/test_fs_start_stop.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/test_fs_start_stop.c | 21 | * @file fs/test_fs_start_stop.c |
22 | * @brief testcase for fs.c (start-stop only) | 22 | * @brief testcase for fs.c (start-stop only) |
@@ -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 52b0bf2c0..7e27469cc 100644 --- a/src/fs/test_fs_test_lib.c +++ b/src/fs/test_fs_test_lib.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_fs_test_lib.c | 22 | * @file 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,75 +50,74 @@ 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)).rel_value_us) |
60 | { | 60 | { |
61 | GNUNET_break (0); | 61 | GNUNET_break(0); |
62 | ret = 1; | 62 | ret = 1; |
63 | } | 63 | } |
64 | else | 64 | else |
65 | { | 65 | { |
66 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 66 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
67 | "Finished download, shutting down\n"); | 67 | "Finished download, shutting down\n"); |
68 | } | 68 | } |
69 | if (NULL != fn) | 69 | if (NULL != fn) |
70 | { | 70 | { |
71 | GNUNET_DISK_directory_remove (fn); | 71 | GNUNET_DISK_directory_remove(fn); |
72 | GNUNET_free (fn); | 72 | GNUNET_free(fn); |
73 | } | 73 | } |
74 | GNUNET_SCHEDULER_shutdown (); | 74 | GNUNET_SCHEDULER_shutdown(); |
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
78 | static void | 78 | static void |
79 | do_download (void *cls, | 79 | do_download(void *cls, |
80 | const struct GNUNET_FS_Uri *uri, | 80 | const struct GNUNET_FS_Uri *uri, |
81 | const char *fn) | 81 | const char *fn) |
82 | { | 82 | { |
83 | if (NULL == uri) | 83 | if (NULL == uri) |
84 | { | 84 | { |
85 | GNUNET_break (0); | 85 | GNUNET_break(0); |
86 | GNUNET_SCHEDULER_shutdown (); | 86 | GNUNET_SCHEDULER_shutdown(); |
87 | ret = 1; | 87 | ret = 1; |
88 | return; | 88 | return; |
89 | } | 89 | } |
90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 90 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
91 | "Downloading %llu bytes\n", | 91 | "Downloading %llu bytes\n", |
92 | (unsigned long long) FILESIZE); | 92 | (unsigned long long)FILESIZE); |
93 | start_time = GNUNET_TIME_absolute_get (); | 93 | start_time = GNUNET_TIME_absolute_get(); |
94 | GNUNET_FS_TEST_download (the_peers[0], | 94 | GNUNET_FS_TEST_download(the_peers[0], |
95 | TIMEOUT, 1, SEED, | 95 | TIMEOUT, 1, SEED, |
96 | uri, | 96 | uri, |
97 | VERBOSE, | 97 | VERBOSE, |
98 | &do_stop, | 98 | &do_stop, |
99 | (NULL == fn) ? NULL : GNUNET_strdup (fn)); | 99 | (NULL == fn) ? NULL : GNUNET_strdup(fn)); |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | static void | 103 | static void |
104 | do_publish (void *cls, | 104 | do_publish(void *cls, |
105 | struct GNUNET_TESTBED_Operation *op, | 105 | struct GNUNET_TESTBED_Operation *op, |
106 | const char *emsg) | 106 | const char *emsg) |
107 | { | 107 | { |
108 | GNUNET_TESTBED_operation_done (op); | 108 | GNUNET_TESTBED_operation_done(op); |
109 | if (NULL != emsg) | 109 | if (NULL != emsg) |
110 | { | 110 | { |
111 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect peers: %s\n", emsg); | 111 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect peers: %s\n", emsg); |
112 | GNUNET_break (0); | 112 | GNUNET_break(0); |
113 | ret = 1; | 113 | ret = 1; |
114 | GNUNET_SCHEDULER_shutdown (); | 114 | GNUNET_SCHEDULER_shutdown(); |
115 | return; | 115 | return; |
116 | } | 116 | } |
117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", | 117 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", |
118 | (unsigned long long) FILESIZE); | 118 | (unsigned long long)FILESIZE); |
119 | GNUNET_FS_TEST_publish (the_peers[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED, | 119 | GNUNET_FS_TEST_publish(the_peers[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED, |
120 | VERBOSE, &do_download, NULL); | 120 | VERBOSE, &do_download, NULL); |
121 | |||
122 | } | 121 | } |
123 | 122 | ||
124 | 123 | ||
@@ -135,23 +134,23 @@ do_publish (void *cls, | |||
135 | * failed | 134 | * failed |
136 | */ | 135 | */ |
137 | static void | 136 | static void |
138 | run (void *cls, | 137 | run(void *cls, |
139 | struct GNUNET_TESTBED_RunHandle *h, | 138 | struct GNUNET_TESTBED_RunHandle *h, |
140 | unsigned int num_peers, | 139 | unsigned int num_peers, |
141 | struct GNUNET_TESTBED_Peer **peers, | 140 | struct GNUNET_TESTBED_Peer **peers, |
142 | unsigned int links_succeeded, | 141 | unsigned int links_succeeded, |
143 | unsigned int links_failed) | 142 | unsigned int links_failed) |
144 | { | 143 | { |
145 | unsigned int i; | 144 | unsigned int i; |
146 | 145 | ||
147 | GNUNET_assert (NUM_DAEMONS == num_peers); | 146 | GNUNET_assert(NUM_DAEMONS == num_peers); |
148 | for (i=0;i<num_peers;i++) | 147 | for (i = 0; i < num_peers; i++) |
149 | the_peers[i] = peers[i]; | 148 | the_peers[i] = peers[i]; |
150 | GNUNET_TESTBED_overlay_connect (NULL, | 149 | GNUNET_TESTBED_overlay_connect(NULL, |
151 | &do_publish, | 150 | &do_publish, |
152 | NULL, | 151 | NULL, |
153 | peers[0], | 152 | peers[0], |
154 | peers[1]); | 153 | peers[1]); |
155 | } | 154 | } |
156 | 155 | ||
157 | 156 | ||
@@ -163,15 +162,15 @@ run (void *cls, | |||
163 | * @return 0 on success | 162 | * @return 0 on success |
164 | */ | 163 | */ |
165 | int | 164 | int |
166 | main (int argc, char *argv[]) | 165 | main(int argc, char *argv[]) |
167 | { | 166 | { |
168 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | 167 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/"); |
169 | (void) GNUNET_TESTBED_test_run ("test_fs_test_lib", | 168 | (void)GNUNET_TESTBED_test_run("test_fs_test_lib", |
170 | "fs_test_lib_data.conf", | 169 | "fs_test_lib_data.conf", |
171 | NUM_DAEMONS, | 170 | NUM_DAEMONS, |
172 | 0, NULL, NULL, | 171 | 0, NULL, NULL, |
173 | &run, NULL); | 172 | &run, NULL); |
174 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | 173 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/"); |
175 | return ret; | 174 | return ret; |
176 | } | 175 | } |
177 | 176 | ||
diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c index b4bdc1b80..1c1cf6239 100644 --- a/src/fs/test_fs_unindex.c +++ b/src/fs/test_fs_unindex.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_fs_unindex.c | 22 | * @file 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,117 +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 | |||
82 | switch (event->status) | 81 | switch (event->status) |
83 | { | 82 | { |
84 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 83 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 84 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
86 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 85 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
87 | (unsigned long long) event->value.publish.completed, | 86 | (unsigned long long)event->value.publish.completed, |
88 | (unsigned long long) event->value.publish.size, | 87 | (unsigned long long)event->value.publish.size, |
89 | event->value.publish.specifics.progress.depth, | 88 | event->value.publish.specifics.progress.depth, |
90 | (unsigned long long) event->value.publish.specifics. | 89 | (unsigned long long)event->value.publish.specifics. |
91 | progress.offset); | 90 | progress.offset); |
92 | break; | 91 | break; |
93 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 92 | |
94 | break; | 93 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
95 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 94 | break; |
96 | printf ("Publishing complete, %llu kbps.\n", | 95 | |
97 | (unsigned long long) (FILESIZE * 1000000LL / | 96 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
97 | printf("Publishing complete, %llu kbps.\n", | ||
98 | (unsigned long long)(FILESIZE * 1000000LL / | ||
98 | (1 + | 99 | (1 + |
99 | GNUNET_TIME_absolute_get_duration | 100 | GNUNET_TIME_absolute_get_duration |
100 | (start).rel_value_us) / 1024)); | 101 | (start).rel_value_us) / 1024)); |
101 | start = GNUNET_TIME_absolute_get (); | 102 | start = GNUNET_TIME_absolute_get(); |
102 | unindex = GNUNET_FS_unindex_start (fs, fn, "unindex"); | 103 | unindex = GNUNET_FS_unindex_start(fs, fn, "unindex"); |
103 | GNUNET_assert (unindex != NULL); | 104 | GNUNET_assert(unindex != NULL); |
104 | break; | 105 | break; |
105 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | 106 | |
106 | printf ("Unindex complete, %llu kbps.\n", | 107 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: |
107 | (unsigned long long) (FILESIZE * 1000000LL / | 108 | printf("Unindex complete, %llu kbps.\n", |
109 | (unsigned long long)(FILESIZE * 1000000LL / | ||
108 | (1 + | 110 | (1 + |
109 | GNUNET_TIME_absolute_get_duration | 111 | GNUNET_TIME_absolute_get_duration |
110 | (start).rel_value_us) / 1024)); | 112 | (start).rel_value_us) / 1024)); |
111 | GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); | 113 | GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL); |
112 | break; | 114 | break; |
113 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | 115 | |
114 | GNUNET_assert (unindex == event->value.unindex.uc); | 116 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: |
115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 117 | GNUNET_assert(unindex == event->value.unindex.uc); |
116 | "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", | 118 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
117 | (unsigned long long) event->value.unindex.completed, | 119 | "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", |
118 | (unsigned long long) event->value.unindex.size, | 120 | (unsigned long long)event->value.unindex.completed, |
119 | event->value.unindex.specifics.progress.depth, | 121 | (unsigned long long)event->value.unindex.size, |
120 | (unsigned long long) event->value.unindex.specifics. | 122 | event->value.unindex.specifics.progress.depth, |
121 | progress.offset); | 123 | (unsigned long long)event->value.unindex.specifics. |
122 | break; | 124 | progress.offset); |
123 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 125 | break; |
124 | fprintf (stderr, "Error publishing file: %s\n", | 126 | |
125 | event->value.publish.specifics.error.message); | 127 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
126 | GNUNET_break (0); | 128 | fprintf(stderr, "Error publishing file: %s\n", |
127 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 129 | event->value.publish.specifics.error.message); |
128 | break; | 130 | GNUNET_break(0); |
129 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | 131 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); |
130 | fprintf (stderr, "Error unindexing file: %s\n", | 132 | break; |
131 | event->value.unindex.specifics.error.message); | 133 | |
132 | GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); | 134 | case GNUNET_FS_STATUS_UNINDEX_ERROR: |
133 | break; | 135 | fprintf(stderr, "Error unindexing file: %s\n", |
134 | case GNUNET_FS_STATUS_PUBLISH_START: | 136 | event->value.unindex.specifics.error.message); |
135 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | 137 | GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL); |
136 | GNUNET_assert (NULL == event->value.publish.pctx); | 138 | break; |
137 | GNUNET_assert (FILESIZE == event->value.publish.size); | 139 | |
138 | GNUNET_assert (0 == event->value.publish.completed); | 140 | case GNUNET_FS_STATUS_PUBLISH_START: |
139 | GNUNET_assert (1 == event->value.publish.anonymity); | 141 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); |
140 | break; | 142 | GNUNET_assert(NULL == event->value.publish.pctx); |
141 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 143 | GNUNET_assert(FILESIZE == event->value.publish.size); |
142 | GNUNET_assert (publish == event->value.publish.pc); | 144 | GNUNET_assert(0 == event->value.publish.completed); |
143 | GNUNET_assert (FILESIZE == event->value.publish.size); | 145 | GNUNET_assert(1 == event->value.publish.anonymity); |
144 | GNUNET_assert (1 == event->value.publish.anonymity); | 146 | break; |
145 | GNUNET_FS_stop (fs); | 147 | |
146 | fs = NULL; | 148 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
147 | break; | 149 | GNUNET_assert(publish == event->value.publish.pc); |
148 | case GNUNET_FS_STATUS_UNINDEX_START: | 150 | GNUNET_assert(FILESIZE == event->value.publish.size); |
149 | GNUNET_assert (unindex == NULL); | 151 | GNUNET_assert(1 == event->value.publish.anonymity); |
150 | GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx)); | 152 | GNUNET_FS_stop(fs); |
151 | GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename)); | 153 | fs = NULL; |
152 | GNUNET_assert (FILESIZE == event->value.unindex.size); | 154 | break; |
153 | GNUNET_assert (0 == event->value.unindex.completed); | 155 | |
154 | break; | 156 | case GNUNET_FS_STATUS_UNINDEX_START: |
155 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | 157 | GNUNET_assert(unindex == NULL); |
156 | GNUNET_assert (unindex == event->value.unindex.uc); | 158 | GNUNET_assert(0 == strcmp("unindex", event->value.unindex.cctx)); |
157 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 159 | GNUNET_assert(0 == strcmp(fn, event->value.unindex.filename)); |
158 | break; | 160 | GNUNET_assert(FILESIZE == event->value.unindex.size); |
159 | default: | 161 | GNUNET_assert(0 == event->value.unindex.completed); |
160 | printf ("Unexpected event: %d\n", event->status); | 162 | break; |
161 | break; | 163 | |
162 | } | 164 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: |
165 | GNUNET_assert(unindex == event->value.unindex.uc); | ||
166 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
167 | break; | ||
168 | |||
169 | default: | ||
170 | printf("Unexpected event: %d\n", event->status); | ||
171 | break; | ||
172 | } | ||
163 | return NULL; | 173 | return NULL; |
164 | } | 174 | } |
165 | 175 | ||
166 | 176 | ||
167 | static void | 177 | static void |
168 | run (void *cls, | 178 | run(void *cls, |
169 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 179 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
170 | struct GNUNET_TESTING_Peer *peer) | 180 | struct GNUNET_TESTING_Peer *peer) |
171 | { | 181 | { |
172 | const char *keywords[] = { | 182 | const char *keywords[] = { |
173 | "down_foo", | 183 | "down_foo", |
@@ -180,44 +190,44 @@ run (void *cls, | |||
180 | size_t i; | 190 | size_t i; |
181 | struct GNUNET_FS_BlockOptions bo; | 191 | struct GNUNET_FS_BlockOptions bo; |
182 | 192 | ||
183 | fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); | 193 | fn = GNUNET_DISK_mktemp("gnunet-unindex-test-dst"); |
184 | fs = GNUNET_FS_start (cfg, "test-fs-unindex", &progress_cb, NULL, | 194 | fs = GNUNET_FS_start(cfg, "test-fs-unindex", &progress_cb, NULL, |
185 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 195 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
186 | GNUNET_assert (NULL != fs); | 196 | GNUNET_assert(NULL != fs); |
187 | buf = GNUNET_malloc (FILESIZE); | 197 | buf = GNUNET_malloc(FILESIZE); |
188 | for (i = 0; i < FILESIZE; i++) | 198 | for (i = 0; i < FILESIZE; i++) |
189 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 199 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
190 | GNUNET_assert (FILESIZE == | 200 | GNUNET_assert(FILESIZE == |
191 | GNUNET_DISK_fn_write (fn, buf, FILESIZE, | 201 | GNUNET_DISK_fn_write(fn, buf, FILESIZE, |
192 | GNUNET_DISK_PERM_USER_READ | | 202 | GNUNET_DISK_PERM_USER_READ | |
193 | GNUNET_DISK_PERM_USER_WRITE)); | 203 | GNUNET_DISK_PERM_USER_WRITE)); |
194 | GNUNET_free (buf); | 204 | GNUNET_free(buf); |
195 | meta = GNUNET_CONTAINER_meta_data_create (); | 205 | meta = GNUNET_CONTAINER_meta_data_create(); |
196 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 206 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); |
197 | bo.content_priority = 42; | 207 | bo.content_priority = 42; |
198 | bo.anonymity_level = 1; | 208 | bo.anonymity_level = 1; |
199 | bo.replication_level = 0; | 209 | bo.replication_level = 0; |
200 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 210 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); |
201 | 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, |
202 | kuri, meta, GNUNET_YES, | 212 | kuri, meta, GNUNET_YES, |
203 | &bo); | 213 | &bo); |
204 | GNUNET_FS_uri_destroy (kuri); | 214 | GNUNET_FS_uri_destroy(kuri); |
205 | GNUNET_CONTAINER_meta_data_destroy (meta); | 215 | GNUNET_CONTAINER_meta_data_destroy(meta); |
206 | GNUNET_assert (NULL != fi); | 216 | GNUNET_assert(NULL != fi); |
207 | start = GNUNET_TIME_absolute_get (); | 217 | start = GNUNET_TIME_absolute_get(); |
208 | publish = | 218 | publish = |
209 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, | 219 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, |
210 | GNUNET_FS_PUBLISH_OPTION_NONE); | 220 | GNUNET_FS_PUBLISH_OPTION_NONE); |
211 | GNUNET_assert (publish != NULL); | 221 | GNUNET_assert(publish != NULL); |
212 | } | 222 | } |
213 | 223 | ||
214 | 224 | ||
215 | int | 225 | int |
216 | main (int argc, char *argv[]) | 226 | main(int argc, char *argv[]) |
217 | { | 227 | { |
218 | if (0 != GNUNET_TESTING_peer_run ("test-fs-unindex", | 228 | if (0 != GNUNET_TESTING_peer_run("test-fs-unindex", |
219 | "test_fs_unindex_data.conf", | 229 | "test_fs_unindex_data.conf", |
220 | &run, NULL)) | 230 | &run, NULL)) |
221 | return 1; | 231 | return 1; |
222 | return 0; | 232 | return 0; |
223 | } | 233 | } |
diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c index 50d45708a..7deebb95b 100644 --- a/src/fs/test_fs_unindex_persistence.c +++ b/src/fs/test_fs_unindex_persistence.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_fs_unindex_persistence.c | 22 | * @file 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,125 +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 | { | 125 | { |
126 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 126 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 127 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
128 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 128 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
129 | (unsigned long long) event->value.publish.completed, | 129 | (unsigned long long)event->value.publish.completed, |
130 | (unsigned long long) event->value.publish.size, | 130 | (unsigned long long)event->value.publish.size, |
131 | event->value.publish.specifics.progress.depth, | 131 | event->value.publish.specifics.progress.depth, |
132 | (unsigned long long) event->value.publish.specifics. | 132 | (unsigned long long)event->value.publish.specifics. |
133 | progress.offset); | 133 | progress.offset); |
134 | break; | 134 | break; |
135 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 135 | |
136 | break; | 136 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
137 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 137 | break; |
138 | printf ("Publishing complete, %llu kbps.\n", | 138 | |
139 | (unsigned long long) (FILESIZE * 1000000LL / | 139 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
140 | printf("Publishing complete, %llu kbps.\n", | ||
141 | (unsigned long long)(FILESIZE * 1000000LL / | ||
140 | (1 + | 142 | (1 + |
141 | GNUNET_TIME_absolute_get_duration | 143 | GNUNET_TIME_absolute_get_duration |
142 | (start).rel_value_us) / 1024)); | 144 | (start).rel_value_us) / 1024)); |
143 | start = GNUNET_TIME_absolute_get (); | 145 | start = GNUNET_TIME_absolute_get(); |
144 | unindex = GNUNET_FS_unindex_start (fs, fn, "unindex"); | 146 | unindex = GNUNET_FS_unindex_start(fs, fn, "unindex"); |
145 | GNUNET_assert (unindex != NULL); | 147 | GNUNET_assert(unindex != NULL); |
146 | break; | 148 | break; |
147 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | 149 | |
148 | printf ("Unindex complete, %llu kbps.\n", | 150 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: |
149 | (unsigned long long) (FILESIZE * 1000000LL / | 151 | printf("Unindex complete, %llu kbps.\n", |
152 | (unsigned long long)(FILESIZE * 1000000LL / | ||
150 | (1 + | 153 | (1 + |
151 | GNUNET_TIME_absolute_get_duration | 154 | GNUNET_TIME_absolute_get_duration |
152 | (start).rel_value_us) / 1024)); | 155 | (start).rel_value_us) / 1024)); |
153 | GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); | 156 | GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL); |
154 | break; | 157 | break; |
155 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | 158 | |
156 | consider_restart (event->status); | 159 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: |
157 | GNUNET_assert (unindex == event->value.unindex.uc); | 160 | consider_restart(event->status); |
158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 161 | GNUNET_assert(unindex == event->value.unindex.uc); |
159 | "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", | 162 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
160 | (unsigned long long) event->value.unindex.completed, | 163 | "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", |
161 | (unsigned long long) event->value.unindex.size, | 164 | (unsigned long long)event->value.unindex.completed, |
162 | event->value.unindex.specifics.progress.depth, | 165 | (unsigned long long)event->value.unindex.size, |
163 | (unsigned long long) event->value.unindex.specifics. | 166 | event->value.unindex.specifics.progress.depth, |
164 | progress.offset); | 167 | (unsigned long long)event->value.unindex.specifics. |
165 | break; | 168 | progress.offset); |
166 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: | 169 | break; |
167 | if (event->value.publish.pc == publish) | 170 | |
168 | publish = NULL; | 171 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: |
169 | break; | 172 | if (event->value.publish.pc == publish) |
170 | case GNUNET_FS_STATUS_PUBLISH_RESUME: | 173 | publish = NULL; |
171 | if (NULL == publish) | 174 | break; |
172 | { | 175 | |
173 | publish = event->value.publish.pc; | 176 | case GNUNET_FS_STATUS_PUBLISH_RESUME: |
174 | return "publish-context"; | 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; | ||
175 | } | 241 | } |
176 | break; | ||
177 | case GNUNET_FS_STATUS_UNINDEX_SUSPEND: | ||
178 | GNUNET_assert (event->value.unindex.uc == unindex); | ||
179 | unindex = NULL; | ||
180 | break; | ||
181 | case GNUNET_FS_STATUS_UNINDEX_RESUME: | ||
182 | GNUNET_assert (NULL == unindex); | ||
183 | unindex = event->value.unindex.uc; | ||
184 | return "unindex"; | ||
185 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
186 | fprintf (stderr, "Error publishing file: %s\n", | ||
187 | event->value.publish.specifics.error.message); | ||
188 | GNUNET_break (0); | ||
189 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
190 | break; | ||
191 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
193 | "Error unindexing file: %s\n", | ||
194 | event->value.unindex.specifics.error.message); | ||
195 | GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); | ||
196 | break; | ||
197 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
198 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | ||
199 | GNUNET_assert (NULL == event->value.publish.pctx); | ||
200 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
201 | GNUNET_assert (0 == event->value.publish.completed); | ||
202 | GNUNET_assert (1 == event->value.publish.anonymity); | ||
203 | break; | ||
204 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
205 | GNUNET_assert (publish == event->value.publish.pc); | ||
206 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
207 | GNUNET_assert (1 == event->value.publish.anonymity); | ||
208 | GNUNET_FS_stop (fs); | ||
209 | fs = NULL; | ||
210 | break; | ||
211 | case GNUNET_FS_STATUS_UNINDEX_START: | ||
212 | consider_restart (event->status); | ||
213 | GNUNET_assert (unindex == NULL); | ||
214 | GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx)); | ||
215 | GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename)); | ||
216 | GNUNET_assert (FILESIZE == event->value.unindex.size); | ||
217 | GNUNET_assert (0 == event->value.unindex.completed); | ||
218 | break; | ||
219 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | ||
220 | GNUNET_assert (unindex == event->value.unindex.uc); | ||
221 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
222 | break; | ||
223 | default: | ||
224 | printf ("Unexpected event: %d\n", event->status); | ||
225 | break; | ||
226 | } | ||
227 | return NULL; | 242 | return NULL; |
228 | } | 243 | } |
229 | 244 | ||
230 | 245 | ||
231 | static void | 246 | static void |
232 | run (void *cls, | 247 | run(void *cls, |
233 | const struct GNUNET_CONFIGURATION_Handle *c, | 248 | const struct GNUNET_CONFIGURATION_Handle *c, |
234 | struct GNUNET_TESTING_Peer *peer) | 249 | struct GNUNET_TESTING_Peer *peer) |
235 | { | 250 | { |
236 | const char *keywords[] = { | 251 | const char *keywords[] = { |
237 | "down_foo", | 252 | "down_foo", |
@@ -245,44 +260,44 @@ run (void *cls, | |||
245 | struct GNUNET_FS_BlockOptions bo; | 260 | struct GNUNET_FS_BlockOptions bo; |
246 | 261 | ||
247 | cfg = c; | 262 | cfg = c; |
248 | fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); | 263 | fn = GNUNET_DISK_mktemp("gnunet-unindex-test-dst"); |
249 | 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, |
250 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 265 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
251 | GNUNET_assert (NULL != fs); | 266 | GNUNET_assert(NULL != fs); |
252 | buf = GNUNET_malloc (FILESIZE); | 267 | buf = GNUNET_malloc(FILESIZE); |
253 | for (i = 0; i < FILESIZE; i++) | 268 | for (i = 0; i < FILESIZE; i++) |
254 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 269 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); |
255 | GNUNET_assert (FILESIZE == | 270 | GNUNET_assert(FILESIZE == |
256 | GNUNET_DISK_fn_write (fn, buf, FILESIZE, | 271 | GNUNET_DISK_fn_write(fn, buf, FILESIZE, |
257 | GNUNET_DISK_PERM_USER_READ | | 272 | GNUNET_DISK_PERM_USER_READ | |
258 | GNUNET_DISK_PERM_USER_WRITE)); | 273 | GNUNET_DISK_PERM_USER_WRITE)); |
259 | GNUNET_free (buf); | 274 | GNUNET_free(buf); |
260 | meta = GNUNET_CONTAINER_meta_data_create (); | 275 | meta = GNUNET_CONTAINER_meta_data_create(); |
261 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); | 276 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); |
262 | bo.content_priority = 42; | 277 | bo.content_priority = 42; |
263 | bo.anonymity_level = 1; | 278 | bo.anonymity_level = 1; |
264 | bo.replication_level = 0; | 279 | bo.replication_level = 0; |
265 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 280 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); |
266 | 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, |
267 | kuri, meta, GNUNET_YES, | 282 | kuri, meta, GNUNET_YES, |
268 | &bo); | 283 | &bo); |
269 | GNUNET_FS_uri_destroy (kuri); | 284 | GNUNET_FS_uri_destroy(kuri); |
270 | GNUNET_CONTAINER_meta_data_destroy (meta); | 285 | GNUNET_CONTAINER_meta_data_destroy(meta); |
271 | GNUNET_assert (NULL != fi); | 286 | GNUNET_assert(NULL != fi); |
272 | start = GNUNET_TIME_absolute_get (); | 287 | start = GNUNET_TIME_absolute_get(); |
273 | publish = | 288 | publish = |
274 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, | 289 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, |
275 | GNUNET_FS_PUBLISH_OPTION_NONE); | 290 | GNUNET_FS_PUBLISH_OPTION_NONE); |
276 | GNUNET_assert (publish != NULL); | 291 | GNUNET_assert(publish != NULL); |
277 | } | 292 | } |
278 | 293 | ||
279 | 294 | ||
280 | int | 295 | int |
281 | main (int argc, char *argv[]) | 296 | main(int argc, char *argv[]) |
282 | { | 297 | { |
283 | if (0 != GNUNET_TESTING_peer_run ("test-fs-unindex-persistence", | 298 | if (0 != GNUNET_TESTING_peer_run("test-fs-unindex-persistence", |
284 | "test_fs_unindex_data.conf", | 299 | "test_fs_unindex_data.conf", |
285 | &run, NULL)) | 300 | &run, NULL)) |
286 | return 1; | 301 | return 1; |
287 | return 0; | 302 | return 0; |
288 | } | 303 | } |
diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c index e0a2ecea7..3cbbc27d3 100644 --- a/src/fs/test_fs_uri.c +++ b/src/fs/test_fs_uri.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/test_fs_uri.c | 21 | * @file fs/test_fs_uri.c |
22 | * @brief Test for fs_uri.c | 22 | * @brief Test for 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; |
@@ -84,71 +84,71 @@ testLocation () | |||
84 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 84 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; |
85 | 85 | ||
86 | baseURI = | 86 | baseURI = |
87 | GNUNET_FS_uri_parse | 87 | GNUNET_FS_uri_parse |
88 | ("gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.15999", | 88 | ("gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.15999", |
89 | &emsg); | 89 | &emsg); |
90 | GNUNET_assert (baseURI != NULL); | 90 | GNUNET_assert(baseURI != NULL); |
91 | GNUNET_assert (emsg == NULL); | 91 | GNUNET_assert(emsg == NULL); |
92 | pk = GNUNET_CRYPTO_eddsa_key_create (); | 92 | pk = GNUNET_CRYPTO_eddsa_key_create(); |
93 | uri = GNUNET_FS_uri_loc_create (baseURI, | 93 | uri = GNUNET_FS_uri_loc_create(baseURI, |
94 | pk, | 94 | pk, |
95 | GNUNET_TIME_absolute_get ()); | 95 | GNUNET_TIME_absolute_get()); |
96 | GNUNET_free (pk); | 96 | GNUNET_free(pk); |
97 | if (NULL == uri) | 97 | if (NULL == uri) |
98 | { | 98 | { |
99 | GNUNET_break (0); | 99 | GNUNET_break(0); |
100 | GNUNET_FS_uri_destroy (baseURI); | 100 | GNUNET_FS_uri_destroy(baseURI); |
101 | return 1; | 101 | return 1; |
102 | } | 102 | } |
103 | if (! GNUNET_FS_uri_test_loc (uri)) | 103 | if (!GNUNET_FS_uri_test_loc(uri)) |
104 | { | 104 | { |
105 | GNUNET_break (0); | 105 | GNUNET_break(0); |
106 | GNUNET_FS_uri_destroy (uri); | 106 | GNUNET_FS_uri_destroy(uri); |
107 | GNUNET_FS_uri_destroy (baseURI); | 107 | GNUNET_FS_uri_destroy(baseURI); |
108 | return 1; | 108 | return 1; |
109 | } | 109 | } |
110 | uri2 = GNUNET_FS_uri_loc_get_uri (uri); | 110 | uri2 = GNUNET_FS_uri_loc_get_uri(uri); |
111 | if (! GNUNET_FS_uri_test_equal (baseURI, uri2)) | 111 | if (!GNUNET_FS_uri_test_equal(baseURI, uri2)) |
112 | { | 112 | { |
113 | GNUNET_break (0); | 113 | GNUNET_break(0); |
114 | GNUNET_FS_uri_destroy (uri); | 114 | GNUNET_FS_uri_destroy(uri); |
115 | GNUNET_FS_uri_destroy (uri2); | 115 | GNUNET_FS_uri_destroy(uri2); |
116 | GNUNET_FS_uri_destroy (baseURI); | 116 | GNUNET_FS_uri_destroy(baseURI); |
117 | return 1; | 117 | return 1; |
118 | } | 118 | } |
119 | GNUNET_FS_uri_destroy (uri2); | 119 | GNUNET_FS_uri_destroy(uri2); |
120 | GNUNET_FS_uri_destroy (baseURI); | 120 | GNUNET_FS_uri_destroy(baseURI); |
121 | uric = GNUNET_FS_uri_to_string (uri); | 121 | uric = GNUNET_FS_uri_to_string(uri); |
122 | #if 0 | 122 | #if 0 |
123 | /* not for the faint of heart: */ | 123 | /* not for the faint of heart: */ |
124 | printf ("URI: `%s'\n", uric); | 124 | printf("URI: `%s'\n", uric); |
125 | #endif | 125 | #endif |
126 | uri2 = GNUNET_FS_uri_parse (uric, &emsg); | 126 | uri2 = GNUNET_FS_uri_parse(uric, &emsg); |
127 | GNUNET_free (uric); | 127 | GNUNET_free(uric); |
128 | if (uri2 == NULL) | 128 | if (uri2 == NULL) |
129 | { | 129 | { |
130 | fprintf (stderr, "URI parsing failed: %s\n", emsg); | 130 | fprintf(stderr, "URI parsing failed: %s\n", emsg); |
131 | GNUNET_break (0); | 131 | GNUNET_break(0); |
132 | GNUNET_FS_uri_destroy (uri); | 132 | GNUNET_FS_uri_destroy(uri); |
133 | GNUNET_free (emsg); | 133 | GNUNET_free(emsg); |
134 | return 1; | 134 | return 1; |
135 | } | 135 | } |
136 | GNUNET_assert (NULL == emsg); | 136 | GNUNET_assert(NULL == emsg); |
137 | if (GNUNET_YES != GNUNET_FS_uri_test_equal (uri, uri2)) | 137 | if (GNUNET_YES != GNUNET_FS_uri_test_equal(uri, uri2)) |
138 | { | 138 | { |
139 | GNUNET_break (0); | 139 | GNUNET_break(0); |
140 | GNUNET_FS_uri_destroy (uri); | 140 | GNUNET_FS_uri_destroy(uri); |
141 | GNUNET_FS_uri_destroy (uri2); | 141 | GNUNET_FS_uri_destroy(uri2); |
142 | return 1; | 142 | return 1; |
143 | } | 143 | } |
144 | GNUNET_FS_uri_destroy (uri2); | 144 | GNUNET_FS_uri_destroy(uri2); |
145 | GNUNET_FS_uri_destroy (uri); | 145 | GNUNET_FS_uri_destroy(uri); |
146 | return 0; | 146 | return 0; |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
150 | static int | 150 | static int |
151 | testNamespace (int i) | 151 | testNamespace(int i) |
152 | { | 152 | { |
153 | char *uri; | 153 | char *uri; |
154 | struct GNUNET_FS_Uri *ret; | 154 | struct GNUNET_FS_Uri *ret; |
@@ -161,71 +161,71 @@ testNamespace (int i) | |||
161 | 161 | ||
162 | if (NULL != | 162 | if (NULL != |
163 | (ret = | 163 | (ret = |
164 | GNUNET_FS_uri_parse ("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK", | 164 | GNUNET_FS_uri_parse("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK", |
165 | &emsg))) | 165 | &emsg))) |
166 | { | 166 | { |
167 | GNUNET_FS_uri_destroy (ret); | 167 | GNUNET_FS_uri_destroy(ret); |
168 | GNUNET_assert (0); | 168 | GNUNET_assert(0); |
169 | } | 169 | } |
170 | GNUNET_free (emsg); | 170 | GNUNET_free(emsg); |
171 | if (NULL != | 171 | if (NULL != |
172 | (ret = | 172 | (ret = |
173 | GNUNET_FS_uri_parse | 173 | GNUNET_FS_uri_parse |
174 | ("gnunet://fs/sks/XQHH4R288W26EBV369F6RCE0PJVJTX2Y74Q2FJPMPGA31HJX2JG/this", &emsg))) | 174 | ("gnunet://fs/sks/XQHH4R288W26EBV369F6RCE0PJVJTX2Y74Q2FJPMPGA31HJX2JG/this", &emsg))) |
175 | { | 175 | { |
176 | GNUNET_FS_uri_destroy (ret); | 176 | GNUNET_FS_uri_destroy(ret); |
177 | GNUNET_assert (0); | 177 | GNUNET_assert(0); |
178 | } | 178 | } |
179 | GNUNET_free (emsg); | 179 | GNUNET_free(emsg); |
180 | if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/sks/test", &emsg))) | 180 | if (NULL != (ret = GNUNET_FS_uri_parse("gnunet://fs/sks/test", &emsg))) |
181 | { | 181 | { |
182 | GNUNET_FS_uri_destroy (ret); | 182 | GNUNET_FS_uri_destroy(ret); |
183 | GNUNET_assert (0); | 183 | GNUNET_assert(0); |
184 | } | 184 | } |
185 | GNUNET_free (emsg); | 185 | GNUNET_free(emsg); |
186 | ph = GNUNET_CRYPTO_ecdsa_key_create (); | 186 | ph = GNUNET_CRYPTO_ecdsa_key_create(); |
187 | GNUNET_CRYPTO_ecdsa_key_get_public (ph, &id); | 187 | GNUNET_CRYPTO_ecdsa_key_get_public(ph, &id); |
188 | sret = GNUNET_STRINGS_data_to_string (&id, sizeof (id), | 188 | sret = GNUNET_STRINGS_data_to_string(&id, sizeof(id), |
189 | ubuf, sizeof (ubuf) - 1); | 189 | ubuf, sizeof(ubuf) - 1); |
190 | GNUNET_assert (NULL != sret); | 190 | GNUNET_assert(NULL != sret); |
191 | sret[0] = '\0'; | 191 | sret[0] = '\0'; |
192 | GNUNET_snprintf (buf, sizeof (buf), | 192 | GNUNET_snprintf(buf, sizeof(buf), |
193 | "gnunet://fs/sks/%s/test", | 193 | "gnunet://fs/sks/%s/test", |
194 | ubuf); | 194 | ubuf); |
195 | ret = GNUNET_FS_uri_parse (buf, &emsg); | 195 | ret = GNUNET_FS_uri_parse(buf, &emsg); |
196 | if (NULL == ret) | 196 | if (NULL == ret) |
197 | { | 197 | { |
198 | GNUNET_free (emsg); | 198 | GNUNET_free(emsg); |
199 | GNUNET_assert (0); | 199 | GNUNET_assert(0); |
200 | } | 200 | } |
201 | if (GNUNET_FS_uri_test_ksk (ret)) | 201 | if (GNUNET_FS_uri_test_ksk(ret)) |
202 | { | 202 | { |
203 | GNUNET_FS_uri_destroy (ret); | 203 | GNUNET_FS_uri_destroy(ret); |
204 | GNUNET_assert (0); | 204 | GNUNET_assert(0); |
205 | } | 205 | } |
206 | if (!GNUNET_FS_uri_test_sks (ret)) | 206 | if (!GNUNET_FS_uri_test_sks(ret)) |
207 | { | 207 | { |
208 | GNUNET_FS_uri_destroy (ret); | 208 | GNUNET_FS_uri_destroy(ret); |
209 | GNUNET_assert (0); | 209 | GNUNET_assert(0); |
210 | } | 210 | } |
211 | 211 | ||
212 | uri = GNUNET_FS_uri_to_string (ret); | 212 | uri = GNUNET_FS_uri_to_string(ret); |
213 | if (0 != | 213 | if (0 != |
214 | strcmp (uri, | 214 | strcmp(uri, |
215 | buf)) | 215 | buf)) |
216 | { | 216 | { |
217 | GNUNET_FS_uri_destroy (ret); | 217 | GNUNET_FS_uri_destroy(ret); |
218 | GNUNET_free (uri); | 218 | GNUNET_free(uri); |
219 | GNUNET_assert (0); | 219 | GNUNET_assert(0); |
220 | } | 220 | } |
221 | GNUNET_free (uri); | 221 | GNUNET_free(uri); |
222 | GNUNET_FS_uri_destroy (ret); | 222 | GNUNET_FS_uri_destroy(ret); |
223 | return 0; | 223 | return 0; |
224 | } | 224 | } |
225 | 225 | ||
226 | 226 | ||
227 | static int | 227 | static int |
228 | testFile (int i) | 228 | testFile(int i) |
229 | { | 229 | { |
230 | char *uri; | 230 | char *uri; |
231 | struct GNUNET_FS_Uri *ret; | 231 | struct GNUNET_FS_Uri *ret; |
@@ -233,93 +233,93 @@ testFile (int i) | |||
233 | 233 | ||
234 | if (NULL != | 234 | if (NULL != |
235 | (ret = | 235 | (ret = |
236 | GNUNET_FS_uri_parse | 236 | GNUNET_FS_uri_parse |
237 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42", | 237 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42", |
238 | &emsg))) | 238 | &emsg))) |
239 | { | 239 | { |
240 | GNUNET_FS_uri_destroy (ret); | 240 | GNUNET_FS_uri_destroy(ret); |
241 | GNUNET_assert (0); | 241 | GNUNET_assert(0); |
242 | } | 242 | } |
243 | GNUNET_free (emsg); | 243 | GNUNET_free(emsg); |
244 | if (NULL != | 244 | if (NULL != |
245 | (ret = | 245 | (ret = |
246 | GNUNET_FS_uri_parse | 246 | GNUNET_FS_uri_parse |
247 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000", | 247 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000", |
248 | &emsg))) | 248 | &emsg))) |
249 | { | 249 | { |
250 | GNUNET_FS_uri_destroy (ret); | 250 | GNUNET_FS_uri_destroy(ret); |
251 | GNUNET_assert (0); | 251 | GNUNET_assert(0); |
252 | } | 252 | } |
253 | GNUNET_free (emsg); | 253 | GNUNET_free(emsg); |
254 | if (NULL != | 254 | if (NULL != |
255 | (ret = | 255 | (ret = |
256 | GNUNET_FS_uri_parse | 256 | GNUNET_FS_uri_parse |
257 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH", | 257 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH", |
258 | &emsg))) | 258 | &emsg))) |
259 | { | 259 | { |
260 | GNUNET_FS_uri_destroy (ret); | 260 | GNUNET_FS_uri_destroy(ret); |
261 | GNUNET_assert (0); | 261 | GNUNET_assert(0); |
262 | } | 262 | } |
263 | GNUNET_free (emsg); | 263 | GNUNET_free(emsg); |
264 | ret = | 264 | ret = |
265 | GNUNET_FS_uri_parse | 265 | GNUNET_FS_uri_parse |
266 | ("gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42", | 266 | ("gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42", |
267 | &emsg); | 267 | &emsg); |
268 | if (ret == NULL) | 268 | if (ret == NULL) |
269 | { | 269 | { |
270 | GNUNET_free (emsg); | 270 | GNUNET_free(emsg); |
271 | GNUNET_assert (0); | 271 | GNUNET_assert(0); |
272 | } | 272 | } |
273 | if (GNUNET_FS_uri_test_ksk (ret)) | 273 | if (GNUNET_FS_uri_test_ksk(ret)) |
274 | { | 274 | { |
275 | GNUNET_FS_uri_destroy (ret); | 275 | GNUNET_FS_uri_destroy(ret); |
276 | GNUNET_assert (0); | 276 | GNUNET_assert(0); |
277 | } | 277 | } |
278 | if (GNUNET_FS_uri_test_sks (ret)) | 278 | if (GNUNET_FS_uri_test_sks(ret)) |
279 | { | 279 | { |
280 | GNUNET_FS_uri_destroy (ret); | 280 | GNUNET_FS_uri_destroy(ret); |
281 | GNUNET_assert (0); | 281 | GNUNET_assert(0); |
282 | } | 282 | } |
283 | if (GNUNET_ntohll (ret->data.chk.file_length) != 42) | 283 | if (GNUNET_ntohll(ret->data.chk.file_length) != 42) |
284 | { | 284 | { |
285 | GNUNET_FS_uri_destroy (ret); | 285 | GNUNET_FS_uri_destroy(ret); |
286 | GNUNET_assert (0); | 286 | GNUNET_assert(0); |
287 | } | 287 | } |
288 | 288 | ||
289 | uri = GNUNET_FS_uri_to_string (ret); | 289 | uri = GNUNET_FS_uri_to_string(ret); |
290 | if (0 != | 290 | if (0 != |
291 | strcmp (uri, | 291 | strcmp(uri, |
292 | "gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42")) | 292 | "gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42")) |
293 | { | 293 | { |
294 | GNUNET_free (uri); | 294 | GNUNET_free(uri); |
295 | GNUNET_FS_uri_destroy (ret); | 295 | GNUNET_FS_uri_destroy(ret); |
296 | GNUNET_assert (0); | 296 | GNUNET_assert(0); |
297 | } | 297 | } |
298 | GNUNET_free (uri); | 298 | GNUNET_free(uri); |
299 | GNUNET_FS_uri_destroy (ret); | 299 | GNUNET_FS_uri_destroy(ret); |
300 | return 0; | 300 | return 0; |
301 | } | 301 | } |
302 | 302 | ||
303 | 303 | ||
304 | int | 304 | int |
305 | main (int argc, char *argv[]) | 305 | main(int argc, char *argv[]) |
306 | { | 306 | { |
307 | int failureCount = 0; | 307 | int failureCount = 0; |
308 | int i; | 308 | int i; |
309 | 309 | ||
310 | GNUNET_log_setup ("test_fs_uri", | 310 | GNUNET_log_setup("test_fs_uri", |
311 | "WARNING", | 311 | "WARNING", |
312 | NULL); | 312 | NULL); |
313 | failureCount += testKeyword (); | 313 | failureCount += testKeyword(); |
314 | failureCount += testLocation (); | 314 | failureCount += testLocation(); |
315 | for (i = 0; i < 255; i++) | 315 | for (i = 0; i < 255; i++) |
316 | { | 316 | { |
317 | /* fprintf (stderr, "%s", "."); */ | 317 | /* fprintf (stderr, "%s", "."); */ |
318 | failureCount += testNamespace (i); | 318 | failureCount += testNamespace(i); |
319 | failureCount += testFile (i); | 319 | failureCount += testFile(i); |
320 | } | 320 | } |
321 | /* fprintf (stderr, "%s", "\n"); */ | 321 | /* fprintf (stderr, "%s", "\n"); */ |
322 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri"); | 322 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-uri"); |
323 | if (failureCount != 0) | 323 | if (failureCount != 0) |
324 | return 1; | 324 | return 1; |
325 | return 0; | 325 | return 0; |
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c index f7daf6b1a..c56e89e11 100644 --- a/src/fs/test_gnunet_service_fs_migration.c +++ b/src/fs/test_gnunet_service_fs_migration.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_gnunet_service_fs_migration.c | 22 | * @file fs/test_gnunet_service_fs_migration.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, 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, 90) |
46 | 46 | ||
47 | #define SEED 42 | 47 | #define SEED 42 |
48 | 48 | ||
@@ -55,8 +55,7 @@ static struct GNUNET_TIME_Absolute start_time; | |||
55 | static struct GNUNET_TESTBED_Operation *op; | 55 | static struct GNUNET_TESTBED_Operation *op; |
56 | 56 | ||
57 | 57 | ||
58 | struct DownloadContext | 58 | struct DownloadContext { |
59 | { | ||
60 | char *fn; | 59 | char *fn; |
61 | 60 | ||
62 | struct GNUNET_FS_Uri *uri; | 61 | struct GNUNET_FS_Uri *uri; |
@@ -64,154 +63,154 @@ struct DownloadContext | |||
64 | 63 | ||
65 | 64 | ||
66 | static void | 65 | static void |
67 | do_stop (void *cls) | 66 | do_stop(void *cls) |
68 | { | 67 | { |
69 | struct GNUNET_TIME_Relative del; | 68 | struct GNUNET_TIME_Relative del; |
70 | char *fancy; | 69 | char *fancy; |
71 | 70 | ||
72 | GNUNET_SCHEDULER_shutdown (); | 71 | GNUNET_SCHEDULER_shutdown(); |
73 | if (0 == | 72 | if (0 == |
74 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, | 73 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, |
75 | TIMEOUT)).rel_value_us) | 74 | TIMEOUT)).rel_value_us) |
76 | { | 75 | { |
77 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 76 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
78 | "Timeout during download, shutting down with error\n"); | 77 | "Timeout during download, shutting down with error\n"); |
79 | ok = 1; | 78 | ok = 1; |
80 | } | 79 | } |
81 | else | 80 | else |
82 | { | 81 | { |
83 | del = GNUNET_TIME_absolute_get_duration (start_time); | 82 | del = GNUNET_TIME_absolute_get_duration(start_time); |
84 | if (del.rel_value_us == 0) | 83 | if (del.rel_value_us == 0) |
85 | del.rel_value_us = 1; | 84 | del.rel_value_us = 1; |
86 | fancy = | 85 | fancy = |
87 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * | 86 | GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * |
88 | 1000000LL / del.rel_value_us); | 87 | 1000000LL / del.rel_value_us); |
89 | fprintf (stdout, | 88 | fprintf(stdout, |
90 | "Download speed was %s/s\n", | 89 | "Download speed was %s/s\n", |
91 | fancy); | 90 | fancy); |
92 | GNUNET_free (fancy); | 91 | GNUNET_free(fancy); |
93 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 92 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
94 | "Finished download, shutting down\n"); | 93 | "Finished download, shutting down\n"); |
95 | } | 94 | } |
96 | } | 95 | } |
97 | 96 | ||
98 | 97 | ||
99 | static void | 98 | static void |
100 | do_download (void *cls, | 99 | do_download(void *cls, |
101 | const char *emsg) | 100 | const char *emsg) |
102 | { | 101 | { |
103 | struct DownloadContext *dc = cls; | 102 | struct DownloadContext *dc = cls; |
104 | struct GNUNET_FS_Uri *uri = dc->uri; | 103 | struct GNUNET_FS_Uri *uri = dc->uri; |
105 | 104 | ||
106 | GNUNET_TESTBED_operation_done (op); | 105 | GNUNET_TESTBED_operation_done(op); |
107 | op = NULL; | 106 | op = NULL; |
108 | if (NULL != dc->fn) | 107 | if (NULL != dc->fn) |
109 | { | 108 | { |
110 | GNUNET_DISK_directory_remove (dc->fn); | 109 | GNUNET_DISK_directory_remove(dc->fn); |
111 | GNUNET_free (dc->fn); | 110 | GNUNET_free(dc->fn); |
112 | } | 111 | } |
113 | GNUNET_free (dc); | 112 | GNUNET_free(dc); |
114 | if (NULL != emsg) | 113 | if (NULL != emsg) |
115 | { | 114 | { |
116 | GNUNET_SCHEDULER_shutdown (); | 115 | GNUNET_SCHEDULER_shutdown(); |
117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 116 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
118 | "Failed to stop source daemon: %s\n", | 117 | "Failed to stop source daemon: %s\n", |
119 | emsg); | 118 | emsg); |
120 | GNUNET_FS_uri_destroy (uri); | 119 | GNUNET_FS_uri_destroy(uri); |
121 | ok = 1; | 120 | ok = 1; |
122 | return; | 121 | return; |
123 | } | 122 | } |
124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 123 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
125 | "Downloading %llu bytes\n", | 124 | "Downloading %llu bytes\n", |
126 | (unsigned long long) FILESIZE); | 125 | (unsigned long long)FILESIZE); |
127 | start_time = GNUNET_TIME_absolute_get (); | 126 | start_time = GNUNET_TIME_absolute_get(); |
128 | GNUNET_FS_TEST_download (daemons[0], | 127 | GNUNET_FS_TEST_download(daemons[0], |
129 | TIMEOUT, | 128 | TIMEOUT, |
130 | 1, | 129 | 1, |
131 | SEED, | 130 | SEED, |
132 | uri, | 131 | uri, |
133 | VERBOSE, | 132 | VERBOSE, |
134 | &do_stop, | 133 | &do_stop, |
135 | NULL); | 134 | NULL); |
136 | GNUNET_FS_uri_destroy (uri); | 135 | GNUNET_FS_uri_destroy(uri); |
137 | } | 136 | } |
138 | 137 | ||
139 | 138 | ||
140 | static void | 139 | static void |
141 | stop_source_peer (void *cls) | 140 | stop_source_peer(void *cls) |
142 | { | 141 | { |
143 | struct DownloadContext *dc = cls; | 142 | struct DownloadContext *dc = cls; |
144 | 143 | ||
145 | /* FIXME: We should not interact with testbed when shutting down */ | 144 | /* FIXME: We should not interact with testbed when shutting down */ |
146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 145 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
147 | "Stopping source peer\n"); | 146 | "Stopping source peer\n"); |
148 | op = GNUNET_TESTBED_peer_stop (NULL, | 147 | op = GNUNET_TESTBED_peer_stop(NULL, |
149 | daemons[1], | 148 | daemons[1], |
150 | &do_download, dc); | 149 | &do_download, dc); |
151 | GNUNET_assert (NULL != op); | 150 | GNUNET_assert(NULL != op); |
152 | } | 151 | } |
153 | 152 | ||
154 | 153 | ||
155 | static void | 154 | static void |
156 | do_wait (void *cls, | 155 | do_wait(void *cls, |
157 | const struct GNUNET_FS_Uri *uri, | 156 | const struct GNUNET_FS_Uri *uri, |
158 | const char *fn) | 157 | const char *fn) |
159 | { | 158 | { |
160 | struct DownloadContext *dc; | 159 | struct DownloadContext *dc; |
161 | 160 | ||
162 | if (NULL == uri) | 161 | if (NULL == uri) |
163 | { | 162 | { |
164 | GNUNET_SCHEDULER_shutdown (); | 163 | GNUNET_SCHEDULER_shutdown(); |
165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 164 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
166 | "Timeout during upload attempt, shutting down with error\n"); | 165 | "Timeout during upload attempt, shutting down with error\n"); |
167 | ok = 1; | 166 | ok = 1; |
168 | return; | 167 | return; |
169 | } | 168 | } |
170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 169 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
171 | "Waiting to allow content to migrate\n"); | 170 | "Waiting to allow content to migrate\n"); |
172 | dc = GNUNET_new (struct DownloadContext); | 171 | dc = GNUNET_new(struct DownloadContext); |
173 | dc->uri = GNUNET_FS_uri_dup (uri); | 172 | dc->uri = GNUNET_FS_uri_dup(uri); |
174 | if (NULL != fn) | 173 | if (NULL != fn) |
175 | dc->fn = GNUNET_strdup (fn); | 174 | dc->fn = GNUNET_strdup(fn); |
176 | (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, | 175 | (void)GNUNET_SCHEDULER_add_delayed(MIGRATION_DELAY, |
177 | &stop_source_peer, | 176 | &stop_source_peer, |
178 | dc); | 177 | dc); |
179 | } | 178 | } |
180 | 179 | ||
181 | 180 | ||
182 | static void | 181 | static void |
183 | do_publish (void *cls, | 182 | do_publish(void *cls, |
184 | struct GNUNET_TESTBED_RunHandle *h, | 183 | struct GNUNET_TESTBED_RunHandle *h, |
185 | unsigned int num_peers, | 184 | unsigned int num_peers, |
186 | struct GNUNET_TESTBED_Peer **peers, | 185 | struct GNUNET_TESTBED_Peer **peers, |
187 | unsigned int links_succeeded, | 186 | unsigned int links_succeeded, |
188 | unsigned int links_failed) | 187 | unsigned int links_failed) |
189 | { | 188 | { |
190 | unsigned int i; | 189 | unsigned int i; |
191 | 190 | ||
192 | GNUNET_assert (2 == num_peers); | 191 | GNUNET_assert(2 == num_peers); |
193 | for (i=0;i<num_peers;i++) | 192 | for (i = 0; i < num_peers; i++) |
194 | daemons[i] = peers[i]; | 193 | daemons[i] = peers[i]; |
195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 194 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
196 | "Publishing %llu bytes\n", | 195 | "Publishing %llu bytes\n", |
197 | (unsigned long long) FILESIZE); | 196 | (unsigned long long)FILESIZE); |
198 | GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO, | 197 | GNUNET_FS_TEST_publish(daemons[1], TIMEOUT, 1, GNUNET_NO, |
199 | FILESIZE, SEED, | 198 | FILESIZE, SEED, |
200 | VERBOSE, &do_wait, NULL); | 199 | VERBOSE, &do_wait, NULL); |
201 | } | 200 | } |
202 | 201 | ||
203 | 202 | ||
204 | int | 203 | int |
205 | main (int argc, | 204 | main(int argc, |
206 | char *argv[]) | 205 | char *argv[]) |
207 | { | 206 | { |
208 | (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration", | 207 | (void)GNUNET_TESTBED_test_run("test-gnunet-service-fs-migration", |
209 | "fs_test_lib_data.conf", | 208 | "fs_test_lib_data.conf", |
210 | 2, | 209 | 2, |
211 | 0, NULL, NULL, | 210 | 0, NULL, NULL, |
212 | &do_publish, | 211 | &do_publish, |
213 | NULL); | 212 | NULL); |
214 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); | 213 | GNUNET_DISK_directory_remove("/tmp/test-gnunet-service-fs-migration/"); |
215 | return ok; | 214 | return ok; |
216 | } | 215 | } |
217 | 216 | ||
diff --git a/src/fs/test_gnunet_service_fs_p2p.c b/src/fs/test_gnunet_service_fs_p2p.c index 2050b0835..eba4e112d 100644 --- a/src/fs/test_gnunet_service_fs_p2p.c +++ b/src/fs/test_gnunet_service_fs_p2p.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/test_gnunet_service_fs_p2p.c | 22 | * @file 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,110 @@ 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)).rel_value_us) |
67 | { | 67 | { |
68 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 68 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
69 | "Timeout during download, shutting down with error\n"); | 69 | "Timeout during download, shutting down with error\n"); |
70 | ok = 1; | 70 | ok = 1; |
71 | } | 71 | } |
72 | else | 72 | else |
73 | { | 73 | { |
74 | del = GNUNET_TIME_absolute_get_duration (start_time); | 74 | del = GNUNET_TIME_absolute_get_duration(start_time); |
75 | if (0 == del.rel_value_us) | 75 | if (0 == del.rel_value_us) |
76 | del.rel_value_us = 1; | 76 | del.rel_value_us = 1; |
77 | fancy = | 77 | fancy = |
78 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * | 78 | GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * |
79 | 1000000LL / del.rel_value_us); | 79 | 1000000LL / del.rel_value_us); |
80 | fprintf (stdout, | 80 | fprintf(stdout, |
81 | "Download speed was %s/s\n", | 81 | "Download speed was %s/s\n", |
82 | fancy); | 82 | fancy); |
83 | GNUNET_free (fancy); | 83 | GNUNET_free(fancy); |
84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 84 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
85 | "Finished download, shutting down\n"); | 85 | "Finished download, shutting down\n"); |
86 | } | 86 | } |
87 | if (NULL != fn) | 87 | if (NULL != fn) |
88 | { | 88 | { |
89 | GNUNET_DISK_directory_remove (fn); | 89 | GNUNET_DISK_directory_remove(fn); |
90 | GNUNET_free (fn); | 90 | GNUNET_free(fn); |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | 94 | ||
95 | static void | 95 | static void |
96 | do_download (void *cls, const struct GNUNET_FS_Uri *uri, | 96 | do_download(void *cls, const struct GNUNET_FS_Uri *uri, |
97 | const char *fn) | 97 | const char *fn) |
98 | { | 98 | { |
99 | if (NULL == uri) | 99 | if (NULL == uri) |
100 | { | 100 | { |
101 | GNUNET_SCHEDULER_shutdown (); | 101 | GNUNET_SCHEDULER_shutdown(); |
102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 102 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
103 | "Timeout during upload attempt, shutting down with error\n"); | 103 | "Timeout during upload attempt, shutting down with error\n"); |
104 | ok = 1; | 104 | ok = 1; |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", | 107 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", |
108 | (unsigned long long) FILESIZE); | 108 | (unsigned long long)FILESIZE); |
109 | start_time = GNUNET_TIME_absolute_get (); | 109 | start_time = GNUNET_TIME_absolute_get(); |
110 | GNUNET_FS_TEST_download (daemons[0], TIMEOUT, | 110 | GNUNET_FS_TEST_download(daemons[0], TIMEOUT, |
111 | anonymity_level, SEED, uri, | 111 | anonymity_level, SEED, uri, |
112 | VERBOSE, &do_stop, | 112 | VERBOSE, &do_stop, |
113 | (NULL == fn) | 113 | (NULL == fn) |
114 | ? NULL | 114 | ? NULL |
115 | : GNUNET_strdup (fn)); | 115 | : GNUNET_strdup(fn)); |
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | static void | 119 | static void |
120 | do_publish (void *cls, | 120 | do_publish(void *cls, |
121 | struct GNUNET_TESTBED_RunHandle *h, | 121 | struct GNUNET_TESTBED_RunHandle *h, |
122 | unsigned int num_peers, | 122 | unsigned int num_peers, |
123 | struct GNUNET_TESTBED_Peer **peers, | 123 | struct GNUNET_TESTBED_Peer **peers, |
124 | unsigned int links_succeeded, | 124 | unsigned int links_succeeded, |
125 | unsigned int links_failed) | 125 | unsigned int links_failed) |
126 | { | 126 | { |
127 | unsigned int i; | 127 | unsigned int i; |
128 | 128 | ||
129 | if (NULL != strstr (progname, "cadet")) | 129 | if (NULL != strstr(progname, "cadet")) |
130 | anonymity_level = 0; | 130 | anonymity_level = 0; |
131 | else | 131 | else |
132 | anonymity_level = 1; | 132 | anonymity_level = 1; |
133 | GNUNET_assert (NUM_DAEMONS == num_peers); | 133 | GNUNET_assert(NUM_DAEMONS == num_peers); |
134 | for (i=0;i<num_peers;i++) | 134 | for (i = 0; i < num_peers; i++) |
135 | daemons[i] = peers[i]; | 135 | daemons[i] = peers[i]; |
136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", | 136 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", |
137 | (unsigned long long) FILESIZE); | 137 | (unsigned long long)FILESIZE); |
138 | GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, | 138 | GNUNET_FS_TEST_publish(daemons[1], TIMEOUT, |
139 | anonymity_level, GNUNET_NO, | 139 | anonymity_level, GNUNET_NO, |
140 | FILESIZE, SEED, | 140 | FILESIZE, SEED, |
141 | VERBOSE, &do_download, NULL); | 141 | VERBOSE, &do_download, NULL); |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | int | 145 | int |
146 | main (int argc, char *argv[]) | 146 | main(int argc, char *argv[]) |
147 | { | 147 | { |
148 | const char *config; | 148 | const char *config; |
149 | 149 | ||
150 | progname = argv[0]; | 150 | progname = argv[0]; |
151 | if (NULL != strstr (progname, "cadet")) | 151 | if (NULL != strstr(progname, "cadet")) |
152 | config = "test_gnunet_service_fs_p2p_cadet.conf"; | 152 | config = "test_gnunet_service_fs_p2p_cadet.conf"; |
153 | else | 153 | else |
154 | config = "fs_test_lib_data.conf"; | 154 | config = "fs_test_lib_data.conf"; |
155 | (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-p2p", | 155 | (void)GNUNET_TESTBED_test_run("test-gnunet-service-fs-p2p", |
156 | config, | 156 | config, |
157 | NUM_DAEMONS, | 157 | NUM_DAEMONS, |
158 | 0, NULL, NULL, | 158 | 0, NULL, NULL, |
159 | &do_publish, NULL); | 159 | &do_publish, NULL); |
160 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | 160 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/"); |
161 | return ok; | 161 | return ok; |
162 | } | 162 | } |
163 | 163 | ||
diff --git a/src/fs/test_plugin_block_fs.c b/src/fs/test_plugin_block_fs.c index 3b17b6917..53f7304dd 100644 --- a/src/fs/test_plugin_block_fs.c +++ b/src/fs/test_plugin_block_fs.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file fs/test_plugin_block_fs.c | 21 | * @file fs/test_plugin_block_fs.c |
22 | * @brief test for plugin_block_fs.c | 22 | * @brief test for 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 | ||