aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-09-02 19:20:51 +0000
committerChristian Grothoff <christian@grothoff.org>2009-09-02 19:20:51 +0000
commit8922e187c0d77dfa7cbd56440b10de5670d9d311 (patch)
tree6b75c230961271ddea8b11f7196c5d6b47a9ef71 /src
parent3e5a482b0e25536e3fff87b32ebf210adaf8b95a (diff)
downloadgnunet-8922e187c0d77dfa7cbd56440b10de5670d9d311.tar.gz
gnunet-8922e187c0d77dfa7cbd56440b10de5670d9d311.zip
fixing fixmes
Diffstat (limited to 'src')
-rw-r--r--src/fs/fs.h46
-rw-r--r--src/fs/fs_publish.c2
-rw-r--r--src/fs/fs_tree.h1
-rw-r--r--src/fs/fs_unindex.c131
4 files changed, 135 insertions, 45 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h
index c8712b492..7df395e86 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -238,19 +238,6 @@ struct GNUNET_FS_FileInformation
238 * (for operational persistence). 238 * (for operational persistence).
239 */ 239 */
240 char *serialization; 240 char *serialization;
241
242 /**
243 * In-memory cache of the current CHK tree.
244 * This struct will contain the CHK values
245 * from the root to the currently processed
246 * node in the tree as identified by
247 * "current_depth" and "publish_offset".
248 * The "chktree" will be initially NULL,
249 * then allocated to a sufficient number of
250 * entries for the size of the file and
251 * finally freed once the upload is complete.
252 */
253 // struct ContentHashKey *chk_tree;
254 241
255 /** 242 /**
256 * Encoder being used to publish this file. 243 * Encoder being used to publish this file.
@@ -262,24 +249,6 @@ struct GNUNET_FS_FileInformation
262 * failed). 249 * failed).
263 */ 250 */
264 char *emsg; 251 char *emsg;
265
266 /**
267 * Number of entries in "chk_tree".
268 */
269 // unsigned int chk_tree_depth;
270
271 /**
272 * Depth in the CHK-tree at which we are
273 * currently publishing. 0 is the root
274 * of the tree.
275 */
276 // unsigned int current_depth;
277
278 /**
279 * How many bytes of this file or directory have been
280 * published so far?
281 */
282 // uint64_t publish_offset;
283 252
284 /** 253 /**
285 * Data describing either the file or the directory. 254 * Data describing either the file or the directory.
@@ -580,14 +549,19 @@ struct GNUNET_FS_UnindexContext
580 void *client_info; 549 void *client_info;
581 550
582 /** 551 /**
583 * Overall size of the file. 552 * Merkle-ish tree encoder context.
584 */ 553 */
585 uint64_t file_size; 554 struct GNUNET_FS_TreeEncoder *tc;
586 555
587 /** 556 /**
588 * How far have we gotten? 557 * Handle used to read the file.
558 */
559 struct GNUNET_DISK_FileHandle *fh;
560
561 /**
562 * Overall size of the file.
589 */ 563 */
590 uint64_t unindex_offset; 564 uint64_t file_size;
591 565
592 /** 566 /**
593 * When did we start? 567 * When did we start?
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index 76f73fdc0..8417f6082 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -372,7 +372,7 @@ block_reader (void *cls,
372{ 372{
373 struct GNUNET_FS_PublishContext *sc = cls; 373 struct GNUNET_FS_PublishContext *sc = cls;
374 struct GNUNET_FS_FileInformation *p; 374 struct GNUNET_FS_FileInformation *p;
375 uint16_t pt_size; 375 size_t pt_size;
376 const char *dd; 376 const char *dd;
377 377
378 p = sc->fi_pos; 378 p = sc->fi_pos;
diff --git a/src/fs/fs_tree.h b/src/fs/fs_tree.h
index f24130a3c..47d383fb5 100644
--- a/src/fs/fs_tree.h
+++ b/src/fs/fs_tree.h
@@ -95,6 +95,7 @@ typedef void (*GNUNET_FS_TreeProgressCallback)(void *cls,
95 * @param proc function to call on each encrypted block 95 * @param proc function to call on each encrypted block
96 * @param progress function to call with progress information 96 * @param progress function to call with progress information
97 * @param cont function to call when done 97 * @param cont function to call when done
98 * @return tree encoder context
98 */ 99 */
99struct GNUNET_FS_TreeEncoder * 100struct GNUNET_FS_TreeEncoder *
100GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, 101GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h,
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index 9f1caac3a..1416667f3 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -32,8 +32,96 @@
32#include "gnunet_fs_service.h" 32#include "gnunet_fs_service.h"
33#include "gnunet_protocols.h" 33#include "gnunet_protocols.h"
34#include "fs.h" 34#include "fs.h"
35#include "fs_tree.h"
35 36
36 37
38/**
39 * Function called by the tree encoder to obtain
40 * a block of plaintext data (for the lowest level
41 * of the tree).
42 *
43 * @param cls our publishing context
44 * @param offset identifies which block to get
45 * @param max (maximum) number of bytes to get; returning
46 * fewer will also cause errors
47 * @param buf where to copy the plaintext buffer
48 * @param emsg location to store an error message (on error)
49 * @return number of bytes copied to buf, 0 on error
50 */
51static size_t
52unindex_reader (void *cls,
53 uint64_t offset,
54 size_t max,
55 void *buf,
56 char **emsg)
57{
58 struct GNUNET_FS_UnindexContext *uc = cls;
59 size_t pt_size;
60
61 pt_size = GNUNET_MIN(max,
62 uc->file_size - offset);
63 if (offset !=
64 GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET))
65 {
66 *emsg = GNUNET_strdup (_("Failed to find given position in file"));
67 return 0;
68 }
69 if (pt_size !=
70 GNUNET_DISK_file_read (uc->fh,
71 buf,
72 pt_size))
73 {
74 *emsg = GNUNET_strdup (_("Failed to read file"));
75 return 0;
76 }
77 return pt_size;
78}
79
80
81/**
82 * Function called asking for the current (encoded)
83 * block to be processed. After processing the
84 * client should either call "GNUNET_FS_tree_encode_next"
85 * or (on error) "GNUNET_FS_tree_encode_finish".
86 *
87 * @param cls closure
88 * @param query the query for the block (key for lookup in the datastore)
89 * @param offset offset of the block
90 * @param type type of the block (IBLOCK or DBLOCK)
91 * @param block the (encrypted) block
92 * @param block_size size of block (in bytes)
93 */
94static void
95unindex_process (void *cls,
96 const GNUNET_HashCode *query,
97 uint64_t offset,
98 unsigned int type,
99 const void *block,
100 uint16_t block_size)
101{
102}
103
104
105/**
106 * Function called with information about our
107 * progress in computing the tree encoding.
108 *
109 * @param cls closure
110 * @param offset where are we in the file
111 * @param pt_block plaintext of the currently processed block
112 * @param pt_size size of pt_block
113 * @param depth depth of the block in the tree
114 */
115static void
116unindex_progress (void *cls,
117 uint64_t offset,
118 const void *pt_block,
119 size_t pt_size,
120 unsigned int depth)
121{
122 // FIXME
123}
124
37 125
38 126
39/** 127/**
@@ -45,7 +133,8 @@
45 */ 133 */
46static void 134static void
47make_unindex_status (struct GNUNET_FS_ProgressInfo *pi, 135make_unindex_status (struct GNUNET_FS_ProgressInfo *pi,
48 struct GNUNET_FS_UnindexContext *uc) 136 struct GNUNET_FS_UnindexContext *uc,
137 uint64_t offset)
49{ 138{
50 pi->value.unindex.uc = uc; 139 pi->value.unindex.uc = uc;
51 pi->value.unindex.cctx = uc->client_info; 140 pi->value.unindex.cctx = uc->client_info;
@@ -53,10 +142,10 @@ make_unindex_status (struct GNUNET_FS_ProgressInfo *pi,
53 pi->value.unindex.size = uc->file_size; 142 pi->value.unindex.size = uc->file_size;
54 pi->value.unindex.eta 143 pi->value.unindex.eta
55 = GNUNET_TIME_calculate_eta (uc->start_time, 144 = GNUNET_TIME_calculate_eta (uc->start_time,
56 uc->unindex_offset, 145 offset,
57 uc->file_size); 146 uc->file_size);
58 pi->value.publish.duration = GNUNET_TIME_absolute_get_duration (uc->start_time); 147 pi->value.publish.duration = GNUNET_TIME_absolute_get_duration (uc->start_time);
59 pi->value.publish.completed = uc->unindex_offset; 148 pi->value.publish.completed = offset;
60} 149}
61 150
62 151
@@ -74,7 +163,7 @@ signal_unindex_error (struct GNUNET_FS_UnindexContext *uc,
74 struct GNUNET_FS_ProgressInfo pi; 163 struct GNUNET_FS_ProgressInfo pi;
75 164
76 pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR; 165 pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR;
77 make_unindex_status (&pi, uc); 166 make_unindex_status (&pi, uc, 0);
78 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; 167 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
79 pi.value.unindex.specifics.error.message = emsg; 168 pi.value.unindex.specifics.error.message = emsg;
80 uc->client_info 169 uc->client_info
@@ -83,6 +172,13 @@ signal_unindex_error (struct GNUNET_FS_UnindexContext *uc,
83} 172}
84 173
85 174
175static void
176unindex_finish (void *cls,
177 const struct GNUNET_SCHEDULER_TaskContext *tc)
178{
179}
180
181
86/** 182/**
87 * Function called with the response from the 183 * Function called with the response from the
88 * FS service to our unindexing request. 184 * FS service to our unindexing request.
@@ -127,8 +223,25 @@ process_fs_response (void *cls,
127 _("Failed to connect to `datastore' service.")); 223 _("Failed to connect to `datastore' service."));
128 return; 224 return;
129 } 225 }
130 226 uc->fh = GNUNET_DISK_file_open (uc->filename,
131 // FIXME: call shared code with publishing... 227 GNUNET_DISK_OPEN_READ);
228 if (NULL == uc->fh)
229 {
230 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
231 uc->dsh = NULL;
232 uc->state = UNINDEX_STATE_ERROR;
233 signal_unindex_error (uc,
234 _("Failed to open file for unindexing."));
235 return;
236 }
237 uc->tc = GNUNET_FS_tree_encoder_create (uc->h,
238 uc->file_size,
239 uc,
240 &unindex_reader,
241 &unindex_process,
242 &unindex_progress,
243 &unindex_finish);
244 GNUNET_FS_tree_encoder_next (uc->tc);
132} 245}
133 246
134 247
@@ -203,7 +316,7 @@ GNUNET_FS_unindex (struct GNUNET_FS_Handle *h,
203 316
204 // FIXME: make persistent! 317 // FIXME: make persistent!
205 pi.status = GNUNET_FS_STATUS_UNINDEX_START; 318 pi.status = GNUNET_FS_STATUS_UNINDEX_START;
206 make_unindex_status (&pi, ret); 319 make_unindex_status (&pi, ret, 0);
207 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; 320 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
208 ret->client_info 321 ret->client_info
209 = h->upcb (h->upcb_cls, 322 = h->upcb (h->upcb_cls,
@@ -236,8 +349,10 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc)
236 return; 349 return;
237 } 350 }
238 // FIXME: make unpersistent! 351 // FIXME: make unpersistent!
352 make_unindex_status (&pi, uc,
353 (uc->state == UNINDEX_STATE_COMPLETE)
354 ? uc->file_size : 0);
239 pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; 355 pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED;
240 make_unindex_status (&pi, uc);
241 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; 356 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
242 uc->client_info 357 uc->client_info
243 = uc->h->upcb (uc->h->upcb_cls, 358 = uc->h->upcb (uc->h->upcb_cls,