diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-18 09:32:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-18 09:32:04 +0000 |
commit | d7f07521d128b52e1b2c2326705cf64ad3888143 (patch) | |
tree | faea8518d65916093acda56894ecfa9100633af3 /src/fs/gnunet-auto-share.c | |
parent | 0115176c8a7b78096db7cc3cb020422409e34bf8 (diff) | |
download | gnunet-d7f07521d128b52e1b2c2326705cf64ad3888143.tar.gz gnunet-d7f07521d128b52e1b2c2326705cf64ad3888143.zip |
-implementing read_state
Diffstat (limited to 'src/fs/gnunet-auto-share.c')
-rw-r--r-- | src/fs/gnunet-auto-share.c | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index 8436e8442..ec324e43e 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c | |||
@@ -141,13 +141,74 @@ static struct GNUNET_TIME_Absolute start_time; | |||
141 | 141 | ||
142 | 142 | ||
143 | /** | 143 | /** |
144 | * Compute the name of the state database file we will use. | ||
145 | */ | ||
146 | static char * | ||
147 | get_state_file () | ||
148 | { | ||
149 | char *ret; | ||
150 | |||
151 | GNUNET_asprintf (&ret, | ||
152 | "%s%s.auto", | ||
153 | dir_name, | ||
154 | (DIR_SEPARATOR == dir_name[strlen(dir_name)-1]) ? "" : DIR_SEPARATOR_STR); | ||
155 | return ret; | ||
156 | } | ||
157 | |||
158 | |||
159 | /** | ||
144 | * Load the set of 'work_finished' items from disk. | 160 | * Load the set of 'work_finished' items from disk. |
145 | */ | 161 | */ |
146 | static void | 162 | static void |
147 | load_state () | 163 | load_state () |
148 | { | 164 | { |
149 | GNUNET_break (0); | 165 | char *fn; |
150 | // FIXME: implement! | 166 | struct GNUNET_BIO_ReadHandle *rh; |
167 | uint32_t n; | ||
168 | struct GNUNET_HashCode id; | ||
169 | struct WorkItem *wi; | ||
170 | char *emsg; | ||
171 | |||
172 | emsg = NULL; | ||
173 | fn = get_state_file (); | ||
174 | rh = GNUNET_BIO_read_open (fn); | ||
175 | GNUNET_free (fn); | ||
176 | if (NULL == rh) | ||
177 | return; | ||
178 | fn = NULL; | ||
179 | if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &n)) | ||
180 | goto error; | ||
181 | while (n-- > 0) | ||
182 | { | ||
183 | if ( (GNUNET_OK != | ||
184 | GNUNET_BIO_read_string (rh, "filename", &fn, 1024)) || | ||
185 | (GNUNET_OK != | ||
186 | GNUNET_BIO_read (rh, "id", &id, sizeof (struct GNUNET_HashCode))) ) | ||
187 | goto error; | ||
188 | wi = GNUNET_malloc (sizeof (struct WorkItem)); | ||
189 | wi->id = id; | ||
190 | wi->filename = fn; | ||
191 | fn = NULL; | ||
192 | GNUNET_CRYPTO_hash (wi->filename, | ||
193 | strlen (wi->filename), | ||
194 | &id); | ||
195 | GNUNET_CONTAINER_multihashmap_put (work_finished, | ||
196 | &id, | ||
197 | wi, | ||
198 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
199 | } | ||
200 | if (GNUNET_OK == | ||
201 | GNUNET_BIO_read_close (rh, &emsg)) | ||
202 | return; | ||
203 | rh = NULL; | ||
204 | error: | ||
205 | GNUNET_free_non_null (fn); | ||
206 | if (NULL != rh) | ||
207 | GNUNET_BIO_read_close (rh, &emsg); | ||
208 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
209 | _("Failed to load state: %s\n"), | ||
210 | emsg); | ||
211 | GNUNET_free_non_null (emsg); | ||
151 | } | 212 | } |
152 | 213 | ||
153 | 214 | ||