diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-09-02 19:20:51 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-09-02 19:20:51 +0000 |
commit | 8922e187c0d77dfa7cbd56440b10de5670d9d311 (patch) | |
tree | 6b75c230961271ddea8b11f7196c5d6b47a9ef71 /src/fs/fs_unindex.c | |
parent | 3e5a482b0e25536e3fff87b32ebf210adaf8b95a (diff) | |
download | gnunet-8922e187c0d77dfa7cbd56440b10de5670d9d311.tar.gz gnunet-8922e187c0d77dfa7cbd56440b10de5670d9d311.zip |
fixing fixmes
Diffstat (limited to 'src/fs/fs_unindex.c')
-rw-r--r-- | src/fs/fs_unindex.c | 131 |
1 files changed, 123 insertions, 8 deletions
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 | */ | ||
51 | static size_t | ||
52 | unindex_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 | */ | ||
94 | static void | ||
95 | unindex_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 | */ | ||
115 | static void | ||
116 | unindex_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 | */ |
46 | static void | 134 | static void |
47 | make_unindex_status (struct GNUNET_FS_ProgressInfo *pi, | 135 | make_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 | ||
175 | static void | ||
176 | unindex_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, |