[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r24315 - gnunet/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r24315 - gnunet/src/fs |
Date: |
Sun, 14 Oct 2012 20:08:15 +0200 |
Author: grothoff
Date: 2012-10-14 20:08:15 +0200 (Sun, 14 Oct 2012)
New Revision: 24315
Modified:
gnunet/src/fs/gnunet-service-fs_indexing.c
gnunet/src/fs/gnunet-service-fs_pr.c
Log:
-use DLL, nicer use of indexing map, improve ability to use future hash map
memory optimization
Modified: gnunet/src/fs/gnunet-service-fs_indexing.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_indexing.c 2012-10-14 16:48:49 UTC (rev
24314)
+++ gnunet/src/fs/gnunet-service-fs_indexing.c 2012-10-14 18:08:15 UTC (rev
24315)
@@ -43,11 +43,16 @@
{
/**
- * This is a linked list.
+ * This is a doubly linked list.
*/
struct IndexInfo *next;
/**
+ * This is a doubly linked list.
+ */
+ struct IndexInfo *prev;
+
+ /**
* Name of the indexed file. Memory allocated
* at the end of this struct (do not free).
*/
@@ -73,12 +78,17 @@
/**
- * Linked list of indexed files.
+ * Head of linked list of indexed files.
*/
-static struct IndexInfo *indexed_files;
+static struct IndexInfo *indexed_files_head;
/**
- * Maps hash over content of indexed files to the respective filename.
+ * Tail of linked list of indexed files.
+ */
+static struct IndexInfo *indexed_files_tail;
+
+/**
+ * Maps hash over content of indexed files to the respective 'struct
IndexInfo'.
* The filenames are pointers into the indexed_files linked list and
* do not need to be freed.
*/
@@ -121,15 +131,11 @@
GNUNET_free (fn);
return;
}
- pos = indexed_files;
- while (pos != NULL)
- {
+ for (pos = indexed_files_head; NULL != pos; pos = pos->next)
if ((GNUNET_OK !=
GNUNET_BIO_write (wh, &pos->file_id, sizeof (struct
GNUNET_HashCode))) ||
(GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename)))
break;
- pos = pos->next;
- }
if (GNUNET_OK != GNUNET_BIO_write_close (wh))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
@@ -189,15 +195,16 @@
pos->filename = (const char *) &pos[1];
memcpy (&pos[1], fname, slen);
if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_put (ifm, &hc, (void *) pos->filename,
+ GNUNET_CONTAINER_multihashmap_put (ifm, &pos->file_id, pos,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
GNUNET_free (pos);
}
else
{
- pos->next = indexed_files;
- indexed_files = pos;
+ GNUNET_CONTAINER_DLL_insert (indexed_files_head,
+ indexed_files_tail,
+ pos);
}
GNUNET_free (fname);
}
@@ -216,25 +223,28 @@
static void
signal_index_ok (struct IndexInfo *ii)
{
+ struct IndexInfo *ir;
if (GNUNET_SYSERR ==
GNUNET_CONTAINER_multihashmap_put (ifm, &ii->file_id,
- (void *) ii->filename,
+ ii,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
+ ir = GNUNET_CONTAINER_multihashmap_get (ifm,
+ &ii->file_id);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_
("Index request received for file `%s' is already indexed as
`%s'. Permitting anyway.\n"),
ii->filename,
- (const char *) GNUNET_CONTAINER_multihashmap_get (ifm,
-
&ii->file_id));
+ ir->filename);
GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
GNUNET_free (ii);
return;
}
- ii->next = indexed_files;
- indexed_files = ii;
+ GNUNET_CONTAINER_DLL_insert (indexed_files_head,
+ indexed_files_tail,
+ ii);
write_index_list ();
GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
@@ -373,8 +383,7 @@
tc = GNUNET_SERVER_transmit_context_create (client);
iim = (struct IndexInfoMessage *) buf;
- pos = indexed_files;
- while (NULL != pos)
+ for (pos = indexed_files_head; NULL != pos; pos = pos->next)
{
fn = pos->filename;
slen = strlen (fn) + 1;
@@ -390,7 +399,6 @@
iim->file_id = pos->file_id;
memcpy (&iim[1], fn, slen);
GNUNET_SERVER_transmit_context_append_message (tc, &iim->header);
- pos = pos->next;
}
GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
@@ -411,8 +419,6 @@
{
const struct UnindexMessage *um;
struct IndexInfo *pos;
- struct IndexInfo *prev;
- struct IndexInfo *next;
struct GNUNET_SERVER_TransmitContext *tc;
int found;
@@ -424,29 +430,20 @@
return;
}
found = GNUNET_NO;
- prev = NULL;
- pos = indexed_files;
- while (NULL != pos)
+ for (pos = indexed_files_head; NULL != pos; pos = pos->next)
{
- next = pos->next;
if (0 == memcmp (&pos->file_id, &um->file_id, sizeof (struct
GNUNET_HashCode)))
{
- if (prev == NULL)
- indexed_files = next;
- else
- prev->next = next;
+ GNUNET_CONTAINER_DLL_remove (indexed_files_head,
+ indexed_files_tail,
+ pos);
GNUNET_break (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id,
- (void *)
- pos->filename));
+ pos));
GNUNET_free (pos);
found = GNUNET_YES;
+ break;
}
- else
- {
- prev = pos;
- }
- pos = next;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Client requested unindexing of file `%s': %s\n",
@@ -519,6 +516,7 @@
const char *fn;
struct GNUNET_DISK_FileHandle *fh;
uint64_t off;
+ struct IndexInfo *ii;
if (size != sizeof (struct OnDemandBlock))
{
@@ -529,7 +527,8 @@
}
odb = (const struct OnDemandBlock *) data;
off = GNUNET_ntohll (odb->offset);
- fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
+ ii = GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
+ fn = ii->filename;
if ((NULL == fn) || (0 != ACCESS (fn, R_OK)))
{
GNUNET_STATISTICS_update (GSF_stats,
@@ -588,15 +587,20 @@
{
struct IndexInfo *pos;
- GNUNET_CONTAINER_multihashmap_destroy (ifm);
- ifm = NULL;
- while (NULL != (pos = indexed_files))
+ while (NULL != (pos = indexed_files_head))
{
- indexed_files = pos->next;
+ GNUNET_CONTAINER_DLL_remove (indexed_files_head,
+ indexed_files_tail,
+ pos);
if (pos->fhc != NULL)
GNUNET_CRYPTO_hash_file_cancel (pos->fhc);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (ifm,
+ &pos->file_id, pos));
GNUNET_free (pos);
}
+ GNUNET_CONTAINER_multihashmap_destroy (ifm);
+ ifm = NULL;
cfg = NULL;
}
@@ -613,7 +617,7 @@
{
cfg = c;
dsh = d;
- ifm = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO);
+ ifm = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES);
read_index_list ();
return GNUNET_OK;
}
Modified: gnunet/src/fs/gnunet-service-fs_pr.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_pr.c 2012-10-14 16:48:49 UTC (rev
24314)
+++ gnunet/src/fs/gnunet-service-fs_pr.c 2012-10-14 18:08:15 UTC (rev
24315)
@@ -351,7 +351,8 @@
{
refresh_bloomfilter (pr);
}
- GNUNET_CONTAINER_multihashmap_put (pr_map, query, pr,
+ GNUNET_CONTAINER_multihashmap_put (pr_map,
+ &pr->public_data.query, pr,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
if (0 == (options & GSF_PRO_REQUEST_NEVER_EXPIRES))
{
@@ -1627,7 +1628,7 @@
active_to_migration =
GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_CACHING");
datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
- pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024, GNUNET_NO);
+ pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024, GNUNET_YES);
requests_by_expiration_heap =
GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r24315 - gnunet/src/fs,
gnunet <=