aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_hash_file.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
committerChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
commit95f9076a2139f5fb042b944a0658b6cda2fa35db (patch)
treeb0826a2a1dcf812e6b4450fe6b05d47cd53ae49d /src/util/crypto_hash_file.c
parent7746f68db77b9ca3c4aaca24ab2ce5253461240b (diff)
downloadgnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.tar.gz
gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.zip
implementing new scheduler shutdown semantics
Diffstat (limited to 'src/util/crypto_hash_file.c')
-rw-r--r--src/util/crypto_hash_file.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/util/crypto_hash_file.c b/src/util/crypto_hash_file.c
index f2d49d164..ace5212c9 100644
--- a/src/util/crypto_hash_file.c
+++ b/src/util/crypto_hash_file.c
@@ -130,9 +130,13 @@ file_hash_task (void *cls)
130 delta = fhc->bsize; 130 delta = fhc->bsize;
131 if (fhc->fsize - fhc->offset < delta) 131 if (fhc->fsize - fhc->offset < delta)
132 delta = fhc->fsize - fhc->offset; 132 delta = fhc->fsize - fhc->offset;
133 if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta)) 133 if (delta != GNUNET_DISK_file_read (fhc->fh,
134 fhc->buffer,
135 delta))
134 { 136 {
135 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename); 137 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
138 "read",
139 fhc->filename);
136 file_hash_finish (fhc, NULL); 140 file_hash_finish (fhc, NULL);
137 return; 141 return;
138 } 142 }
@@ -140,12 +144,14 @@ file_hash_task (void *cls)
140 fhc->offset += delta; 144 fhc->offset += delta;
141 if (fhc->offset == fhc->fsize) 145 if (fhc->offset == fhc->fsize)
142 { 146 {
143 res = (struct GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512); 147 res = (struct GNUNET_HashCode *) gcry_md_read (fhc->md,
148 GCRY_MD_SHA512);
144 file_hash_finish (fhc, res); 149 file_hash_finish (fhc, res);
145 return; 150 return;
146 } 151 }
147 fhc->task = GNUNET_SCHEDULER_add_with_priority (fhc->priority, 152 fhc->task = GNUNET_SCHEDULER_add_with_priority (fhc->priority,
148 &file_hash_task, fhc); 153 &file_hash_task,
154 fhc);
149} 155}
150 156
151 157
@@ -156,12 +162,13 @@ file_hash_task (void *cls)
156 * @param filename name of file to hash 162 * @param filename name of file to hash
157 * @param blocksize number of bytes to process in one task 163 * @param blocksize number of bytes to process in one task
158 * @param callback function to call upon completion 164 * @param callback function to call upon completion
159 * @param callback_cls closure for callback 165 * @param callback_cls closure for @a callback
160 * @return NULL on (immediate) errror 166 * @return NULL on (immediate) errror
161 */ 167 */
162struct GNUNET_CRYPTO_FileHashContext * 168struct GNUNET_CRYPTO_FileHashContext *
163GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, 169GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
164 const char *filename, size_t blocksize, 170 const char *filename,
171 size_t blocksize,
165 GNUNET_CRYPTO_HashCompletedCallback callback, 172 GNUNET_CRYPTO_HashCompletedCallback callback,
166 void *callback_cls) 173 void *callback_cls)
167{ 174{
@@ -181,24 +188,29 @@ GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
181 return NULL; 188 return NULL;
182 } 189 }
183 fhc->bsize = blocksize; 190 fhc->bsize = blocksize;
184 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO, GNUNET_YES)) 191 if (GNUNET_OK !=
192 GNUNET_DISK_file_size (filename,
193 &fhc->fsize,
194 GNUNET_NO,
195 GNUNET_YES))
185 { 196 {
186 GNUNET_free (fhc->filename); 197 GNUNET_free (fhc->filename);
187 GNUNET_free (fhc); 198 GNUNET_free (fhc);
188 return NULL; 199 return NULL;
189 } 200 }
190 fhc->fh = 201 fhc->fh = GNUNET_DISK_file_open (filename,
191 GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 202 GNUNET_DISK_OPEN_READ,
192 GNUNET_DISK_PERM_NONE); 203 GNUNET_DISK_PERM_NONE);
193 if (!fhc->fh) 204 if (! fhc->fh)
194 { 205 {
195 GNUNET_free (fhc->filename); 206 GNUNET_free (fhc->filename);
196 GNUNET_free (fhc); 207 GNUNET_free (fhc);
197 return NULL; 208 return NULL;
198 } 209 }
199 fhc->priority = priority; 210 fhc->priority = priority;
200 fhc->task = 211 fhc->task = GNUNET_SCHEDULER_add_with_priority (priority,
201 GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc); 212 &file_hash_task,
213 fhc);
202 return fhc; 214 return fhc;
203} 215}
204 216
@@ -213,7 +225,8 @@ GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc)
213{ 225{
214 GNUNET_SCHEDULER_cancel (fhc->task); 226 GNUNET_SCHEDULER_cancel (fhc->task);
215 GNUNET_free (fhc->filename); 227 GNUNET_free (fhc->filename);
216 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh)); 228 GNUNET_break (GNUNET_OK ==
229 GNUNET_DISK_file_close (fhc->fh));
217 GNUNET_free (fhc); 230 GNUNET_free (fhc);
218} 231}
219 232