aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-auto-share.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-18 09:22:42 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-18 09:22:42 +0000
commit0115176c8a7b78096db7cc3cb020422409e34bf8 (patch)
tree68ec06f067491deca460fa0c904b71c62fff59d5 /src/fs/gnunet-auto-share.c
parent3bea1b11de57b46ba7a5b360b7c8e5dc0565edbb (diff)
downloadgnunet-0115176c8a7b78096db7cc3cb020422409e34bf8.tar.gz
gnunet-0115176c8a7b78096db7cc3cb020422409e34bf8.zip
-implementing 'determine_id'
Diffstat (limited to 'src/fs/gnunet-auto-share.c')
-rw-r--r--src/fs/gnunet-auto-share.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c
index 01c48aab0..8436e8442 100644
--- a/src/fs/gnunet-auto-share.c
+++ b/src/fs/gnunet-auto-share.c
@@ -224,15 +224,45 @@ work (void *cls,
224 * Recursively scan the given file/directory structure to determine 224 * Recursively scan the given file/directory structure to determine
225 * a unique ID that represents the current state of the hierarchy. 225 * a unique ID that represents the current state of the hierarchy.
226 * 226 *
227 * @param cls where to store the unique ID we are computing
227 * @param filename file to scan 228 * @param filename file to scan
228 * @param id where to store the unique ID we computed 229 * @return GNUNET_OK (always)
229 */ 230 */
230static void 231static int
231determine_id (const char *filename, 232determine_id (void *cls,
232 struct GNUNET_HashCode *id) 233 const char *filename)
233{ 234{
234 // FIXME: implement! 235 struct GNUNET_HashCode *id = cls;
235 GNUNET_break (0); 236 struct stat sbuf;
237 struct GNUNET_HashCode fx[2];
238 struct GNUNET_HashCode ft;
239
240 if (0 != STAT (filename, &sbuf))
241 {
242 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
243 return GNUNET_OK;
244 }
245 GNUNET_CRYPTO_hash (filename, strlen (filename), &fx[0]);
246 if (!S_ISDIR (sbuf.st_mode))
247 {
248 uint64_t fsize = GNUNET_htonll (sbuf.st_size);
249
250 GNUNET_CRYPTO_hash (&fsize, sizeof (uint64_t), &fx[1]);
251 }
252 else
253 {
254 memset (&fx[1], 1, sizeof (struct GNUNET_HashCode));
255 GNUNET_DISK_directory_scan (filename,
256 &determine_id,
257 &fx[1]);
258 }
259 /* use hash here to make hierarchical structure distinct from
260 all files on the same level */
261 GNUNET_CRYPTO_hash (fx, sizeof (fx), &ft);
262 /* use XOR here so that order of the files in the directory
263 does not matter! */
264 GNUNET_CRYPTO_hash_xor (&ft, id, id);
265 return GNUNET_OK;
236} 266}
237 267
238 268
@@ -261,7 +291,7 @@ add_file (void *cls,
261 wi = GNUNET_CONTAINER_multihashmap_get (work_finished, 291 wi = GNUNET_CONTAINER_multihashmap_get (work_finished,
262 &key); 292 &key);
263 memset (&id, 0, sizeof (struct GNUNET_HashCode)); 293 memset (&id, 0, sizeof (struct GNUNET_HashCode));
264 determine_id (filename, &id); 294 determine_id (&id, filename);
265 if (NULL != wi) 295 if (NULL != wi)
266 { 296 {
267 if (0 == memcmp (&id, 297 if (0 == memcmp (&id,