From 4f64cda2fd1594d6fcb419707e652d0811111086 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 30 Aug 2009 19:24:21 +0000 Subject: [PATCH] clarification --- HACKING | 7 +++++ src/fs/fs.c | 1 + src/fs/fs.h | 15 ++++++---- src/fs/fs_directory.c | 28 ++++++++--------- src/fs/fs_publish.c | 70 +++++++++++++++++++++---------------------- 5 files changed, 67 insertions(+), 54 deletions(-) diff --git a/HACKING b/HACKING index 142f83315..5008b49ce 100644 --- a/HACKING +++ b/HACKING @@ -27,6 +27,13 @@ exported symbols: - must start with "GNUNET_modulename_" and be defined in "modulename.c" - exceptions: those defined in gnunet_common.h +private (library-internal) symbols (including structs & macros): +- must NOT start with any prefix +- must not be exported in a way that linkers could use them or + other libraries might see them via headers; they must be either + declared/defined in C source files or in headers that are in + the respective directory under src/modulename/ and NEVER be + declared in src/include/. testcases: - must be called "test_module-under-test_case-description.c" diff --git a/src/fs/fs.c b/src/fs/fs.c index 157f4ef22..66699507b 100644 --- a/src/fs/fs.c +++ b/src/fs/fs.c @@ -61,6 +61,7 @@ GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched, ret->upcb_cls = upcb_cls; ret->client = client; // FIXME: setup receive-loop with client + // FIXME: deserialize state; use client-name to find master-directory! // Deserialize-Upload: // * read FNs for upload FIs, deserialize each diff --git a/src/fs/fs.h b/src/fs/fs.h index f13619041..288903418 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h @@ -32,7 +32,7 @@ /** * Size of the individual blocks used for file-sharing. */ -#define GNUNET_FS_DBLOCK_SIZE (32*1024) +#define DBLOCK_SIZE (32*1024) /** @@ -42,14 +42,14 @@ * value is 32768 byte / 128 byte = 256 * (128 byte = 2 * 512 bits). DO NOT CHANGE! */ -#define GNUNET_FS_CHK_PER_INODE 256 +#define CHK_PER_INODE 256 /** * Maximum size for a file to be considered for * inlining in a directory. */ -#define GNUNET_FS_MAX_INLINE_SIZE 65536 +#define MAX_INLINE_SIZE 65536 @@ -509,7 +509,7 @@ struct GNUNET_FS_Namespace /** * @brief keyword block (advertising data under a keyword) */ -struct GNUNET_FS_KBlock +struct KBlock { /** @@ -536,7 +536,7 @@ struct GNUNET_FS_KBlock /** * @brief namespace content block (advertising data under an identifier in a namespace) */ -struct GNUNET_FS_SBlock +struct SBlock { /** @@ -571,6 +571,11 @@ struct GNUNET_FS_SBlock }; +struct IndexStartMessage +{ + +}; + #endif diff --git a/src/fs/fs_directory.c b/src/fs/fs_directory.c index be7c0d3e5..d67c6e8ef 100644 --- a/src/fs/fs_directory.c +++ b/src/fs/fs_directory.c @@ -173,11 +173,11 @@ GNUNET_FS_directory_list_contents (size_t size, /* URI is never empty, must be end of block, skip to next alignment */ align = - ((pos / GNUNET_FS_DBLOCK_SIZE) + 1) * GNUNET_FS_DBLOCK_SIZE; + ((pos / DBLOCK_SIZE) + 1) * DBLOCK_SIZE; if (align == pos) { /* if we were already aligned, still skip a block! */ - align += GNUNET_FS_DBLOCK_SIZE; + align += DBLOCK_SIZE; } pos = align; if (pos >= size) @@ -333,7 +333,7 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, fsize = GNUNET_FS_uri_chk_get_file_size (GNUNET_FS_uri_loc_get_uri (uri)); else fsize = 0; /* not given */ - if (fsize > GNUNET_FS_MAX_INLINE_SIZE) + if (fsize > MAX_INLINE_SIZE) fsize = 0; /* too large */ if (NULL != memchr (data, 0, fsize)) fsize = 0; /* must not have 0's in data! */ @@ -353,8 +353,8 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, mdxs = GNUNET_CONTAINER_meta_data_get_serialized_size (meta, GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); - if ( (slen + sizeof (uint32_t) + mdxs - 1) / GNUNET_FS_DBLOCK_SIZE == - (slen + sizeof (uint32_t) + mds - 1) / GNUNET_FS_DBLOCK_SIZE) + if ( (slen + sizeof (uint32_t) + mdxs - 1) / DBLOCK_SIZE == + (slen + sizeof (uint32_t) + mds - 1) / DBLOCK_SIZE) { /* adding full data would not cause us to cross additional blocks, so add it! */ @@ -392,7 +392,7 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, /** * Given the start and end position of a block of * data, return the end position of that data - * after alignment to the GNUNET_FS_DBLOCK_SIZE. + * after alignment to the DBLOCK_SIZE. */ static size_t do_align (size_t start_position, @@ -400,7 +400,7 @@ do_align (size_t start_position, { size_t align; - align = (end_position / GNUNET_FS_DBLOCK_SIZE) * GNUNET_FS_DBLOCK_SIZE; + align = (end_position / DBLOCK_SIZE) * DBLOCK_SIZE; if ((start_position < align) && (end_position > align)) return align + end_position - start_position; return end_position; @@ -442,28 +442,28 @@ block_align (size_t start, { cval = perm[j]; cend = cpos + sizes[cval]; - if (cpos % GNUNET_FS_DBLOCK_SIZE == 0) + if (cpos % DBLOCK_SIZE == 0) { /* prefer placing the largest blocks first */ - cbad = -(cend % GNUNET_FS_DBLOCK_SIZE); + cbad = -(cend % DBLOCK_SIZE); } else { - if (cpos / GNUNET_FS_DBLOCK_SIZE == - cend / GNUNET_FS_DBLOCK_SIZE) + if (cpos / DBLOCK_SIZE == + cend / DBLOCK_SIZE) { /* Data fits into the same block! Prefer small left-overs! */ cbad = - GNUNET_FS_DBLOCK_SIZE - cend % GNUNET_FS_DBLOCK_SIZE; + DBLOCK_SIZE - cend % DBLOCK_SIZE; } else { /* Would have to waste space to re-align, add big factor, this case is a real loss (proportional to space wasted)! */ cbad = - GNUNET_FS_DBLOCK_SIZE * (GNUNET_FS_DBLOCK_SIZE - + DBLOCK_SIZE * (DBLOCK_SIZE - cpos % - GNUNET_FS_DBLOCK_SIZE); + DBLOCK_SIZE); } } if (cbad < badness) diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 1445c98d5..91ca3240a 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c @@ -360,16 +360,16 @@ compute_depth (uint64_t flen) uint64_t fl; treeDepth = 1; - fl = GNUNET_FS_DBLOCK_SIZE; + fl = DBLOCK_SIZE; while (fl < flen) { treeDepth++; - if (fl * GNUNET_FS_CHK_PER_INODE < fl) + if (fl * CHK_PER_INODE < fl) { /* integer overflow, this is a HUGE file... */ return treeDepth; } - fl = fl * GNUNET_FS_CHK_PER_INODE; + fl = fl * CHK_PER_INODE; } return treeDepth; } @@ -393,20 +393,20 @@ compute_iblock_size (unsigned int height, uint64_t bds; GNUNET_assert (height > 0); - bds = GNUNET_FS_DBLOCK_SIZE; /* number of bytes each CHK at level "i" + bds = DBLOCK_SIZE; /* number of bytes each CHK at level "i" corresponds to */ for (i=0;idata.file.file_size < GNUNET_FS_MAX_INLINE_SIZE) && + if ( (dirpos->data.file.file_size < MAX_INLINE_SIZE) && (dirpos->data.file.file_size > 0) ) { raw_data = GNUNET_malloc (dirpos->data.file.file_size); @@ -524,21 +524,21 @@ publish_content (struct GNUNET_FS_PublishContext *sc, p->chk_tree_depth = compute_depth (size); p->chk_tree = GNUNET_malloc (p->chk_tree_depth * sizeof (struct ContentHashKey) * - GNUNET_FS_CHK_PER_INODE); + CHK_PER_INODE); p->current_depth = p->chk_tree_depth; } if (p->current_depth == p->chk_tree_depth) { if (p->is_directory) { - pt_size = GNUNET_MIN(GNUNET_FS_DBLOCK_SIZE, + pt_size = GNUNET_MIN(DBLOCK_SIZE, p->data.dir.dir_size - p->publish_offset); dd = p->data.dir.dir_data; pt_block = &dd[p->publish_offset]; } else { - pt_size = GNUNET_MIN(GNUNET_FS_DBLOCK_SIZE, + pt_size = GNUNET_MIN(DBLOCK_SIZE, p->data.file.file_size - p->publish_offset); emsg = NULL; if (pt_size != @@ -579,11 +579,11 @@ publish_content (struct GNUNET_FS_PublishContext *sc, pt_size = compute_iblock_size (p->chk_tree_depth - p->current_depth, p->publish_offset); pt_block = &p->chk_tree[p->current_depth * - GNUNET_FS_CHK_PER_INODE]; + CHK_PER_INODE]; } off = compute_chk_offset (p->chk_tree_depth - p->current_depth, p->publish_offset); - mychk = &p->chk_tree[(p->current_depth-1)*GNUNET_FS_CHK_PER_INODE+off]; + mychk = &p->chk_tree[(p->current_depth-1)*CHK_PER_INODE+off]; GNUNET_CRYPTO_hash (pt_block, pt_size, &mychk->key); GNUNET_CRYPTO_hash_to_aes_key (&mychk->key, &sk, &iv); GNUNET_CRYPTO_aes_encrypt (pt_block, @@ -645,12 +645,12 @@ publish_content (struct GNUNET_FS_PublishContext *sc, { p->publish_offset += pt_size; if ( (p->publish_offset == size) || - (0 == p->publish_offset % (GNUNET_FS_CHK_PER_INODE * GNUNET_FS_DBLOCK_SIZE) ) ) + (0 == p->publish_offset % (CHK_PER_INODE * DBLOCK_SIZE) ) ) p->current_depth--; } else { - if ( (off == GNUNET_FS_CHK_PER_INODE) || + if ( (off == CHK_PER_INODE) || (p->publish_offset == size) ) p->current_depth--; else @@ -951,13 +951,13 @@ struct PublishKskContext * (in plaintext), has "mdsize+slen" more * bytes than the struct would suggest. */ - struct GNUNET_FS_KBlock *kb; + struct KBlock *kb; /** * Buffer of the same size as "kb" for * the encrypted version. */ - struct GNUNET_FS_KBlock *cpy; + struct KBlock *cpy; /** * Handle to the datastore, NULL if we are just @@ -1114,7 +1114,7 @@ publish_ksk_cont (void *cls, 0, &query, pkc->mdsize + - sizeof (struct GNUNET_FS_KBlock) + + sizeof (struct KBlock) + pkc->slen, pkc->cpy, GNUNET_DATASTORE_BLOCKTYPE_KBLOCK, @@ -1181,11 +1181,11 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, GNUNET_assert (pkc->mdsize >= 0); uris = GNUNET_FS_uri_to_string (uri); pkc->slen = strlen (uris) + 1; - size = pkc->mdsize + sizeof (struct GNUNET_FS_KBlock) + pkc->slen; + size = pkc->mdsize + sizeof (struct KBlock) + pkc->slen; if (size > MAX_KBLOCK_SIZE) { size = MAX_KBLOCK_SIZE; - pkc->mdsize = size - sizeof (struct GNUNET_FS_KBlock) - pkc->slen; + pkc->mdsize = size - sizeof (struct KBlock) - pkc->slen; } pkc->kb = GNUNET_malloc (size); kbe = (char *) &pkc->kb[1]; @@ -1206,7 +1206,7 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, GNUNET_free (pkc); return; } - size = sizeof (struct GNUNET_FS_KBlock) + pkc->slen + pkc->mdsize; + size = sizeof (struct KBlock) + pkc->slen + pkc->mdsize; pkc->cpy = GNUNET_malloc (size); pkc->cpy->purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + @@ -1322,8 +1322,8 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, size_t nidlen; size_t idlen; ssize_t mdsize; - struct GNUNET_FS_SBlock *sb; - struct GNUNET_FS_SBlock *sb_enc; + struct SBlock *sb; + struct SBlock *sb_enc; char *dest; GNUNET_HashCode key; /* hash of thisId = key */ GNUNET_HashCode id; /* hash of hc = identifier */ @@ -1337,13 +1337,13 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta, GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); - size = sizeof (struct GNUNET_FS_SBlock) + slen + nidlen + mdsize; + size = sizeof (struct SBlock) + slen + nidlen + mdsize; if (size > MAX_SBLOCK_SIZE) { size = MAX_SBLOCK_SIZE; - mdsize = size - (sizeof (struct GNUNET_FS_SBlock) + slen + nidlen); + mdsize = size - (sizeof (struct SBlock) + slen + nidlen); } - sb = GNUNET_malloc (sizeof (struct GNUNET_FS_SBlock) + size); + sb = GNUNET_malloc (sizeof (struct SBlock) + size); dest = (char *) &sb[1]; memcpy (dest, update, nidlen); dest += nidlen; @@ -1363,8 +1363,8 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, _("Internal error.")); return; } - size = sizeof (struct GNUNET_FS_SBlock) + mdsize + slen + nidlen; - sb_enc = GNUNET_malloc (sizeof (struct GNUNET_FS_SBlock) + size); + size = sizeof (struct SBlock) + mdsize + slen + nidlen; + sb_enc = GNUNET_malloc (sizeof (struct SBlock) + size); GNUNET_CRYPTO_hash (identifier, idlen, &key); GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &id); sks_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); @@ -1379,14 +1379,14 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, &sb_enc->identifier); GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv); GNUNET_CRYPTO_aes_encrypt (&sb[1], - size - sizeof (struct GNUNET_FS_SBlock), + size - sizeof (struct SBlock), &sk, &iv, &sb_enc[1]); GNUNET_free (sb); sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK); sb_enc->purpose.size = htonl(slen + mdsize + nidlen - + sizeof(struct GNUNET_FS_SBlock) + + sizeof(struct SBlock) - sizeof(struct GNUNET_CRYPTO_RsaSignature)); GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_rsa_sign (namespace->key, -- 2.25.1