diff options
Diffstat (limited to 'src/fs/gnunet-service-fs_indexing.c')
-rw-r--r-- | src/fs/gnunet-service-fs_indexing.c | 473 |
1 files changed, 237 insertions, 236 deletions
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c index e21b2ca57..4a7172c50 100644 --- a/src/fs/gnunet-service-fs_indexing.c +++ b/src/fs/gnunet-service-fs_indexing.c | |||
@@ -39,7 +39,8 @@ | |||
39 | * In-memory information about indexed files (also available | 39 | * In-memory information about indexed files (also available |
40 | * on-disk). | 40 | * on-disk). |
41 | */ | 41 | */ |
42 | struct IndexInfo { | 42 | struct IndexInfo |
43 | { | ||
43 | /** | 44 | /** |
44 | * This is a doubly linked list. | 45 | * This is a doubly linked list. |
45 | */ | 46 | */ |
@@ -108,44 +109,44 @@ static struct GNUNET_DATASTORE_Handle *dsh; | |||
108 | * Write the current index information list to disk. | 109 | * Write the current index information list to disk. |
109 | */ | 110 | */ |
110 | static void | 111 | static void |
111 | write_index_list() | 112 | write_index_list () |
112 | { | 113 | { |
113 | struct GNUNET_BIO_WriteHandle *wh; | 114 | struct GNUNET_BIO_WriteHandle *wh; |
114 | char *fn; | 115 | char *fn; |
115 | struct IndexInfo *pos; | 116 | struct IndexInfo *pos; |
116 | 117 | ||
117 | if (GNUNET_OK != | 118 | if (GNUNET_OK != |
118 | GNUNET_CONFIGURATION_get_value_filename(cfg, "FS", "INDEXDB", &fn)) | 119 | GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) |
119 | { | 120 | { |
120 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 121 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
121 | "fs", | 122 | "fs", |
122 | "INDEXDB"); | 123 | "INDEXDB"); |
123 | return; | 124 | return; |
124 | } | 125 | } |
125 | wh = GNUNET_BIO_write_open(fn); | 126 | wh = GNUNET_BIO_write_open (fn); |
126 | if (NULL == wh) | 127 | if (NULL == wh) |
127 | { | 128 | { |
128 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 129 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
129 | _("Could not open `%s'.\n"), | 130 | _ ("Could not open `%s'.\n"), |
130 | fn); | 131 | fn); |
131 | GNUNET_free(fn); | 132 | GNUNET_free (fn); |
132 | return; | 133 | return; |
133 | } | 134 | } |
134 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) | 135 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) |
135 | if ((GNUNET_OK != GNUNET_BIO_write(wh, | 136 | if ((GNUNET_OK != GNUNET_BIO_write (wh, |
136 | &pos->file_id, | 137 | &pos->file_id, |
137 | sizeof(struct GNUNET_HashCode))) || | 138 | sizeof(struct GNUNET_HashCode))) || |
138 | (GNUNET_OK != GNUNET_BIO_write_string(wh, pos->filename))) | 139 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename))) |
139 | break; | 140 | break; |
140 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) | 141 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) |
141 | { | 142 | { |
142 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 143 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
143 | _("Error writing `%s'.\n"), | 144 | _ ("Error writing `%s'.\n"), |
144 | fn); | 145 | fn); |
145 | GNUNET_free(fn); | 146 | GNUNET_free (fn); |
146 | return; | 147 | return; |
147 | } | 148 | } |
148 | GNUNET_free(fn); | 149 | GNUNET_free (fn); |
149 | } | 150 | } |
150 | 151 | ||
151 | 152 | ||
@@ -153,7 +154,7 @@ write_index_list() | |||
153 | * Read index information from disk. | 154 | * Read index information from disk. |
154 | */ | 155 | */ |
155 | static void | 156 | static void |
156 | read_index_list() | 157 | read_index_list () |
157 | { | 158 | { |
158 | struct GNUNET_BIO_ReadHandle *rh; | 159 | struct GNUNET_BIO_ReadHandle *rh; |
159 | char *fn; | 160 | char *fn; |
@@ -164,59 +165,59 @@ read_index_list() | |||
164 | char *emsg; | 165 | char *emsg; |
165 | 166 | ||
166 | if (GNUNET_OK != | 167 | if (GNUNET_OK != |
167 | GNUNET_CONFIGURATION_get_value_filename(cfg, "FS", "INDEXDB", &fn)) | 168 | GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) |
168 | { | 169 | { |
169 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 170 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
170 | "fs", | 171 | "fs", |
171 | "INDEXDB"); | 172 | "INDEXDB"); |
172 | return; | 173 | return; |
173 | } | 174 | } |
174 | if (GNUNET_NO == GNUNET_DISK_file_test(fn)) | 175 | if (GNUNET_NO == GNUNET_DISK_file_test (fn)) |
175 | { | 176 | { |
176 | /* no index info yet */ | 177 | /* no index info yet */ |
177 | GNUNET_free(fn); | 178 | GNUNET_free (fn); |
178 | return; | 179 | return; |
179 | } | 180 | } |
180 | rh = GNUNET_BIO_read_open(fn); | 181 | rh = GNUNET_BIO_read_open (fn); |
181 | if (NULL == rh) | 182 | if (NULL == rh) |
182 | { | 183 | { |
183 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
184 | _("Could not open `%s'.\n"), | 185 | _ ("Could not open `%s'.\n"), |
185 | fn); | 186 | fn); |
186 | GNUNET_free(fn); | 187 | GNUNET_free (fn); |
187 | return; | 188 | return; |
188 | } | 189 | } |
189 | while ( | 190 | while ( |
190 | (GNUNET_OK == GNUNET_BIO_read(rh, | 191 | (GNUNET_OK == GNUNET_BIO_read (rh, |
191 | "Hash of indexed file", | 192 | "Hash of indexed file", |
192 | &hc, | 193 | &hc, |
193 | sizeof(struct GNUNET_HashCode))) && | 194 | sizeof(struct GNUNET_HashCode))) && |
194 | (GNUNET_OK == | 195 | (GNUNET_OK == |
195 | GNUNET_BIO_read_string(rh, "Name of indexed file", &fname, 1024 * 16)) && | 196 | GNUNET_BIO_read_string (rh, "Name of indexed file", &fname, 1024 * 16)) && |
196 | (fname != NULL)) | 197 | (fname != NULL)) |
198 | { | ||
199 | slen = strlen (fname) + 1; | ||
200 | pos = GNUNET_malloc (sizeof(struct IndexInfo) + slen); | ||
201 | pos->file_id = hc; | ||
202 | pos->filename = (const char *) &pos[1]; | ||
203 | GNUNET_memcpy (&pos[1], fname, slen); | ||
204 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( | ||
205 | ifm, | ||
206 | &pos->file_id, | ||
207 | pos, | ||
208 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
209 | { | ||
210 | GNUNET_free (pos); | ||
211 | } | ||
212 | else | ||
197 | { | 213 | { |
198 | slen = strlen(fname) + 1; | 214 | GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, pos); |
199 | pos = GNUNET_malloc(sizeof(struct IndexInfo) + slen); | ||
200 | pos->file_id = hc; | ||
201 | pos->filename = (const char *)&pos[1]; | ||
202 | GNUNET_memcpy(&pos[1], fname, slen); | ||
203 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put( | ||
204 | ifm, | ||
205 | &pos->file_id, | ||
206 | pos, | ||
207 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
208 | { | ||
209 | GNUNET_free(pos); | ||
210 | } | ||
211 | else | ||
212 | { | ||
213 | GNUNET_CONTAINER_DLL_insert(indexed_files_head, indexed_files_tail, pos); | ||
214 | } | ||
215 | GNUNET_free(fname); | ||
216 | } | 215 | } |
217 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) | 216 | GNUNET_free (fname); |
218 | GNUNET_free(emsg); | 217 | } |
219 | GNUNET_free(fn); | 218 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
219 | GNUNET_free (emsg); | ||
220 | GNUNET_free (fn); | ||
220 | } | 221 | } |
221 | 222 | ||
222 | 223 | ||
@@ -230,15 +231,15 @@ read_index_list() | |||
230 | * @param msg error message | 231 | * @param msg error message |
231 | */ | 232 | */ |
232 | static void | 233 | static void |
233 | remove_cont(void *cls, | 234 | remove_cont (void *cls, |
234 | int success, | 235 | int success, |
235 | struct GNUNET_TIME_Absolute min_expiration, | 236 | struct GNUNET_TIME_Absolute min_expiration, |
236 | const char *msg) | 237 | const char *msg) |
237 | { | 238 | { |
238 | if (GNUNET_OK != success) | 239 | if (GNUNET_OK != success) |
239 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 240 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
240 | _("Failed to delete bogus block: %s\n"), | 241 | _ ("Failed to delete bogus block: %s\n"), |
241 | msg); | 242 | msg); |
242 | } | 243 | } |
243 | 244 | ||
244 | 245 | ||
@@ -263,17 +264,17 @@ remove_cont(void *cls, | |||
263 | * @return GNUNET_OK on success | 264 | * @return GNUNET_OK on success |
264 | */ | 265 | */ |
265 | int | 266 | int |
266 | GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, | 267 | GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, |
267 | uint32_t size, | 268 | uint32_t size, |
268 | const void *data, | 269 | const void *data, |
269 | enum GNUNET_BLOCK_Type type, | 270 | enum GNUNET_BLOCK_Type type, |
270 | uint32_t priority, | 271 | uint32_t priority, |
271 | uint32_t anonymity, | 272 | uint32_t anonymity, |
272 | uint32_t replication, | 273 | uint32_t replication, |
273 | struct GNUNET_TIME_Absolute expiration, | 274 | struct GNUNET_TIME_Absolute expiration, |
274 | uint64_t uid, | 275 | uint64_t uid, |
275 | GNUNET_DATASTORE_DatumProcessor cont, | 276 | GNUNET_DATASTORE_DatumProcessor cont, |
276 | void *cont_cls) | 277 | void *cont_cls) |
277 | { | 278 | { |
278 | const struct OnDemandBlock *odb; | 279 | const struct OnDemandBlock *odb; |
279 | struct GNUNET_HashCode nkey; | 280 | struct GNUNET_HashCode nkey; |
@@ -289,78 +290,78 @@ GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, | |||
289 | struct IndexInfo *ii; | 290 | struct IndexInfo *ii; |
290 | 291 | ||
291 | if (size != sizeof(struct OnDemandBlock)) | 292 | if (size != sizeof(struct OnDemandBlock)) |
292 | { | 293 | { |
293 | GNUNET_break(0); | 294 | GNUNET_break (0); |
294 | GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); | 295 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); |
295 | return GNUNET_SYSERR; | 296 | return GNUNET_SYSERR; |
296 | } | 297 | } |
297 | odb = (const struct OnDemandBlock *)data; | 298 | odb = (const struct OnDemandBlock *) data; |
298 | off = GNUNET_ntohll(odb->offset); | 299 | off = GNUNET_ntohll (odb->offset); |
299 | ii = GNUNET_CONTAINER_multihashmap_get(ifm, &odb->file_id); | 300 | ii = GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id); |
300 | if (NULL == ii) | 301 | if (NULL == ii) |
301 | { | 302 | { |
302 | GNUNET_break(0); | 303 | GNUNET_break (0); |
303 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 304 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
304 | "Failed to find index %s\n", | 305 | "Failed to find index %s\n", |
305 | GNUNET_h2s(&odb->file_id)); | 306 | GNUNET_h2s (&odb->file_id)); |
306 | return GNUNET_SYSERR; | 307 | return GNUNET_SYSERR; |
307 | } | 308 | } |
308 | fn = ii->filename; | 309 | fn = ii->filename; |
309 | if ((NULL == fn) || (0 != access(fn, R_OK))) | 310 | if ((NULL == fn) || (0 != access (fn, R_OK))) |
310 | { | 311 | { |
311 | GNUNET_STATISTICS_update( | 312 | GNUNET_STATISTICS_update ( |
312 | GSF_stats, | 313 | GSF_stats, |
313 | gettext_noop("# index blocks removed: original file inaccessible"), | 314 | gettext_noop ("# index blocks removed: original file inaccessible"), |
314 | 1, | 315 | 1, |
315 | GNUNET_YES); | 316 | GNUNET_YES); |
316 | GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); | 317 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); |
317 | return GNUNET_SYSERR; | 318 | return GNUNET_SYSERR; |
318 | } | 319 | } |
319 | if ((NULL == (fh = GNUNET_DISK_file_open(fn, | 320 | if ((NULL == (fh = GNUNET_DISK_file_open (fn, |
320 | GNUNET_DISK_OPEN_READ, | 321 | GNUNET_DISK_OPEN_READ, |
321 | GNUNET_DISK_PERM_NONE))) || | 322 | GNUNET_DISK_PERM_NONE))) || |
322 | (off != GNUNET_DISK_file_seek(fh, off, GNUNET_DISK_SEEK_SET)) || | 323 | (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) || |
323 | (-1 == (nsize = GNUNET_DISK_file_read(fh, ndata, sizeof(ndata))))) | 324 | (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof(ndata))))) |
324 | { | 325 | { |
325 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 326 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
326 | _( | 327 | _ ( |
327 | "Could not access indexed file `%s' (%s) at offset %llu: %s\n"), | 328 | "Could not access indexed file `%s' (%s) at offset %llu: %s\n"), |
328 | GNUNET_h2s(&odb->file_id), | 329 | GNUNET_h2s (&odb->file_id), |
329 | fn, | 330 | fn, |
330 | (unsigned long long)off, | 331 | (unsigned long long) off, |
331 | (fn == NULL) ? _("not indexed") : strerror(errno)); | 332 | (fn == NULL) ? _ ("not indexed") : strerror (errno)); |
332 | if (fh != NULL) | 333 | if (fh != NULL) |
333 | GNUNET_DISK_file_close(fh); | 334 | GNUNET_DISK_file_close (fh); |
334 | GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); | 335 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); |
335 | return GNUNET_SYSERR; | 336 | return GNUNET_SYSERR; |
336 | } | 337 | } |
337 | GNUNET_DISK_file_close(fh); | 338 | GNUNET_DISK_file_close (fh); |
338 | GNUNET_CRYPTO_hash(ndata, nsize, &nkey); | 339 | GNUNET_CRYPTO_hash (ndata, nsize, &nkey); |
339 | GNUNET_CRYPTO_hash_to_aes_key(&nkey, &skey, &iv); | 340 | GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv); |
340 | GNUNET_CRYPTO_symmetric_encrypt(ndata, nsize, &skey, &iv, edata); | 341 | GNUNET_CRYPTO_symmetric_encrypt (ndata, nsize, &skey, &iv, edata); |
341 | GNUNET_CRYPTO_hash(edata, nsize, &query); | 342 | GNUNET_CRYPTO_hash (edata, nsize, &query); |
342 | if (0 != memcmp(&query, key, sizeof(struct GNUNET_HashCode))) | 343 | if (0 != memcmp (&query, key, sizeof(struct GNUNET_HashCode))) |
343 | { | 344 | { |
344 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 345 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
345 | _("Indexed file `%s' changed at offset %llu\n"), | 346 | _ ("Indexed file `%s' changed at offset %llu\n"), |
346 | fn, | 347 | fn, |
347 | (unsigned long long)off); | 348 | (unsigned long long) off); |
348 | GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); | 349 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); |
349 | return GNUNET_SYSERR; | 350 | return GNUNET_SYSERR; |
350 | } | 351 | } |
351 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
352 | "On-demand encoded block for query `%s'\n", | 353 | "On-demand encoded block for query `%s'\n", |
353 | GNUNET_h2s(key)); | 354 | GNUNET_h2s (key)); |
354 | cont(cont_cls, | 355 | cont (cont_cls, |
355 | key, | 356 | key, |
356 | nsize, | 357 | nsize, |
357 | edata, | 358 | edata, |
358 | GNUNET_BLOCK_TYPE_FS_DBLOCK, | 359 | GNUNET_BLOCK_TYPE_FS_DBLOCK, |
359 | priority, | 360 | priority, |
360 | anonymity, | 361 | anonymity, |
361 | replication, | 362 | replication, |
362 | expiration, | 363 | expiration, |
363 | uid); | 364 | uid); |
364 | return GNUNET_OK; | 365 | return GNUNET_OK; |
365 | } | 366 | } |
366 | 367 | ||
@@ -371,7 +372,7 @@ GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, | |||
371 | * @param mq message queue to send information to | 372 | * @param mq message queue to send information to |
372 | */ | 373 | */ |
373 | void | 374 | void |
374 | GNUNET_FS_indexing_send_list(struct GNUNET_MQ_Handle *mq) | 375 | GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq) |
375 | { | 376 | { |
376 | struct GNUNET_MQ_Envelope *env; | 377 | struct GNUNET_MQ_Envelope *env; |
377 | struct IndexInfoMessage *iim; | 378 | struct IndexInfoMessage *iim; |
@@ -381,23 +382,23 @@ GNUNET_FS_indexing_send_list(struct GNUNET_MQ_Handle *mq) | |||
381 | struct IndexInfo *pos; | 382 | struct IndexInfo *pos; |
382 | 383 | ||
383 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) | 384 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) |
385 | { | ||
386 | fn = pos->filename; | ||
387 | slen = strlen (fn) + 1; | ||
388 | if (slen + sizeof(struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE) | ||
384 | { | 389 | { |
385 | fn = pos->filename; | 390 | GNUNET_break (0); |
386 | slen = strlen(fn) + 1; | 391 | break; |
387 | if (slen + sizeof(struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE) | ||
388 | { | ||
389 | GNUNET_break(0); | ||
390 | break; | ||
391 | } | ||
392 | env = | ||
393 | GNUNET_MQ_msg_extra(iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); | ||
394 | iim->reserved = 0; | ||
395 | iim->file_id = pos->file_id; | ||
396 | GNUNET_memcpy(&iim[1], fn, slen); | ||
397 | GNUNET_MQ_send(mq, env); | ||
398 | } | 392 | } |
399 | env = GNUNET_MQ_msg(iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); | 393 | env = |
400 | GNUNET_MQ_send(mq, env); | 394 | GNUNET_MQ_msg_extra (iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); |
395 | iim->reserved = 0; | ||
396 | iim->file_id = pos->file_id; | ||
397 | GNUNET_memcpy (&iim[1], fn, slen); | ||
398 | GNUNET_MQ_send (mq, env); | ||
399 | } | ||
400 | env = GNUNET_MQ_msg (iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); | ||
401 | GNUNET_MQ_send (mq, env); | ||
401 | } | 402 | } |
402 | 403 | ||
403 | 404 | ||
@@ -408,23 +409,23 @@ GNUNET_FS_indexing_send_list(struct GNUNET_MQ_Handle *mq) | |||
408 | * @return #GNUNET_YES if the @a fid was found | 409 | * @return #GNUNET_YES if the @a fid was found |
409 | */ | 410 | */ |
410 | int | 411 | int |
411 | GNUNET_FS_indexing_do_unindex(const struct GNUNET_HashCode *fid) | 412 | GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid) |
412 | { | 413 | { |
413 | struct IndexInfo *pos; | 414 | struct IndexInfo *pos; |
414 | 415 | ||
415 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) | 416 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) |
417 | { | ||
418 | if (0 == memcmp (&pos->file_id, fid, sizeof(struct GNUNET_HashCode))) | ||
416 | { | 419 | { |
417 | if (0 == memcmp(&pos->file_id, fid, sizeof(struct GNUNET_HashCode))) | 420 | GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); |
418 | { | 421 | GNUNET_break ( |
419 | GNUNET_CONTAINER_DLL_remove(indexed_files_head, indexed_files_tail, pos); | 422 | GNUNET_OK == |
420 | GNUNET_break( | 423 | GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); |
421 | GNUNET_OK == | 424 | GNUNET_free (pos); |
422 | GNUNET_CONTAINER_multihashmap_remove(ifm, &pos->file_id, pos)); | 425 | write_index_list (); |
423 | GNUNET_free(pos); | 426 | return GNUNET_YES; |
424 | write_index_list(); | ||
425 | return GNUNET_YES; | ||
426 | } | ||
427 | } | 427 | } |
428 | } | ||
428 | return GNUNET_NO; | 429 | return GNUNET_NO; |
429 | } | 430 | } |
430 | 431 | ||
@@ -436,40 +437,40 @@ GNUNET_FS_indexing_do_unindex(const struct GNUNET_HashCode *fid) | |||
436 | * @param file_id hash identifier for @a filename | 437 | * @param file_id hash identifier for @a filename |
437 | */ | 438 | */ |
438 | void | 439 | void |
439 | GNUNET_FS_add_to_index(const char *filename, | 440 | GNUNET_FS_add_to_index (const char *filename, |
440 | const struct GNUNET_HashCode *file_id) | 441 | const struct GNUNET_HashCode *file_id) |
441 | { | 442 | { |
442 | struct IndexInfo *ii; | 443 | struct IndexInfo *ii; |
443 | size_t slen; | 444 | size_t slen; |
444 | 445 | ||
445 | ii = GNUNET_CONTAINER_multihashmap_get(ifm, file_id); | 446 | ii = GNUNET_CONTAINER_multihashmap_get (ifm, file_id); |
446 | if (NULL != ii) | 447 | if (NULL != ii) |
447 | { | 448 | { |
448 | GNUNET_log( | 449 | GNUNET_log ( |
449 | GNUNET_ERROR_TYPE_INFO, | 450 | GNUNET_ERROR_TYPE_INFO, |
450 | _( | 451 | _ ( |
451 | "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), | 452 | "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), |
452 | filename, | 453 | filename, |
453 | ii->filename); | 454 | ii->filename); |
454 | return; | 455 | return; |
455 | } | 456 | } |
456 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
457 | "Adding file %s to index as %s\n", | 458 | "Adding file %s to index as %s\n", |
458 | filename, | 459 | filename, |
459 | GNUNET_h2s(file_id)); | 460 | GNUNET_h2s (file_id)); |
460 | slen = strlen(filename) + 1; | 461 | slen = strlen (filename) + 1; |
461 | ii = GNUNET_malloc(sizeof(struct IndexInfo) + slen); | 462 | ii = GNUNET_malloc (sizeof(struct IndexInfo) + slen); |
462 | ii->file_id = *file_id; | 463 | ii->file_id = *file_id; |
463 | ii->filename = (const char *)&ii[1]; | 464 | ii->filename = (const char *) &ii[1]; |
464 | GNUNET_memcpy(&ii[1], filename, slen); | 465 | GNUNET_memcpy (&ii[1], filename, slen); |
465 | GNUNET_CONTAINER_DLL_insert(indexed_files_head, indexed_files_tail, ii); | 466 | GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, ii); |
466 | GNUNET_assert(GNUNET_OK == | 467 | GNUNET_assert (GNUNET_OK == |
467 | GNUNET_CONTAINER_multihashmap_put( | 468 | GNUNET_CONTAINER_multihashmap_put ( |
468 | ifm, | 469 | ifm, |
469 | &ii->file_id, | 470 | &ii->file_id, |
470 | ii, | 471 | ii, |
471 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 472 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
472 | write_index_list(); | 473 | write_index_list (); |
473 | } | 474 | } |
474 | 475 | ||
475 | 476 | ||
@@ -477,21 +478,21 @@ GNUNET_FS_add_to_index(const char *filename, | |||
477 | * Shutdown the module. | 478 | * Shutdown the module. |
478 | */ | 479 | */ |
479 | void | 480 | void |
480 | GNUNET_FS_indexing_done() | 481 | GNUNET_FS_indexing_done () |
481 | { | 482 | { |
482 | struct IndexInfo *pos; | 483 | struct IndexInfo *pos; |
483 | 484 | ||
484 | while (NULL != (pos = indexed_files_head)) | 485 | while (NULL != (pos = indexed_files_head)) |
485 | { | 486 | { |
486 | GNUNET_CONTAINER_DLL_remove(indexed_files_head, indexed_files_tail, pos); | 487 | GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); |
487 | if (pos->fhc != NULL) | 488 | if (pos->fhc != NULL) |
488 | GNUNET_CRYPTO_hash_file_cancel(pos->fhc); | 489 | GNUNET_CRYPTO_hash_file_cancel (pos->fhc); |
489 | GNUNET_break( | 490 | GNUNET_break ( |
490 | GNUNET_OK == | 491 | GNUNET_OK == |
491 | GNUNET_CONTAINER_multihashmap_remove(ifm, &pos->file_id, pos)); | 492 | GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); |
492 | GNUNET_free(pos); | 493 | GNUNET_free (pos); |
493 | } | 494 | } |
494 | GNUNET_CONTAINER_multihashmap_destroy(ifm); | 495 | GNUNET_CONTAINER_multihashmap_destroy (ifm); |
495 | ifm = NULL; | 496 | ifm = NULL; |
496 | cfg = NULL; | 497 | cfg = NULL; |
497 | } | 498 | } |
@@ -504,13 +505,13 @@ GNUNET_FS_indexing_done() | |||
504 | * @param d datastore to use | 505 | * @param d datastore to use |
505 | */ | 506 | */ |
506 | int | 507 | int |
507 | GNUNET_FS_indexing_init(const struct GNUNET_CONFIGURATION_Handle *c, | 508 | GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, |
508 | struct GNUNET_DATASTORE_Handle *d) | 509 | struct GNUNET_DATASTORE_Handle *d) |
509 | { | 510 | { |
510 | cfg = c; | 511 | cfg = c; |
511 | dsh = d; | 512 | dsh = d; |
512 | ifm = GNUNET_CONTAINER_multihashmap_create(128, GNUNET_YES); | 513 | ifm = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES); |
513 | read_index_list(); | 514 | read_index_list (); |
514 | return GNUNET_OK; | 515 | return GNUNET_OK; |
515 | } | 516 | } |
516 | 517 | ||