aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs_indexing.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/fs/gnunet-service-fs_indexing.c
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/fs/gnunet-service-fs_indexing.c')
-rw-r--r--src/fs/gnunet-service-fs_indexing.c659
1 files changed, 296 insertions, 363 deletions
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c
index f92997f49..4bf02adb0 100644
--- a/src/fs/gnunet-service-fs_indexing.c
+++ b/src/fs/gnunet-service-fs_indexing.c
@@ -41,7 +41,7 @@
41 */ 41 */
42struct IndexInfo 42struct IndexInfo
43{ 43{
44 44
45 /** 45 /**
46 * This is a linked list. 46 * This is a linked list.
47 */ 47 */
@@ -63,7 +63,7 @@ struct IndexInfo
63 * Context for hashing of the file. 63 * Context for hashing of the file.
64 */ 64 */
65 struct GNUNET_CRYPTO_FileHashContext *fhc; 65 struct GNUNET_CRYPTO_FileHashContext *fhc;
66 66
67 /** 67 /**
68 * Hash of the contents of the file. 68 * Hash of the contents of the file.
69 */ 69 */
@@ -98,57 +98,48 @@ static struct GNUNET_DATASTORE_Handle *dsh;
98 98
99/** 99/**
100 * Write the current index information list to disk. 100 * Write the current index information list to disk.
101 */ 101 */
102static void 102static void
103write_index_list () 103write_index_list ()
104{ 104{
105 struct GNUNET_BIO_WriteHandle *wh; 105 struct GNUNET_BIO_WriteHandle *wh;
106 char *fn; 106 char *fn;
107 struct IndexInfo *pos; 107 struct IndexInfo *pos;
108 108
109 if (GNUNET_OK != 109 if (GNUNET_OK !=
110 GNUNET_CONFIGURATION_get_value_filename (cfg, 110 GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
111 "FS", 111 {
112 "INDEXDB", 112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
113 &fn)) 113 _("Configuration option `%s' in section `%s' missing.\n"),
114 { 114 "INDEXDB", "FS");
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 115 return;
116 _("Configuration option `%s' in section `%s' missing.\n"), 116 }
117 "INDEXDB",
118 "FS");
119 return;
120 }
121 wh = GNUNET_BIO_write_open (fn); 117 wh = GNUNET_BIO_write_open (fn);
122 if (NULL == wh) 118 if (NULL == wh)
123 { 119 {
124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
125 _("Could not open `%s'.\n"), 121 _("Could not open `%s'.\n"), fn);
126 fn); 122 GNUNET_free (fn);
127 GNUNET_free (fn); 123 return;
128 return; 124 }
129 }
130 pos = indexed_files; 125 pos = indexed_files;
131 while (pos != NULL) 126 while (pos != NULL)
132 { 127 {
133 if ( (GNUNET_OK != 128 if ((GNUNET_OK !=
134 GNUNET_BIO_write (wh, 129 GNUNET_BIO_write (wh,
135 &pos->file_id, 130 &pos->file_id,
136 sizeof (GNUNET_HashCode))) || 131 sizeof (GNUNET_HashCode))) ||
137 (GNUNET_OK != 132 (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename)))
138 GNUNET_BIO_write_string (wh, 133 break;
139 pos->filename)) ) 134 pos = pos->next;
140 break; 135 }
141 pos = pos->next; 136 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
142 } 137 {
143 if (GNUNET_OK != 138 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
144 GNUNET_BIO_write_close (wh)) 139 _("Error writing `%s'.\n"), fn);
145 { 140 GNUNET_free (fn);
146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 141 return;
147 _("Error writing `%s'.\n"), 142 }
148 fn);
149 GNUNET_free (fn);
150 return;
151 }
152 GNUNET_free (fn); 143 GNUNET_free (fn);
153} 144}
154 145
@@ -161,73 +152,65 @@ read_index_list ()
161{ 152{
162 struct GNUNET_BIO_ReadHandle *rh; 153 struct GNUNET_BIO_ReadHandle *rh;
163 char *fn; 154 char *fn;
164 struct IndexInfo *pos; 155 struct IndexInfo *pos;
165 char *fname; 156 char *fname;
166 GNUNET_HashCode hc; 157 GNUNET_HashCode hc;
167 size_t slen; 158 size_t slen;
168 char *emsg; 159 char *emsg;
169 160
170 if (GNUNET_OK != 161 if (GNUNET_OK !=
171 GNUNET_CONFIGURATION_get_value_filename (cfg, 162 GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
172 "FS", 163 {
173 "INDEXDB", 164 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
174 &fn)) 165 _("Configuration option `%s' in section `%s' missing.\n"),
175 { 166 "INDEXDB", "FS");
176 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 167 return;
177 _("Configuration option `%s' in section `%s' missing.\n"), 168 }
178 "INDEXDB",
179 "FS");
180 return;
181 }
182 if (GNUNET_NO == GNUNET_DISK_file_test (fn)) 169 if (GNUNET_NO == GNUNET_DISK_file_test (fn))
183 { 170 {
184 /* no index info yet */ 171 /* no index info yet */
185 GNUNET_free (fn); 172 GNUNET_free (fn);
186 return; 173 return;
187 } 174 }
188 rh = GNUNET_BIO_read_open (fn); 175 rh = GNUNET_BIO_read_open (fn);
189 if (NULL == rh) 176 if (NULL == rh)
177 {
178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
179 _("Could not open `%s'.\n"), fn);
180 GNUNET_free (fn);
181 return;
182 }
183 while ((GNUNET_OK ==
184 GNUNET_BIO_read (rh,
185 "Hash of indexed file",
186 &hc,
187 sizeof (GNUNET_HashCode))) &&
188 (GNUNET_OK ==
189 GNUNET_BIO_read_string (rh,
190 "Name of indexed file",
191 &fname, 1024 * 16)) && (fname != NULL))
192 {
193 slen = strlen (fname) + 1;
194 pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
195 pos->file_id = hc;
196 pos->filename = (const char *) &pos[1];
197 memcpy (&pos[1], fname, slen);
198 if (GNUNET_SYSERR ==
199 GNUNET_CONTAINER_multihashmap_put (ifm,
200 &hc,
201 (void *) pos->filename,
202 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
190 { 203 {
191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 204 GNUNET_free (pos);
192 _("Could not open `%s'.\n"),
193 fn);
194 GNUNET_free (fn);
195 return;
196 } 205 }
197 while ( (GNUNET_OK == 206 else
198 GNUNET_BIO_read (rh,
199 "Hash of indexed file",
200 &hc,
201 sizeof (GNUNET_HashCode))) &&
202 (GNUNET_OK ==
203 GNUNET_BIO_read_string (rh,
204 "Name of indexed file",
205 &fname,
206 1024 * 16)) &&
207 (fname != NULL) )
208 { 207 {
209 slen = strlen (fname) + 1; 208 pos->next = indexed_files;
210 pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen); 209 indexed_files = pos;
211 pos->file_id = hc;
212 pos->filename = (const char *) &pos[1];
213 memcpy (&pos[1], fname, slen);
214 if (GNUNET_SYSERR ==
215 GNUNET_CONTAINER_multihashmap_put (ifm,
216 &hc,
217 (void*) pos->filename,
218 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
219 {
220 GNUNET_free (pos);
221 }
222 else
223 {
224 pos->next = indexed_files;
225 indexed_files = pos;
226 }
227 GNUNET_free (fname);
228 } 210 }
229 if (GNUNET_OK != 211 GNUNET_free (fname);
230 GNUNET_BIO_read_close (rh, &emsg)) 212 }
213 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
231 GNUNET_free (emsg); 214 GNUNET_free (emsg);
232 GNUNET_free (fn); 215 GNUNET_free (fn);
233} 216}
@@ -244,31 +227,29 @@ signal_index_ok (struct IndexInfo *ii)
244{ 227{
245 if (GNUNET_SYSERR == 228 if (GNUNET_SYSERR ==
246 GNUNET_CONTAINER_multihashmap_put (ifm, 229 GNUNET_CONTAINER_multihashmap_put (ifm,
247 &ii->file_id, 230 &ii->file_id,
248 (void*) ii->filename, 231 (void *) ii->filename,
249 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 232 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
250 { 233 {
251 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 234 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
252 _("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), 235 _
253 ii->filename, 236 ("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
254 (const char*) GNUNET_CONTAINER_multihashmap_get (ifm, 237 ii->filename,
255 &ii->file_id)); 238 (const char *) GNUNET_CONTAINER_multihashmap_get (ifm,
256 GNUNET_SERVER_transmit_context_append_data (ii->tc, 239 &ii->file_id));
257 NULL, 0, 240 GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
258 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); 241 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
259 GNUNET_SERVER_transmit_context_run (ii->tc, 242 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
260 GNUNET_TIME_UNIT_MINUTES); 243 GNUNET_free (ii);
261 GNUNET_free (ii); 244 return;
262 return; 245 }
263 }
264 ii->next = indexed_files; 246 ii->next = indexed_files;
265 indexed_files = ii; 247 indexed_files = ii;
266 write_index_list (); 248 write_index_list ();
267 GNUNET_SERVER_transmit_context_append_data (ii->tc, 249 GNUNET_SERVER_transmit_context_append_data (ii->tc,
268 NULL, 0, 250 NULL, 0,
269 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); 251 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
270 GNUNET_SERVER_transmit_context_run (ii->tc, 252 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
271 GNUNET_TIME_UNIT_MINUTES);
272 ii->tc = NULL; 253 ii->tc = NULL;
273} 254}
274 255
@@ -280,36 +261,30 @@ signal_index_ok (struct IndexInfo *ii)
280 * @param cls closure, our publishing context 261 * @param cls closure, our publishing context
281 * @param res resulting hash, NULL on error 262 * @param res resulting hash, NULL on error
282 */ 263 */
283static void 264static void
284hash_for_index_val (void *cls, 265hash_for_index_val (void *cls, const GNUNET_HashCode * res)
285 const GNUNET_HashCode *
286 res)
287{ 266{
288 struct IndexInfo *ii = cls; 267 struct IndexInfo *ii = cls;
289 268
290 ii->fhc = NULL; 269 ii->fhc = NULL;
291 if ( (res == NULL) || 270 if ((res == NULL) ||
292 (0 != memcmp (res, 271 (0 != memcmp (res, &ii->file_id, sizeof (GNUNET_HashCode))))
293 &ii->file_id, 272 {
294 sizeof(GNUNET_HashCode))) ) 273 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
295 { 274 _
296 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 275 ("Hash mismatch trying to index file `%s' which has hash `%s'\n"),
297 _("Hash mismatch trying to index file `%s' which has hash `%s'\n"), 276 ii->filename, GNUNET_h2s (res));
298 ii->filename,
299 GNUNET_h2s (res));
300#if DEBUG_FS 277#if DEBUG_FS
301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
302 "Wanted `%s'\n", 279 "Wanted `%s'\n", GNUNET_h2s (&ii->file_id));
303 GNUNET_h2s (&ii->file_id));
304#endif 280#endif
305 GNUNET_SERVER_transmit_context_append_data (ii->tc, 281 GNUNET_SERVER_transmit_context_append_data (ii->tc,
306 NULL, 0, 282 NULL, 0,
307 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); 283 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
308 GNUNET_SERVER_transmit_context_run (ii->tc, 284 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
309 GNUNET_TIME_UNIT_MINUTES); 285 GNUNET_free (ii);
310 GNUNET_free (ii); 286 return;
311 return; 287 }
312 }
313 signal_index_ok (ii); 288 signal_index_ok (ii);
314} 289}
315 290
@@ -323,8 +298,8 @@ hash_for_index_val (void *cls,
323 */ 298 */
324void 299void
325GNUNET_FS_handle_index_start (void *cls, 300GNUNET_FS_handle_index_start (void *cls,
326 struct GNUNET_SERVER_Client *client, 301 struct GNUNET_SERVER_Client *client,
327 const struct GNUNET_MessageHeader *message) 302 const struct GNUNET_MessageHeader *message)
328{ 303{
329 const struct IndexStartMessage *ism; 304 const struct IndexStartMessage *ism;
330 char *fn; 305 char *fn;
@@ -336,77 +311,70 @@ GNUNET_FS_handle_index_start (void *cls,
336 uint64_t mydev; 311 uint64_t mydev;
337 uint64_t myino; 312 uint64_t myino;
338 313
339 msize = ntohs(message->size); 314 msize = ntohs (message->size);
340 if ( (msize <= sizeof (struct IndexStartMessage)) || 315 if ((msize <= sizeof (struct IndexStartMessage)) ||
341 ( ((const char *)message)[msize-1] != '\0') ) 316 (((const char *) message)[msize - 1] != '\0'))
342 { 317 {
343 GNUNET_break (0); 318 GNUNET_break (0);
344 GNUNET_SERVER_receive_done (client, 319 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
345 GNUNET_SYSERR); 320 return;
346 return; 321 }
347 } 322 ism = (const struct IndexStartMessage *) message;
348 ism = (const struct IndexStartMessage*) message;
349 if (0 != ism->reserved) 323 if (0 != ism->reserved)
350 { 324 {
351 GNUNET_break (0); 325 GNUNET_break (0);
352 GNUNET_SERVER_receive_done (client, 326 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
353 GNUNET_SYSERR); 327 return;
354 return; 328 }
355 } 329 fn = GNUNET_STRINGS_filename_expand ((const char *) &ism[1]);
356 fn = GNUNET_STRINGS_filename_expand ((const char*) &ism[1]);
357 if (fn == NULL) 330 if (fn == NULL)
358 { 331 {
359 GNUNET_SERVER_receive_done (client, 332 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
360 GNUNET_SYSERR); 333 return;
361 return; 334 }
362 }
363 dev = GNUNET_ntohll (ism->device); 335 dev = GNUNET_ntohll (ism->device);
364 ino = GNUNET_ntohll (ism->inode); 336 ino = GNUNET_ntohll (ism->inode);
365 ism = (const struct IndexStartMessage*) message; 337 ism = (const struct IndexStartMessage *) message;
366 slen = strlen (fn) + 1; 338 slen = strlen (fn) + 1;
367 ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen); 339 ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
368 ii->filename = (const char*) &ii[1]; 340 ii->filename = (const char *) &ii[1];
369 memcpy (&ii[1], fn, slen); 341 memcpy (&ii[1], fn, slen);
370 ii->file_id = ism->file_id; 342 ii->file_id = ism->file_id;
371#if DEBUG_FS 343#if DEBUG_FS
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
373 "Received `%s' message for file `%s'\n", 345 "Received `%s' message for file `%s'\n",
374 "START_INDEX", 346 "START_INDEX", ii->filename);
375 ii->filename);
376#endif 347#endif
377 348
378 ii->tc = GNUNET_SERVER_transmit_context_create (client); 349 ii->tc = GNUNET_SERVER_transmit_context_create (client);
379 mydev = 0; 350 mydev = 0;
380 myino = 0; 351 myino = 0;
381 if ( ( (dev != 0) || 352 if (((dev != 0) ||
382 (ino != 0) ) && 353 (ino != 0)) &&
383 (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn, 354 (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn,
384 &mydev, 355 &mydev,
385 &myino)) && 356 &myino)) &&
386 ( (dev == mydev) && 357 ((dev == mydev) && (ino == myino)))
387 (ino == myino) ) ) 358 {
388 { 359 /* fast validation OK! */
389 /* fast validation OK! */ 360 signal_index_ok (ii);
390 signal_index_ok (ii); 361 GNUNET_free (fn);
391 GNUNET_free (fn); 362 return;
392 return; 363 }
393 }
394#if DEBUG_FS 364#if DEBUG_FS
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n", 366 "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n",
397 (unsigned long long) ino, 367 (unsigned long long) ino,
398 (unsigned long long) myino, 368 (unsigned long long) myino,
399 (unsigned int) dev, 369 (unsigned int) dev, (unsigned int) mydev);
400 (unsigned int) mydev);
401#endif 370#endif
402 /* slow validation, need to hash full file (again) */ 371 /* slow validation, need to hash full file (again) */
403 ii->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 372 ii->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
404 fn, 373 fn,
405 HASHING_BLOCKSIZE, 374 HASHING_BLOCKSIZE,
406 &hash_for_index_val, 375 &hash_for_index_val, ii);
407 ii); 376 if (ii->fhc == NULL)
408 if (ii->fhc == NULL) 377 hash_for_index_val (ii, NULL);
409 hash_for_index_val (ii, NULL);
410 GNUNET_free (fn); 378 GNUNET_free (fn);
411} 379}
412 380
@@ -420,8 +388,8 @@ GNUNET_FS_handle_index_start (void *cls,
420 */ 388 */
421void 389void
422GNUNET_FS_handle_index_list_get (void *cls, 390GNUNET_FS_handle_index_list_get (void *cls,
423 struct GNUNET_SERVER_Client *client, 391 struct GNUNET_SERVER_Client *client,
424 const struct GNUNET_MessageHeader *message) 392 const struct GNUNET_MessageHeader *message)
425{ 393{
426 struct GNUNET_SERVER_TransmitContext *tc; 394 struct GNUNET_SERVER_TransmitContext *tc;
427 struct IndexInfoMessage *iim; 395 struct IndexInfoMessage *iim;
@@ -431,31 +399,30 @@ GNUNET_FS_handle_index_list_get (void *cls,
431 struct IndexInfo *pos; 399 struct IndexInfo *pos;
432 400
433 tc = GNUNET_SERVER_transmit_context_create (client); 401 tc = GNUNET_SERVER_transmit_context_create (client);
434 iim = (struct IndexInfoMessage*) buf; 402 iim = (struct IndexInfoMessage *) buf;
435 pos = indexed_files; 403 pos = indexed_files;
436 while (NULL != pos) 404 while (NULL != pos)
405 {
406 fn = pos->filename;
407 slen = strlen (fn) + 1;
408 if (slen + sizeof (struct IndexInfoMessage) >=
409 GNUNET_SERVER_MAX_MESSAGE_SIZE)
437 { 410 {
438 fn = pos->filename; 411 GNUNET_break (0);
439 slen = strlen (fn) + 1; 412 break;
440 if (slen + sizeof (struct IndexInfoMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
441 {
442 GNUNET_break (0);
443 break;
444 }
445 iim->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
446 iim->header.size = htons (slen + sizeof (struct IndexInfoMessage));
447 iim->reserved = 0;
448 iim->file_id = pos->file_id;
449 memcpy (&iim[1], fn, slen);
450 GNUNET_SERVER_transmit_context_append_message (tc,
451 &iim->header);
452 pos = pos->next;
453 } 413 }
414 iim->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
415 iim->header.size = htons (slen + sizeof (struct IndexInfoMessage));
416 iim->reserved = 0;
417 iim->file_id = pos->file_id;
418 memcpy (&iim[1], fn, slen);
419 GNUNET_SERVER_transmit_context_append_message (tc, &iim->header);
420 pos = pos->next;
421 }
454 GNUNET_SERVER_transmit_context_append_data (tc, 422 GNUNET_SERVER_transmit_context_append_data (tc,
455 NULL, 0, 423 NULL, 0,
456 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); 424 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
457 GNUNET_SERVER_transmit_context_run (tc, 425 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES);
458 GNUNET_TIME_UNIT_MINUTES);
459} 426}
460 427
461 428
@@ -468,8 +435,8 @@ GNUNET_FS_handle_index_list_get (void *cls,
468 */ 435 */
469void 436void
470GNUNET_FS_handle_unindex (void *cls, 437GNUNET_FS_handle_unindex (void *cls,
471 struct GNUNET_SERVER_Client *client, 438 struct GNUNET_SERVER_Client *client,
472 const struct GNUNET_MessageHeader *message) 439 const struct GNUNET_MessageHeader *message)
473{ 440{
474 const struct UnindexMessage *um; 441 const struct UnindexMessage *um;
475 struct IndexInfo *pos; 442 struct IndexInfo *pos;
@@ -478,55 +445,51 @@ GNUNET_FS_handle_unindex (void *cls,
478 struct GNUNET_SERVER_TransmitContext *tc; 445 struct GNUNET_SERVER_TransmitContext *tc;
479 int found; 446 int found;
480 447
481 um = (const struct UnindexMessage*) message; 448 um = (const struct UnindexMessage *) message;
482 if (0 != um->reserved) 449 if (0 != um->reserved)
483 { 450 {
484 GNUNET_break (0); 451 GNUNET_break (0);
485 GNUNET_SERVER_receive_done (client, 452 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
486 GNUNET_SYSERR); 453 return;
487 return; 454 }
488 }
489 found = GNUNET_NO; 455 found = GNUNET_NO;
490 prev = NULL; 456 prev = NULL;
491 pos = indexed_files; 457 pos = indexed_files;
492 while (NULL != pos) 458 while (NULL != pos)
459 {
460 next = pos->next;
461 if (0 == memcmp (&pos->file_id, &um->file_id, sizeof (GNUNET_HashCode)))
493 { 462 {
494 next = pos->next; 463 if (prev == NULL)
495 if (0 == memcmp (&pos->file_id, 464 indexed_files = next;
496 &um->file_id,
497 sizeof (GNUNET_HashCode)))
498 {
499 if (prev == NULL)
500 indexed_files = next;
501 else
502 prev->next = next;
503 GNUNET_break (GNUNET_OK ==
504 GNUNET_CONTAINER_multihashmap_remove (ifm,
505 &pos->file_id,
506 (void*) pos->filename));
507 GNUNET_free (pos);
508 found = GNUNET_YES;
509 }
510 else 465 else
511 { 466 prev->next = next;
512 prev = pos; 467 GNUNET_break (GNUNET_OK ==
513 } 468 GNUNET_CONTAINER_multihashmap_remove (ifm,
514 pos = next; 469 &pos->file_id,
470 (void *)
471 pos->filename));
472 GNUNET_free (pos);
473 found = GNUNET_YES;
515 } 474 }
475 else
476 {
477 prev = pos;
478 }
479 pos = next;
480 }
516#if DEBUG_FS 481#if DEBUG_FS
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
518 "Client requested unindexing of file `%s': %s\n", 483 "Client requested unindexing of file `%s': %s\n",
519 GNUNET_h2s (&um->file_id), 484 GNUNET_h2s (&um->file_id), found ? "found" : "not found");
520 found ? "found" : "not found");
521#endif 485#endif
522 if (GNUNET_YES == found) 486 if (GNUNET_YES == found)
523 write_index_list (); 487 write_index_list ();
524 tc = GNUNET_SERVER_transmit_context_create (client); 488 tc = GNUNET_SERVER_transmit_context_create (client);
525 GNUNET_SERVER_transmit_context_append_data (tc, 489 GNUNET_SERVER_transmit_context_append_data (tc,
526 NULL, 0, 490 NULL, 0,
527 GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); 491 GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
528 GNUNET_SERVER_transmit_context_run (tc, 492 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES);
529 GNUNET_TIME_UNIT_MINUTES);
530} 493}
531 494
532 495
@@ -539,14 +502,11 @@ GNUNET_FS_handle_unindex (void *cls,
539 * @param msg error message 502 * @param msg error message
540 */ 503 */
541static void 504static void
542remove_cont (void *cls, 505remove_cont (void *cls, int success, const char *msg)
543 int success,
544 const char *msg)
545{ 506{
546 if (GNUNET_OK != success) 507 if (GNUNET_OK != success)
547 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 508 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
548 _("Failed to delete bogus block: %s\n"), 509 _("Failed to delete bogus block: %s\n"), msg);
549 msg);
550} 510}
551 511
552 512
@@ -571,15 +531,15 @@ remove_cont (void *cls,
571 */ 531 */
572int 532int
573GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, 533GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
574 uint32_t size, 534 uint32_t size,
575 const void *data, 535 const void *data,
576 enum GNUNET_BLOCK_Type type, 536 enum GNUNET_BLOCK_Type type,
577 uint32_t priority, 537 uint32_t priority,
578 uint32_t anonymity, 538 uint32_t anonymity,
579 struct GNUNET_TIME_Absolute 539 struct GNUNET_TIME_Absolute
580 expiration, uint64_t uid, 540 expiration, uint64_t uid,
581 GNUNET_DATASTORE_DatumProcessor cont, 541 GNUNET_DATASTORE_DatumProcessor cont,
582 void *cont_cls) 542 void *cont_cls)
583{ 543{
584 const struct OnDemandBlock *odb; 544 const struct OnDemandBlock *odb;
585 GNUNET_HashCode nkey; 545 GNUNET_HashCode nkey;
@@ -594,99 +554,72 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
594 uint64_t off; 554 uint64_t off;
595 555
596 if (size != sizeof (struct OnDemandBlock)) 556 if (size != sizeof (struct OnDemandBlock))
597 { 557 {
598 GNUNET_break (0); 558 GNUNET_break (0);
599 GNUNET_DATASTORE_remove (dsh, 559 GNUNET_DATASTORE_remove (dsh,
600 key, 560 key,
601 size, 561 size,
602 data, 562 data,
603 -1, -1, 563 -1, -1,
604 GNUNET_TIME_UNIT_FOREVER_REL, 564 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
605 &remove_cont, 565 return GNUNET_SYSERR;
606 NULL); 566 }
607 return GNUNET_SYSERR; 567 odb = (const struct OnDemandBlock *) data;
608 }
609 odb = (const struct OnDemandBlock*) data;
610 off = GNUNET_ntohll (odb->offset); 568 off = GNUNET_ntohll (odb->offset);
611 fn = (const char*) GNUNET_CONTAINER_multihashmap_get (ifm, 569 fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
612 &odb->file_id);
613 fh = NULL; 570 fh = NULL;
614 if ( (NULL == fn) || 571 if ((NULL == fn) ||
615 (NULL == (fh = GNUNET_DISK_file_open (fn, 572 (NULL == (fh = GNUNET_DISK_file_open (fn,
616 GNUNET_DISK_OPEN_READ, 573 GNUNET_DISK_OPEN_READ,
617 GNUNET_DISK_PERM_NONE))) || 574 GNUNET_DISK_PERM_NONE))) ||
618 (off != 575 (off !=
619 GNUNET_DISK_file_seek (fh, 576 GNUNET_DISK_file_seek (fh,
620 off, 577 off,
621 GNUNET_DISK_SEEK_SET)) || 578 GNUNET_DISK_SEEK_SET)) ||
622 (-1 == 579 (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata)))))
623 (nsize = GNUNET_DISK_file_read (fh, 580 {
624 ndata, 581 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
625 sizeof (ndata)))) ) 582 _
626 { 583 ("Could not access indexed file `%s' (%s) at offset %llu: %s\n"),
627 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 584 GNUNET_h2s (&odb->file_id), fn, (unsigned long long) off,
628 _("Could not access indexed file `%s' (%s) at offset %llu: %s\n"), 585 (fn == NULL) ? _("not indexed") : STRERROR (errno));
629 GNUNET_h2s (&odb->file_id), 586 if (fh != NULL)
630 fn, 587 GNUNET_DISK_file_close (fh);
631 (unsigned long long) off, 588 GNUNET_DATASTORE_remove (dsh,
632 (fn == NULL) ? _("not indexed") : STRERROR (errno)); 589 key,
633 if (fh != NULL) 590 size,
634 GNUNET_DISK_file_close (fh); 591 data,
635 GNUNET_DATASTORE_remove (dsh, 592 -1, -1,
636 key, 593 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
637 size, 594 return GNUNET_SYSERR;
638 data, 595 }
639 -1, -1,
640 GNUNET_TIME_UNIT_FOREVER_REL,
641 &remove_cont,
642 NULL);
643 return GNUNET_SYSERR;
644 }
645 GNUNET_DISK_file_close (fh); 596 GNUNET_DISK_file_close (fh);
646 GNUNET_CRYPTO_hash (ndata, 597 GNUNET_CRYPTO_hash (ndata, nsize, &nkey);
647 nsize,
648 &nkey);
649 GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv); 598 GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv);
650 GNUNET_CRYPTO_aes_encrypt (ndata, 599 GNUNET_CRYPTO_aes_encrypt (ndata, nsize, &skey, &iv, edata);
651 nsize, 600 GNUNET_CRYPTO_hash (edata, nsize, &query);
652 &skey, 601 if (0 != memcmp (&query, key, sizeof (GNUNET_HashCode)))
653 &iv, 602 {
654 edata); 603 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
655 GNUNET_CRYPTO_hash (edata, 604 _("Indexed file `%s' changed at offset %llu\n"),
656 nsize, 605 fn, (unsigned long long) off);
657 &query); 606 GNUNET_DATASTORE_remove (dsh,
658 if (0 != memcmp (&query, 607 key,
659 key, 608 size,
660 sizeof (GNUNET_HashCode))) 609 data,
661 { 610 -1, -1,
662 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 611 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
663 _("Indexed file `%s' changed at offset %llu\n"), 612 return GNUNET_SYSERR;
664 fn, 613 }
665 (unsigned long long) off);
666 GNUNET_DATASTORE_remove (dsh,
667 key,
668 size,
669 data,
670 -1, -1,
671 GNUNET_TIME_UNIT_FOREVER_REL,
672 &remove_cont,
673 NULL);
674 return GNUNET_SYSERR;
675 }
676#if DEBUG_FS 614#if DEBUG_FS
677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
678 "On-demand encoded block for query `%s'\n", 616 "On-demand encoded block for query `%s'\n", GNUNET_h2s (key));
679 GNUNET_h2s (key)); 617#endif
680#endif
681 cont (cont_cls, 618 cont (cont_cls,
682 key, 619 key,
683 nsize, 620 nsize,
684 edata, 621 edata,
685 GNUNET_BLOCK_TYPE_FS_DBLOCK, 622 GNUNET_BLOCK_TYPE_FS_DBLOCK, priority, anonymity, expiration, uid);
686 priority,
687 anonymity,
688 expiration,
689 uid);
690 return GNUNET_OK; 623 return GNUNET_OK;
691} 624}
692 625
@@ -697,17 +630,17 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
697void 630void
698GNUNET_FS_indexing_done () 631GNUNET_FS_indexing_done ()
699{ 632{
700 struct IndexInfo *pos; 633 struct IndexInfo *pos;
701 634
702 GNUNET_CONTAINER_multihashmap_destroy (ifm); 635 GNUNET_CONTAINER_multihashmap_destroy (ifm);
703 ifm = NULL; 636 ifm = NULL;
704 while (NULL != (pos = indexed_files)) 637 while (NULL != (pos = indexed_files))
705 { 638 {
706 indexed_files = pos->next; 639 indexed_files = pos->next;
707 if (pos->fhc != NULL) 640 if (pos->fhc != NULL)
708 GNUNET_CRYPTO_hash_file_cancel (pos->fhc); 641 GNUNET_CRYPTO_hash_file_cancel (pos->fhc);
709 GNUNET_free (pos); 642 GNUNET_free (pos);
710 } 643 }
711 cfg = NULL; 644 cfg = NULL;
712} 645}
713 646
@@ -720,7 +653,7 @@ GNUNET_FS_indexing_done ()
720 */ 653 */
721int 654int
722GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, 655GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c,
723 struct GNUNET_DATASTORE_Handle *d) 656 struct GNUNET_DATASTORE_Handle *d)
724{ 657{
725 cfg = c; 658 cfg = c;
726 dsh = d; 659 dsh = d;