aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2018-06-28 19:17:26 -0400
committerFranklin Wei <me@fwei.tk>2018-06-28 19:17:26 -0400
commit3040965c03d9dc7b7762629d8b132716d4091f20 (patch)
tree74e7cb9577690a5808b454f3f3c861219a4960ee
parentcfa1e7cbf63c242abf6de27d631674a6623dffe2 (diff)
downloadcsaa-3040965c03d9dc7b7762629d8b132716d4091f20.zip
csaa-3040965c03d9dc7b7762629d8b132716d4091f20.tar.gz
csaa-3040965c03d9dc7b7762629d8b132716d4091f20.tar.bz2
csaa-3040965c03d9dc7b7762629d8b132716d4091f20.tar.xz
Keep IOMT in memory while initializing
-rw-r--r--iomt.c31
-rw-r--r--service_provider.c41
2 files changed, 48 insertions, 24 deletions
diff --git a/iomt.c b/iomt.c
index 8bf4cbd..1a92568 100644
--- a/iomt.c
+++ b/iomt.c
@@ -561,23 +561,32 @@ struct iomt *iomt_dup_in_db(void *db,
/* produces a new IOMT with no relation with the old one (no pointer
* semantics) */
-struct iomt *iomt_dup(const struct iomt *tree)
+struct iomt *iomt_dup(const struct iomt *oldtree)
{
- if(!tree)
+ if(!oldtree)
return NULL;
- if(!tree->in_memory)
- assert(false);
-
struct iomt *newtree = calloc(1, sizeof(struct iomt));
- newtree->mt_leafcount = tree->mt_leafcount;
- newtree->mt_logleaves = tree->mt_logleaves;
+ newtree->mt_leafcount = oldtree->mt_leafcount;
+ newtree->mt_logleaves = oldtree->mt_logleaves;
- newtree->mem.mt_leaves = calloc(tree->mt_leafcount, sizeof(struct iomt_node));
- memcpy(newtree->mem.mt_leaves, tree->mem.mt_leaves, tree->mt_leafcount * sizeof(struct iomt_node));
+ newtree->mem.mt_leaves = calloc(oldtree->mt_leafcount, sizeof(struct iomt_node));
+ newtree->mem.mt_nodes = calloc(2 * oldtree->mt_leafcount - 1, sizeof(hash_t));
- newtree->mem.mt_nodes = calloc(2 * tree->mt_leafcount - 1, sizeof(hash_t));
- memcpy(newtree->mem.mt_nodes, tree->mem.mt_nodes, (2 * tree->mt_leafcount - 1) * sizeof(hash_t));
+ if(oldtree->in_memory)
+ {
+ memcpy(newtree->mem.mt_leaves, oldtree->mem.mt_leaves, oldtree->mt_leafcount * sizeof(struct iomt_node));
+ memcpy(newtree->mem.mt_nodes, oldtree->mem.mt_nodes, (2 * oldtree->mt_leafcount - 1) * sizeof(hash_t));
+ }
+ else
+ {
+ /* copy nodes, leaves (we do not recalculate the tree) */
+ for(int i = 0; i < newtree->mt_leafcount; ++i)
+ iomt_setleaf(newtree, i, iomt_getleaf(oldtree, i));
+
+ for(int i = 0; i < 2 * newtree->mt_leafcount - 1; ++i)
+ iomt_setnode(newtree, i, iomt_getnode(oldtree, i));
+ }
return newtree;
}
diff --git a/service_provider.c b/service_provider.c
index c917387..852e208 100644
--- a/service_provider.c
+++ b/service_provider.c
@@ -218,18 +218,13 @@ struct service_provider *sp_new(const void *key, size_t keylen, int logleaves, c
sp->tm = tm_new(key, keylen);
- sp->iomt = iomt_new_from_db(sp->db,
- "FileNodes", "FileLeaves",
- NULL, 0,
- NULL, 0,
- logleaves);
-
- begin_transaction(sp->db);
+ /* create IOMT in memory first, then commit to DB */
+ sp->iomt = iomt_new(logleaves);
sp->data_dir = data_dir;
clock_t start = clock();
-
+
/* The trusted module initializes itself with a single placeholder
* node (1,0,1). We first update our list of IOMT leaves. Then we
* insert our desired number of nodes by using EQ certificates to
@@ -267,17 +262,37 @@ struct service_provider *sp_new(const void *key, size_t keylen, int logleaves, c
#endif
assert(tm_set_equiv_root(sp->tm, &eq, hmac));
- //printf("%d\n", i);
+ printf("%d\n", i);
}
+ /* now transfer to database */
+ printf("IOMT initialized in memory, transferring to DB...\n");
+
+ clock_t point1 = clock();
+
+ begin_transaction(sp->db);
+
+ /* we must do it this way because cert_eq expects sp->iomt to be
+ * the working tree */
+ struct iomt *old = sp->iomt;
+
+ sp->iomt = iomt_dup_in_db(sp->db,
+ "FileNodes", "FileLeaves",
+ NULL, 0,
+ NULL, 0,
+ old);
+
commit_transaction(sp->db);
+ iomt_free(old);
+
clock_t stop = clock();
- printf("sp_init(): logleaves=%d, time=%.1fsec, rate=%.1f/sec\n",
+ printf("sp_init(): logleaves=%d, time=%.1fsec, overall_rate=%.1f/sec, db_time=%.1fsec\n",
logleaves, (double)(stop - start) / CLOCKS_PER_SEC,
- (double)(1ULL << logleaves) * CLOCKS_PER_SEC / ( stop - start ));
-
+ (double)(1ULL << logleaves) * CLOCKS_PER_SEC / ( stop - start ),
+ (double)(stop - point1) / CLOCKS_PER_SEC);
+
return sp;
}
@@ -1178,7 +1193,7 @@ void sp_test(void)
clock_t start = clock();
struct service_provider *sp = sp_new("a", 1, logleaves, "files");
clock_t stop = clock();
-
+
check("Tree initialization", sp != NULL);
{