diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/peerstore/plugin_peerstore_flat.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/peerstore/plugin_peerstore_flat.c')
-rw-r--r-- | src/peerstore/plugin_peerstore_flat.c | 509 |
1 files changed, 255 insertions, 254 deletions
diff --git a/src/peerstore/plugin_peerstore_flat.c b/src/peerstore/plugin_peerstore_flat.c index 749e270e4..224664685 100644 --- a/src/peerstore/plugin_peerstore_flat.c +++ b/src/peerstore/plugin_peerstore_flat.c | |||
@@ -32,7 +32,8 @@ | |||
32 | /** | 32 | /** |
33 | * Context for all functions in this plugin. | 33 | * Context for all functions in this plugin. |
34 | */ | 34 | */ |
35 | struct Plugin { | 35 | struct Plugin |
36 | { | ||
36 | /** | 37 | /** |
37 | * Configuration handle | 38 | * Configuration handle |
38 | */ | 39 | */ |
@@ -96,23 +97,23 @@ struct Plugin { | |||
96 | 97 | ||
97 | 98 | ||
98 | static int | 99 | static int |
99 | delete_entries(void *cls, | 100 | delete_entries (void *cls, |
100 | const struct GNUNET_HashCode *key, | 101 | const struct GNUNET_HashCode *key, |
101 | void *value) | 102 | void *value) |
102 | { | 103 | { |
103 | struct Plugin *plugin = cls; | 104 | struct Plugin *plugin = cls; |
104 | struct GNUNET_PEERSTORE_Record *entry = value; | 105 | struct GNUNET_PEERSTORE_Record *entry = value; |
105 | 106 | ||
106 | if (0 != strcmp(plugin->iter_key, entry->key)) | 107 | if (0 != strcmp (plugin->iter_key, entry->key)) |
107 | return GNUNET_YES; | 108 | return GNUNET_YES; |
108 | if (0 != memcmp(plugin->iter_peer, | 109 | if (0 != memcmp (plugin->iter_peer, |
109 | &entry->peer, | 110 | &entry->peer, |
110 | sizeof(struct GNUNET_PeerIdentity))) | 111 | sizeof(struct GNUNET_PeerIdentity))) |
111 | return GNUNET_YES; | 112 | return GNUNET_YES; |
112 | if (0 != strcmp(plugin->iter_sub_system, entry->sub_system)) | 113 | if (0 != strcmp (plugin->iter_sub_system, entry->sub_system)) |
113 | return GNUNET_YES; | 114 | return GNUNET_YES; |
114 | 115 | ||
115 | GNUNET_CONTAINER_multihashmap_remove(plugin->hm, key, value); | 116 | GNUNET_CONTAINER_multihashmap_remove (plugin->hm, key, value); |
116 | plugin->deleted_entries++; | 117 | plugin->deleted_entries++; |
117 | return GNUNET_YES; | 118 | return GNUNET_YES; |
118 | } | 119 | } |
@@ -128,9 +129,9 @@ delete_entries(void *cls, | |||
128 | * @return number of deleted records | 129 | * @return number of deleted records |
129 | */ | 130 | */ |
130 | static int | 131 | static int |
131 | peerstore_flat_delete_records(void *cls, const char *sub_system, | 132 | peerstore_flat_delete_records (void *cls, const char *sub_system, |
132 | const struct GNUNET_PeerIdentity *peer, | 133 | const struct GNUNET_PeerIdentity *peer, |
133 | const char *key) | 134 | const char *key) |
134 | { | 135 | { |
135 | struct Plugin *plugin = cls; | 136 | struct Plugin *plugin = cls; |
136 | 137 | ||
@@ -139,25 +140,25 @@ peerstore_flat_delete_records(void *cls, const char *sub_system, | |||
139 | plugin->iter_key = key; | 140 | plugin->iter_key = key; |
140 | plugin->deleted_entries = 0; | 141 | plugin->deleted_entries = 0; |
141 | 142 | ||
142 | GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, | 143 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, |
143 | &delete_entries, | 144 | &delete_entries, |
144 | plugin); | 145 | plugin); |
145 | return plugin->deleted_entries; | 146 | return plugin->deleted_entries; |
146 | } | 147 | } |
147 | 148 | ||
148 | static int | 149 | static int |
149 | expire_entries(void *cls, | 150 | expire_entries (void *cls, |
150 | const struct GNUNET_HashCode *key, | 151 | const struct GNUNET_HashCode *key, |
151 | void *value) | 152 | void *value) |
152 | { | 153 | { |
153 | struct Plugin *plugin = cls; | 154 | struct Plugin *plugin = cls; |
154 | struct GNUNET_PEERSTORE_Record *entry = value; | 155 | struct GNUNET_PEERSTORE_Record *entry = value; |
155 | 156 | ||
156 | if (entry->expiry.abs_value_us < plugin->iter_now.abs_value_us) | 157 | if (entry->expiry.abs_value_us < plugin->iter_now.abs_value_us) |
157 | { | 158 | { |
158 | GNUNET_CONTAINER_multihashmap_remove(plugin->hm, key, value); | 159 | GNUNET_CONTAINER_multihashmap_remove (plugin->hm, key, value); |
159 | plugin->exp_changes++; | 160 | plugin->exp_changes++; |
160 | } | 161 | } |
161 | return GNUNET_YES; | 162 | return GNUNET_YES; |
162 | } | 163 | } |
163 | 164 | ||
@@ -174,49 +175,49 @@ expire_entries(void *cls, | |||
174 | * called | 175 | * called |
175 | */ | 176 | */ |
176 | static int | 177 | static int |
177 | peerstore_flat_expire_records(void *cls, struct GNUNET_TIME_Absolute now, | 178 | peerstore_flat_expire_records (void *cls, struct GNUNET_TIME_Absolute now, |
178 | GNUNET_PEERSTORE_Continuation cont, | 179 | GNUNET_PEERSTORE_Continuation cont, |
179 | void *cont_cls) | 180 | void *cont_cls) |
180 | { | 181 | { |
181 | struct Plugin *plugin = cls; | 182 | struct Plugin *plugin = cls; |
182 | 183 | ||
183 | plugin->exp_changes = 0; | 184 | plugin->exp_changes = 0; |
184 | plugin->iter_now = now; | 185 | plugin->iter_now = now; |
185 | 186 | ||
186 | GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, | 187 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, |
187 | &expire_entries, | 188 | &expire_entries, |
188 | plugin); | 189 | plugin); |
189 | if (NULL != cont) | 190 | if (NULL != cont) |
190 | { | 191 | { |
191 | cont(cont_cls, plugin->exp_changes); | 192 | cont (cont_cls, plugin->exp_changes); |
192 | } | 193 | } |
193 | return GNUNET_OK; | 194 | return GNUNET_OK; |
194 | } | 195 | } |
195 | 196 | ||
196 | 197 | ||
197 | static int | 198 | static int |
198 | iterate_entries(void *cls, | 199 | iterate_entries (void *cls, |
199 | const struct GNUNET_HashCode *key, | 200 | const struct GNUNET_HashCode *key, |
200 | void *value) | 201 | void *value) |
201 | { | 202 | { |
202 | struct Plugin *plugin = cls; | 203 | struct Plugin *plugin = cls; |
203 | struct GNUNET_PEERSTORE_Record *entry = value; | 204 | struct GNUNET_PEERSTORE_Record *entry = value; |
204 | 205 | ||
205 | if ((NULL != plugin->iter_peer) && | 206 | if ((NULL != plugin->iter_peer) && |
206 | (0 != memcmp(plugin->iter_peer, | 207 | (0 != memcmp (plugin->iter_peer, |
207 | &entry->peer, | 208 | &entry->peer, |
208 | sizeof(struct GNUNET_PeerIdentity)))) | 209 | sizeof(struct GNUNET_PeerIdentity)))) |
209 | { | 210 | { |
210 | return GNUNET_YES; | 211 | return GNUNET_YES; |
211 | } | 212 | } |
212 | if ((NULL != plugin->iter_key) && | 213 | if ((NULL != plugin->iter_key) && |
213 | (0 != strcmp(plugin->iter_key, | 214 | (0 != strcmp (plugin->iter_key, |
214 | entry->key))) | 215 | entry->key))) |
215 | { | 216 | { |
216 | return GNUNET_YES; | 217 | return GNUNET_YES; |
217 | } | 218 | } |
218 | if (NULL != plugin->iter) | 219 | if (NULL != plugin->iter) |
219 | plugin->iter(plugin->iter_cls, entry, NULL); | 220 | plugin->iter (plugin->iter_cls, entry, NULL); |
220 | plugin->iter_result_found = GNUNET_YES; | 221 | plugin->iter_result_found = GNUNET_YES; |
221 | return GNUNET_YES; | 222 | return GNUNET_YES; |
222 | } | 223 | } |
@@ -236,11 +237,11 @@ iterate_entries(void *cls, | |||
236 | * called | 237 | * called |
237 | */ | 238 | */ |
238 | static int | 239 | static int |
239 | peerstore_flat_iterate_records(void *cls, const char *sub_system, | 240 | peerstore_flat_iterate_records (void *cls, const char *sub_system, |
240 | const struct GNUNET_PeerIdentity *peer, | 241 | const struct GNUNET_PeerIdentity *peer, |
241 | const char *key, | 242 | const char *key, |
242 | GNUNET_PEERSTORE_Processor iter, | 243 | GNUNET_PEERSTORE_Processor iter, |
243 | void *iter_cls) | 244 | void *iter_cls) |
244 | { | 245 | { |
245 | struct Plugin *plugin = cls; | 246 | struct Plugin *plugin = cls; |
246 | 247 | ||
@@ -250,11 +251,11 @@ peerstore_flat_iterate_records(void *cls, const char *sub_system, | |||
250 | plugin->iter_sub_system = sub_system; | 251 | plugin->iter_sub_system = sub_system; |
251 | plugin->iter_key = key; | 252 | plugin->iter_key = key; |
252 | 253 | ||
253 | GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, | 254 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, |
254 | &iterate_entries, | 255 | &iterate_entries, |
255 | plugin); | 256 | plugin); |
256 | if (NULL != iter) | 257 | if (NULL != iter) |
257 | iter(iter_cls, NULL, NULL); | 258 | iter (iter_cls, NULL, NULL); |
258 | return GNUNET_OK; | 259 | return GNUNET_OK; |
259 | } | 260 | } |
260 | 261 | ||
@@ -277,13 +278,13 @@ peerstore_flat_iterate_records(void *cls, const char *sub_system, | |||
277 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR and cont is not called | 278 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR and cont is not called |
278 | */ | 279 | */ |
279 | static int | 280 | static int |
280 | peerstore_flat_store_record(void *cls, const char *sub_system, | 281 | peerstore_flat_store_record (void *cls, const char *sub_system, |
281 | const struct GNUNET_PeerIdentity *peer, | 282 | const struct GNUNET_PeerIdentity *peer, |
282 | const char *key, const void *value, size_t size, | 283 | const char *key, const void *value, size_t size, |
283 | struct GNUNET_TIME_Absolute expiry, | 284 | struct GNUNET_TIME_Absolute expiry, |
284 | enum GNUNET_PEERSTORE_StoreOption options, | 285 | enum GNUNET_PEERSTORE_StoreOption options, |
285 | GNUNET_PEERSTORE_Continuation cont, | 286 | GNUNET_PEERSTORE_Continuation cont, |
286 | void *cont_cls) | 287 | void *cont_cls) |
287 | { | 288 | { |
288 | struct Plugin *plugin = cls; | 289 | struct Plugin *plugin = cls; |
289 | struct GNUNET_HashCode hkey; | 290 | struct GNUNET_HashCode hkey; |
@@ -291,33 +292,33 @@ peerstore_flat_store_record(void *cls, const char *sub_system, | |||
291 | const char *peer_id; | 292 | const char *peer_id; |
292 | 293 | ||
293 | 294 | ||
294 | entry = GNUNET_new(struct GNUNET_PEERSTORE_Record); | 295 | entry = GNUNET_new (struct GNUNET_PEERSTORE_Record); |
295 | entry->sub_system = GNUNET_strdup(sub_system); | 296 | entry->sub_system = GNUNET_strdup (sub_system); |
296 | entry->key = GNUNET_strdup(key); | 297 | entry->key = GNUNET_strdup (key); |
297 | entry->value = GNUNET_malloc(size); | 298 | entry->value = GNUNET_malloc (size); |
298 | GNUNET_memcpy(entry->value, value, size); | 299 | GNUNET_memcpy (entry->value, value, size); |
299 | entry->value_size = size; | 300 | entry->value_size = size; |
300 | entry->peer = *peer; | 301 | entry->peer = *peer; |
301 | entry->expiry = expiry; | 302 | entry->expiry = expiry; |
302 | 303 | ||
303 | peer_id = GNUNET_i2s(peer); | 304 | peer_id = GNUNET_i2s (peer); |
304 | GNUNET_CRYPTO_hash(peer_id, | 305 | GNUNET_CRYPTO_hash (peer_id, |
305 | strlen(peer_id), | 306 | strlen (peer_id), |
306 | &hkey); | 307 | &hkey); |
307 | 308 | ||
308 | if (GNUNET_PEERSTORE_STOREOPTION_REPLACE == options) | 309 | if (GNUNET_PEERSTORE_STOREOPTION_REPLACE == options) |
309 | { | 310 | { |
310 | peerstore_flat_delete_records(cls, sub_system, peer, key); | 311 | peerstore_flat_delete_records (cls, sub_system, peer, key); |
311 | } | 312 | } |
312 | 313 | ||
313 | GNUNET_CONTAINER_multihashmap_put(plugin->hm, | 314 | GNUNET_CONTAINER_multihashmap_put (plugin->hm, |
314 | &hkey, | 315 | &hkey, |
315 | entry, | 316 | entry, |
316 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 317 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
317 | if (NULL != cont) | 318 | if (NULL != cont) |
318 | { | 319 | { |
319 | cont(cont_cls, GNUNET_OK); | 320 | cont (cont_cls, GNUNET_OK); |
320 | } | 321 | } |
321 | return GNUNET_OK; | 322 | return GNUNET_OK; |
322 | } | 323 | } |
323 | 324 | ||
@@ -331,7 +332,7 @@ peerstore_flat_store_record(void *cls, const char *sub_system, | |||
331 | * @return GNUNET_OK on success | 332 | * @return GNUNET_OK on success |
332 | */ | 333 | */ |
333 | static int | 334 | static int |
334 | database_setup(struct Plugin *plugin) | 335 | database_setup (struct Plugin *plugin) |
335 | { | 336 | { |
336 | char *afsdir; | 337 | char *afsdir; |
337 | char *key; | 338 | char *key; |
@@ -348,139 +349,139 @@ database_setup(struct Plugin *plugin) | |||
348 | char *line; | 349 | char *line; |
349 | 350 | ||
350 | if (GNUNET_OK != | 351 | if (GNUNET_OK != |
351 | GNUNET_CONFIGURATION_get_value_filename(plugin->cfg, "peerstore-flat", | 352 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, "peerstore-flat", |
352 | "FILENAME", &afsdir)) | 353 | "FILENAME", &afsdir)) |
354 | { | ||
355 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "peerstore-flat", | ||
356 | "FILENAME"); | ||
357 | return GNUNET_SYSERR; | ||
358 | } | ||
359 | if (GNUNET_OK != GNUNET_DISK_file_test (afsdir)) | ||
360 | { | ||
361 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir)) | ||
353 | { | 362 | { |
354 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "peerstore-flat", | 363 | GNUNET_break (0); |
355 | "FILENAME"); | 364 | GNUNET_free (afsdir); |
356 | return GNUNET_SYSERR; | 365 | return GNUNET_SYSERR; |
357 | } | 366 | } |
358 | if (GNUNET_OK != GNUNET_DISK_file_test(afsdir)) | 367 | } |
359 | { | ||
360 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(afsdir)) | ||
361 | { | ||
362 | GNUNET_break(0); | ||
363 | GNUNET_free(afsdir); | ||
364 | return GNUNET_SYSERR; | ||
365 | } | ||
366 | } | ||
367 | /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ | 368 | /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ |
368 | plugin->fn = afsdir; | 369 | plugin->fn = afsdir; |
369 | 370 | ||
370 | fh = GNUNET_DISK_file_open(afsdir, | 371 | fh = GNUNET_DISK_file_open (afsdir, |
371 | GNUNET_DISK_OPEN_CREATE | | 372 | GNUNET_DISK_OPEN_CREATE |
372 | GNUNET_DISK_OPEN_READWRITE, | 373 | | GNUNET_DISK_OPEN_READWRITE, |
373 | GNUNET_DISK_PERM_USER_WRITE | | 374 | GNUNET_DISK_PERM_USER_WRITE |
374 | GNUNET_DISK_PERM_USER_READ); | 375 | | GNUNET_DISK_PERM_USER_READ); |
375 | if (NULL == fh) | 376 | if (NULL == fh) |
376 | { | 377 | { |
377 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 378 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
378 | _("Unable to initialize file: %s.\n"), | 379 | _ ("Unable to initialize file: %s.\n"), |
379 | afsdir); | 380 | afsdir); |
380 | return GNUNET_SYSERR; | 381 | return GNUNET_SYSERR; |
381 | } | 382 | } |
382 | 383 | ||
383 | /* Load data from file into hashmap */ | 384 | /* Load data from file into hashmap */ |
384 | plugin->hm = GNUNET_CONTAINER_multihashmap_create(10, | 385 | plugin->hm = GNUNET_CONTAINER_multihashmap_create (10, |
385 | GNUNET_NO); | 386 | GNUNET_NO); |
386 | 387 | ||
387 | if (GNUNET_SYSERR == GNUNET_DISK_file_size(afsdir, | 388 | if (GNUNET_SYSERR == GNUNET_DISK_file_size (afsdir, |
388 | &size, | 389 | &size, |
389 | GNUNET_YES, | 390 | GNUNET_YES, |
390 | GNUNET_YES)) | 391 | GNUNET_YES)) |
391 | { | 392 | { |
392 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 393 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
393 | _("Unable to get filesize: %s.\n"), | 394 | _ ("Unable to get filesize: %s.\n"), |
394 | afsdir); | 395 | afsdir); |
395 | return GNUNET_SYSERR; | 396 | return GNUNET_SYSERR; |
396 | } | 397 | } |
397 | 398 | ||
398 | buffer = GNUNET_malloc(size + 1); | 399 | buffer = GNUNET_malloc (size + 1); |
399 | 400 | ||
400 | if (GNUNET_SYSERR == GNUNET_DISK_file_read(fh, | 401 | if (GNUNET_SYSERR == GNUNET_DISK_file_read (fh, |
401 | buffer, | 402 | buffer, |
402 | size)) | 403 | size)) |
403 | { | 404 | { |
404 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 405 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
405 | _("Unable to read file: %s.\n"), | 406 | _ ("Unable to read file: %s.\n"), |
406 | afsdir); | 407 | afsdir); |
407 | GNUNET_DISK_file_close(fh); | 408 | GNUNET_DISK_file_close (fh); |
408 | GNUNET_free(buffer); | 409 | GNUNET_free (buffer); |
409 | return GNUNET_SYSERR; | 410 | return GNUNET_SYSERR; |
410 | } | 411 | } |
411 | 412 | ||
412 | buffer[size] = '\0'; | 413 | buffer[size] = '\0'; |
413 | GNUNET_DISK_file_close(fh); | 414 | GNUNET_DISK_file_close (fh); |
414 | if (0 < size) | 415 | if (0 < size) |
416 | { | ||
417 | line = strtok (buffer, "\n"); | ||
418 | while (line != NULL) | ||
415 | { | 419 | { |
416 | line = strtok(buffer, "\n"); | 420 | sub_system = strtok (line, ","); |
417 | while (line != NULL) | 421 | if (NULL == sub_system) |
418 | { | 422 | break; |
419 | sub_system = strtok(line, ","); | 423 | peer = strtok (NULL, ","); |
420 | if (NULL == sub_system) | 424 | if (NULL == peer) |
421 | break; | 425 | break; |
422 | peer = strtok(NULL, ","); | 426 | key = strtok (NULL, ","); |
423 | if (NULL == peer) | 427 | if (NULL == key) |
424 | break; | 428 | break; |
425 | key = strtok(NULL, ","); | 429 | value = strtok (NULL, ","); |
426 | if (NULL == key) | 430 | if (NULL == value) |
427 | break; | 431 | break; |
428 | value = strtok(NULL, ","); | 432 | expiry = strtok (NULL, ","); |
429 | if (NULL == value) | 433 | if (NULL == expiry) |
430 | break; | 434 | break; |
431 | expiry = strtok(NULL, ","); | 435 | entry = GNUNET_new (struct GNUNET_PEERSTORE_Record); |
432 | if (NULL == expiry) | 436 | entry->sub_system = GNUNET_strdup (sub_system); |
433 | break; | 437 | entry->key = GNUNET_strdup (key); |
434 | entry = GNUNET_new(struct GNUNET_PEERSTORE_Record); | 438 | { |
435 | entry->sub_system = GNUNET_strdup(sub_system); | 439 | size_t s; |
436 | entry->key = GNUNET_strdup(key); | 440 | char *o; |
437 | { | 441 | |
438 | size_t s; | 442 | o = NULL; |
439 | char *o; | 443 | s = GNUNET_STRINGS_base64_decode (peer, |
440 | 444 | strlen (peer), | |
441 | o = NULL; | 445 | (void**) &o); |
442 | s = GNUNET_STRINGS_base64_decode(peer, | 446 | if (sizeof(struct GNUNET_PeerIdentity) == s) |
443 | strlen(peer), | 447 | GNUNET_memcpy (&entry->peer, |
444 | (void**)&o); | 448 | o, |
445 | if (sizeof(struct GNUNET_PeerIdentity) == s) | 449 | s); |
446 | GNUNET_memcpy(&entry->peer, | 450 | else |
447 | o, | 451 | GNUNET_break (0); |
448 | s); | 452 | GNUNET_free_non_null (o); |
449 | else | 453 | } |
450 | GNUNET_break(0); | 454 | entry->value_size = GNUNET_STRINGS_base64_decode (value, |
451 | GNUNET_free_non_null(o); | 455 | strlen (value), |
452 | } | 456 | (void**) &entry->value); |
453 | entry->value_size = GNUNET_STRINGS_base64_decode(value, | 457 | if (GNUNET_SYSERR == |
454 | strlen(value), | 458 | GNUNET_STRINGS_fancy_time_to_absolute (expiry, |
455 | (void**)&entry->value); | 459 | &entry->expiry)) |
456 | if (GNUNET_SYSERR == | 460 | { |
457 | GNUNET_STRINGS_fancy_time_to_absolute(expiry, | 461 | GNUNET_free (entry->sub_system); |
458 | &entry->expiry)) | 462 | GNUNET_free (entry->key); |
459 | { | 463 | GNUNET_free (entry); |
460 | GNUNET_free(entry->sub_system); | 464 | break; |
461 | GNUNET_free(entry->key); | 465 | } |
462 | GNUNET_free(entry); | 466 | peer_id = GNUNET_i2s (&entry->peer); |
463 | break; | 467 | GNUNET_CRYPTO_hash (peer_id, |
464 | } | 468 | strlen (peer_id), |
465 | peer_id = GNUNET_i2s(&entry->peer); | 469 | &hkey); |
466 | GNUNET_CRYPTO_hash(peer_id, | 470 | |
467 | strlen(peer_id), | 471 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (plugin->hm, |
468 | &hkey); | 472 | &hkey, |
469 | 473 | entry, | |
470 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(plugin->hm, | 474 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
471 | &hkey, | ||
472 | entry, | ||
473 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
474 | } | ||
475 | } | 475 | } |
476 | GNUNET_free(buffer); | 476 | } |
477 | GNUNET_free (buffer); | ||
477 | return GNUNET_OK; | 478 | return GNUNET_OK; |
478 | } | 479 | } |
479 | 480 | ||
480 | static int | 481 | static int |
481 | store_and_free_entries(void *cls, | 482 | store_and_free_entries (void *cls, |
482 | const struct GNUNET_HashCode *key, | 483 | const struct GNUNET_HashCode *key, |
483 | void *value) | 484 | void *value) |
484 | { | 485 | { |
485 | struct GNUNET_DISK_FileHandle *fh = cls; | 486 | struct GNUNET_DISK_FileHandle *fh = cls; |
486 | struct GNUNET_PEERSTORE_Record *entry = value; | 487 | struct GNUNET_PEERSTORE_Record *entry = value; |
@@ -489,30 +490,30 @@ store_and_free_entries(void *cls, | |||
489 | const char *expiry; | 490 | const char *expiry; |
490 | char *val; | 491 | char *val; |
491 | 492 | ||
492 | GNUNET_STRINGS_base64_encode(entry->value, | 493 | GNUNET_STRINGS_base64_encode (entry->value, |
493 | entry->value_size, | 494 | entry->value_size, |
494 | &val); | 495 | &val); |
495 | expiry = GNUNET_STRINGS_absolute_time_to_string(entry->expiry); | 496 | expiry = GNUNET_STRINGS_absolute_time_to_string (entry->expiry); |
496 | GNUNET_STRINGS_base64_encode((char*)&entry->peer, | 497 | GNUNET_STRINGS_base64_encode ((char*) &entry->peer, |
497 | sizeof(struct GNUNET_PeerIdentity), | 498 | sizeof(struct GNUNET_PeerIdentity), |
498 | &peer); | 499 | &peer); |
499 | GNUNET_asprintf(&line, | 500 | GNUNET_asprintf (&line, |
500 | "%s,%s,%s,%s,%s", | 501 | "%s,%s,%s,%s,%s", |
501 | entry->sub_system, | 502 | entry->sub_system, |
502 | peer, | 503 | peer, |
503 | entry->key, | 504 | entry->key, |
504 | val, | 505 | val, |
505 | expiry); | 506 | expiry); |
506 | GNUNET_free(val); | 507 | GNUNET_free (val); |
507 | GNUNET_free(peer); | 508 | GNUNET_free (peer); |
508 | GNUNET_DISK_file_write(fh, | 509 | GNUNET_DISK_file_write (fh, |
509 | line, | 510 | line, |
510 | strlen(line)); | 511 | strlen (line)); |
511 | GNUNET_free(entry->sub_system); | 512 | GNUNET_free (entry->sub_system); |
512 | GNUNET_free(entry->key); | 513 | GNUNET_free (entry->key); |
513 | GNUNET_free(entry->value); | 514 | GNUNET_free (entry->value); |
514 | GNUNET_free(entry); | 515 | GNUNET_free (entry); |
515 | GNUNET_free(line); | 516 | GNUNET_free (line); |
516 | return GNUNET_YES; | 517 | return GNUNET_YES; |
517 | } | 518 | } |
518 | 519 | ||
@@ -522,28 +523,28 @@ store_and_free_entries(void *cls, | |||
522 | * @param plugin the plugin context (state for this module) | 523 | * @param plugin the plugin context (state for this module) |
523 | */ | 524 | */ |
524 | static void | 525 | static void |
525 | database_shutdown(struct Plugin *plugin) | 526 | database_shutdown (struct Plugin *plugin) |
526 | { | 527 | { |
527 | struct GNUNET_DISK_FileHandle *fh; | 528 | struct GNUNET_DISK_FileHandle *fh; |
528 | 529 | ||
529 | fh = GNUNET_DISK_file_open(plugin->fn, | 530 | fh = GNUNET_DISK_file_open (plugin->fn, |
530 | GNUNET_DISK_OPEN_CREATE | | 531 | GNUNET_DISK_OPEN_CREATE |
531 | GNUNET_DISK_OPEN_TRUNCATE | | 532 | | GNUNET_DISK_OPEN_TRUNCATE |
532 | GNUNET_DISK_OPEN_READWRITE, | 533 | | GNUNET_DISK_OPEN_READWRITE, |
533 | GNUNET_DISK_PERM_USER_WRITE | | 534 | GNUNET_DISK_PERM_USER_WRITE |
534 | GNUNET_DISK_PERM_USER_READ); | 535 | | GNUNET_DISK_PERM_USER_READ); |
535 | if (NULL == fh) | 536 | if (NULL == fh) |
536 | { | 537 | { |
537 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 538 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
538 | _("Unable to initialize file: %s.\n"), | 539 | _ ("Unable to initialize file: %s.\n"), |
539 | plugin->fn); | 540 | plugin->fn); |
540 | return; | 541 | return; |
541 | } | 542 | } |
542 | GNUNET_CONTAINER_multihashmap_iterate(plugin->hm, | 543 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, |
543 | &store_and_free_entries, | 544 | &store_and_free_entries, |
544 | fh); | 545 | fh); |
545 | GNUNET_CONTAINER_multihashmap_destroy(plugin->hm); | 546 | GNUNET_CONTAINER_multihashmap_destroy (plugin->hm); |
546 | GNUNET_DISK_file_close(fh); | 547 | GNUNET_DISK_file_close (fh); |
547 | } | 548 | } |
548 | 549 | ||
549 | 550 | ||
@@ -554,7 +555,7 @@ database_shutdown(struct Plugin *plugin) | |||
554 | * @return NULL on error, otherwise the plugin context | 555 | * @return NULL on error, otherwise the plugin context |
555 | */ | 556 | */ |
556 | void * | 557 | void * |
557 | libgnunet_plugin_peerstore_flat_init(void *cls) | 558 | libgnunet_plugin_peerstore_flat_init (void *cls) |
558 | { | 559 | { |
559 | static struct Plugin plugin; | 560 | static struct Plugin plugin; |
560 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 561 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
@@ -562,19 +563,19 @@ libgnunet_plugin_peerstore_flat_init(void *cls) | |||
562 | 563 | ||
563 | if (NULL != plugin.cfg) | 564 | if (NULL != plugin.cfg) |
564 | return NULL; /* can only initialize once! */ | 565 | return NULL; /* can only initialize once! */ |
565 | memset(&plugin, 0, sizeof(struct Plugin)); | 566 | memset (&plugin, 0, sizeof(struct Plugin)); |
566 | plugin.cfg = cfg; | 567 | plugin.cfg = cfg; |
567 | if (GNUNET_OK != database_setup(&plugin)) | 568 | if (GNUNET_OK != database_setup (&plugin)) |
568 | { | 569 | { |
569 | database_shutdown(&plugin); | 570 | database_shutdown (&plugin); |
570 | return NULL; | 571 | return NULL; |
571 | } | 572 | } |
572 | api = GNUNET_new(struct GNUNET_PEERSTORE_PluginFunctions); | 573 | api = GNUNET_new (struct GNUNET_PEERSTORE_PluginFunctions); |
573 | api->cls = &plugin; | 574 | api->cls = &plugin; |
574 | api->store_record = &peerstore_flat_store_record; | 575 | api->store_record = &peerstore_flat_store_record; |
575 | api->iterate_records = &peerstore_flat_iterate_records; | 576 | api->iterate_records = &peerstore_flat_iterate_records; |
576 | api->expire_records = &peerstore_flat_expire_records; | 577 | api->expire_records = &peerstore_flat_expire_records; |
577 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is running\n"); | 578 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is running\n"); |
578 | return api; | 579 | return api; |
579 | } | 580 | } |
580 | 581 | ||
@@ -586,15 +587,15 @@ libgnunet_plugin_peerstore_flat_init(void *cls) | |||
586 | * @return Always NULL | 587 | * @return Always NULL |
587 | */ | 588 | */ |
588 | void * | 589 | void * |
589 | libgnunet_plugin_peerstore_flat_done(void *cls) | 590 | libgnunet_plugin_peerstore_flat_done (void *cls) |
590 | { | 591 | { |
591 | struct GNUNET_PEERSTORE_PluginFunctions *api = cls; | 592 | struct GNUNET_PEERSTORE_PluginFunctions *api = cls; |
592 | struct Plugin *plugin = api->cls; | 593 | struct Plugin *plugin = api->cls; |
593 | 594 | ||
594 | database_shutdown(plugin); | 595 | database_shutdown (plugin); |
595 | plugin->cfg = NULL; | 596 | plugin->cfg = NULL; |
596 | GNUNET_free(api); | 597 | GNUNET_free (api); |
597 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is finished\n"); | 598 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is finished\n"); |
598 | return NULL; | 599 | return NULL; |
599 | } | 600 | } |
600 | 601 | ||