diff options
author | Alessio Vanni <vannilla@firemail.cc> | 2020-05-14 16:03:10 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-05-19 02:41:47 +0200 |
commit | f4771fcc1c3fda21a46d0cb85d8b29e012254696 (patch) | |
tree | 012df74ed2cf44cb20605b239e1b88dab6edc645 /src/fs/fs_api.c | |
parent | 6a52ce5f9bc35a852b215e7073f3a0d2665ca8de (diff) | |
download | gnunet-f4771fcc1c3fda21a46d0cb85d8b29e012254696.tar.gz gnunet-f4771fcc1c3fda21a46d0cb85d8b29e012254696.zip |
Improved BIO API
BIO now supports reading from and writing to in-memory buffers.
For reading, an allocated buffer (array) and a size is passed as arguments to
the function opening the handle.
For writing, a GNUNET_Buffer is created and used internally. The buffer
contents can be extracted using the relevant function.
There is a new API in addition to the existing read/write: this new API is
more "declarative" in nature and is meant to mimic APIs like GNUNET_SQ.
The read/write operations are defined in an array of specs which are then
"commited" in a single (non-atomic) operation, rather than explicitly
executing multiple function calls and checking their return value.
Also there are small changes to GNUNET_Buffer to account for BIO's new
features.
Signed-off-by: Christian Grothoff <christian@grothoff.org>
Diffstat (limited to 'src/fs/fs_api.c')
-rw-r--r-- | src/fs/fs_api.c | 447 |
1 files changed, 284 insertions, 163 deletions
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index e04a93f9c..39e3add63 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.c | |||
@@ -676,7 +676,7 @@ get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) | |||
676 | fn = get_serialization_file_name (h, ext, ent); | 676 | fn = get_serialization_file_name (h, ext, ent); |
677 | if (NULL == fn) | 677 | if (NULL == fn) |
678 | return NULL; | 678 | return NULL; |
679 | ret = GNUNET_BIO_read_open (fn); | 679 | ret = GNUNET_BIO_read_open_file (fn); |
680 | GNUNET_free (fn); | 680 | GNUNET_free (fn); |
681 | return ret; | 681 | return ret; |
682 | } | 682 | } |
@@ -699,7 +699,7 @@ get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) | |||
699 | fn = get_serialization_file_name (h, ext, ent); | 699 | fn = get_serialization_file_name (h, ext, ent); |
700 | if (NULL == fn) | 700 | if (NULL == fn) |
701 | return NULL; | 701 | return NULL; |
702 | ret = GNUNET_BIO_write_open (fn); | 702 | ret = GNUNET_BIO_write_open_file (fn); |
703 | GNUNET_break (NULL != ret); | 703 | GNUNET_break (NULL != ret); |
704 | GNUNET_free (fn); | 704 | GNUNET_free (fn); |
705 | return ret; | 705 | return ret; |
@@ -727,7 +727,7 @@ get_write_handle_in_dir (struct GNUNET_FS_Handle *h, | |||
727 | fn = get_serialization_file_name_in_dir (h, ext, uni, ent); | 727 | fn = get_serialization_file_name_in_dir (h, ext, uni, ent); |
728 | if (NULL == fn) | 728 | if (NULL == fn) |
729 | return NULL; | 729 | return NULL; |
730 | ret = GNUNET_BIO_write_open (fn); | 730 | ret = GNUNET_BIO_write_open_file (fn); |
731 | GNUNET_free (fn); | 731 | GNUNET_free (fn); |
732 | return ret; | 732 | return ret; |
733 | } | 733 | } |
@@ -839,7 +839,7 @@ write_start_time (struct GNUNET_BIO_WriteHandle *wh, | |||
839 | struct GNUNET_TIME_Relative dur; | 839 | struct GNUNET_TIME_Relative dur; |
840 | 840 | ||
841 | dur = GNUNET_TIME_absolute_get_duration (timestamp); | 841 | dur = GNUNET_TIME_absolute_get_duration (timestamp); |
842 | return GNUNET_BIO_write_int64 (wh, dur.rel_value_us); | 842 | return GNUNET_BIO_write_int64 (wh, "start time", dur.rel_value_us); |
843 | } | 843 | } |
844 | 844 | ||
845 | 845 | ||
@@ -863,7 +863,8 @@ read_start_time (struct GNUNET_BIO_ReadHandle *rh, | |||
863 | { | 863 | { |
864 | struct GNUNET_TIME_Relative dur; | 864 | struct GNUNET_TIME_Relative dur; |
865 | 865 | ||
866 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dur.rel_value_us)) | 866 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, "start time", |
867 | (int64_t *) &dur.rel_value_us)) | ||
867 | return GNUNET_SYSERR; | 868 | return GNUNET_SYSERR; |
868 | *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), dur); | 869 | *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), dur); |
869 | return GNUNET_OK; | 870 | return GNUNET_OK; |
@@ -937,10 +938,22 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
937 | (GNUNET_OK != | 938 | (GNUNET_OK != |
938 | GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || | 939 | GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || |
939 | (GNUNET_OK != | 940 | (GNUNET_OK != |
940 | GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) || | 941 | GNUNET_BIO_read_int64 ( |
941 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || | 942 | rh, |
942 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) || | 943 | "expiration time", |
943 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level))) | 944 | (int64_t *) &ret->bo.expiration_time.abs_value_us)) || |
945 | (GNUNET_OK != GNUNET_BIO_read_int32 ( | ||
946 | rh, | ||
947 | "anonymity level", | ||
948 | (int32_t *) &ret->bo.anonymity_level)) || | ||
949 | (GNUNET_OK != GNUNET_BIO_read_int32 ( | ||
950 | rh, | ||
951 | "content priority", | ||
952 | (int32_t *) &ret->bo.content_priority)) || | ||
953 | (GNUNET_OK != GNUNET_BIO_read_int32 ( | ||
954 | rh, | ||
955 | "replication level", | ||
956 | (int32_t *) &ret->bo.replication_level))) | ||
944 | { | 957 | { |
945 | GNUNET_break (0); | 958 | GNUNET_break (0); |
946 | goto cleanup; | 959 | goto cleanup; |
@@ -948,7 +961,10 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
948 | switch (b) | 961 | switch (b) |
949 | { | 962 | { |
950 | case 0: /* file-insert */ | 963 | case 0: /* file-insert */ |
951 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) | 964 | if (GNUNET_OK != GNUNET_BIO_read_int64 ( |
965 | rh, | ||
966 | "file size", | ||
967 | (int64_t *) &ret->data.file.file_size)) | ||
952 | { | 968 | { |
953 | GNUNET_break (0); | 969 | GNUNET_break (0); |
954 | goto cleanup; | 970 | goto cleanup; |
@@ -990,7 +1006,10 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
990 | GNUNET_break (0); | 1006 | GNUNET_break (0); |
991 | goto cleanup; | 1007 | goto cleanup; |
992 | } | 1008 | } |
993 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) | 1009 | if (GNUNET_OK != GNUNET_BIO_read_int64 ( |
1010 | rh, | ||
1011 | "file size", | ||
1012 | (int64_t *) &ret->data.file.file_size)) | ||
994 | { | 1013 | { |
995 | GNUNET_break (0); | 1014 | GNUNET_break (0); |
996 | goto cleanup; | 1015 | goto cleanup; |
@@ -1010,7 +1029,10 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
1010 | GNUNET_break (0); | 1029 | GNUNET_break (0); |
1011 | goto cleanup; | 1030 | goto cleanup; |
1012 | } | 1031 | } |
1013 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || | 1032 | if ((GNUNET_OK != GNUNET_BIO_read_int64 ( |
1033 | rh, | ||
1034 | "file size", | ||
1035 | (int64_t *) &ret->data.file.file_size)) || | ||
1014 | (GNUNET_OK != GNUNET_BIO_read (rh, | 1036 | (GNUNET_OK != GNUNET_BIO_read (rh, |
1015 | "fileid", | 1037 | "fileid", |
1016 | &ret->data.file.file_id, | 1038 | &ret->data.file.file_id, |
@@ -1034,7 +1056,10 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
1034 | GNUNET_break (0); | 1056 | GNUNET_break (0); |
1035 | goto cleanup; | 1057 | goto cleanup; |
1036 | } | 1058 | } |
1037 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || | 1059 | if ((GNUNET_OK != GNUNET_BIO_read_int64 ( |
1060 | rh, | ||
1061 | "file size", | ||
1062 | (int64_t *) &ret->data.file.file_size)) || | ||
1038 | (GNUNET_OK != GNUNET_BIO_read (rh, | 1063 | (GNUNET_OK != GNUNET_BIO_read (rh, |
1039 | "fileid", | 1064 | "fileid", |
1040 | &ret->data.file.file_id, | 1065 | &ret->data.file.file_id, |
@@ -1054,11 +1079,18 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
1054 | 1079 | ||
1055 | case 4: /* directory */ | 1080 | case 4: /* directory */ |
1056 | ret->is_directory = GNUNET_YES; | 1081 | ret->is_directory = GNUNET_YES; |
1057 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) || | 1082 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, "dsize", |
1083 | (int32_t *) &dsize)) || | ||
1058 | (GNUNET_OK != | 1084 | (GNUNET_OK != |
1059 | GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) || | 1085 | GNUNET_BIO_read_int64 ( |
1086 | rh, | ||
1087 | "contents completed", | ||
1088 | (int64_t *) &ret->data.dir.contents_completed)) || | ||
1060 | (GNUNET_OK != | 1089 | (GNUNET_OK != |
1061 | GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) || | 1090 | GNUNET_BIO_read_int64 ( |
1091 | rh, | ||
1092 | "contents size", | ||
1093 | (int64_t *)&ret->data.dir.contents_size)) || | ||
1062 | (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || | 1094 | (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || |
1063 | (GNUNET_OK != | 1095 | (GNUNET_OK != |
1064 | GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || | 1096 | GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || |
@@ -1294,7 +1326,7 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, | |||
1294 | GNUNET_free (emsg); | 1326 | GNUNET_free (emsg); |
1295 | return GNUNET_SYSERR; | 1327 | return GNUNET_SYSERR; |
1296 | } | 1328 | } |
1297 | if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret)) | 1329 | if (GNUNET_OK != GNUNET_BIO_write (wh, "copied from reader", buf, ret)) |
1298 | return GNUNET_SYSERR; | 1330 | return GNUNET_SYSERR; |
1299 | off += ret; | 1331 | off += ret; |
1300 | } | 1332 | } |
@@ -1353,19 +1385,34 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1353 | skss = GNUNET_FS_uri_to_string (fi->sks_uri); | 1385 | skss = GNUNET_FS_uri_to_string (fi->sks_uri); |
1354 | else | 1386 | else |
1355 | skss = NULL; | 1387 | skss = NULL; |
1356 | if ((GNUNET_OK != GNUNET_BIO_write (wh, &b, sizeof(b))) || | 1388 | struct GNUNET_BIO_WriteSpec ws1[] = { |
1357 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, fi->meta)) || | 1389 | GNUNET_BIO_write_spec_object ("b", &b, sizeof (b)), |
1358 | (GNUNET_OK != GNUNET_BIO_write_string (wh, ksks)) || | 1390 | GNUNET_BIO_write_spec_meta_data ("meta", fi->meta), |
1359 | (GNUNET_OK != GNUNET_BIO_write_string (wh, chks)) || | 1391 | GNUNET_BIO_write_spec_string ("ksks", ksks), |
1360 | (GNUNET_OK != GNUNET_BIO_write_string (wh, skss)) || | 1392 | GNUNET_BIO_write_spec_string ("chks", chks), |
1393 | GNUNET_BIO_write_spec_string ("skss", skss), | ||
1394 | GNUNET_BIO_write_spec_end (), | ||
1395 | }; | ||
1396 | struct GNUNET_BIO_WriteSpec ws2[] = { | ||
1397 | GNUNET_BIO_write_spec_string ("emsg", fi->emsg), | ||
1398 | GNUNET_BIO_write_spec_string ("filename", fi->filename), | ||
1399 | GNUNET_BIO_write_spec_int64 ( | ||
1400 | "expiration time", | ||
1401 | (int64_t *) &fi->bo.expiration_time.abs_value_us), | ||
1402 | GNUNET_BIO_write_spec_int32 ( | ||
1403 | "anonymity level", | ||
1404 | (int32_t *) &fi->bo.anonymity_level), | ||
1405 | GNUNET_BIO_write_spec_int32 ( | ||
1406 | "content priority", | ||
1407 | (int32_t *) &fi->bo.content_priority), | ||
1408 | GNUNET_BIO_write_spec_int32 ( | ||
1409 | "replication level", | ||
1410 | (int32_t *) &fi->bo.replication_level), | ||
1411 | GNUNET_BIO_write_spec_end (), | ||
1412 | }; | ||
1413 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) || | ||
1361 | (GNUNET_OK != write_start_time (wh, fi->start_time)) || | 1414 | (GNUNET_OK != write_start_time (wh, fi->start_time)) || |
1362 | (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->emsg)) || | 1415 | (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws2))) |
1363 | (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->filename)) || | ||
1364 | (GNUNET_OK != | ||
1365 | GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value_us)) || | ||
1366 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) || | ||
1367 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) || | ||
1368 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.replication_level))) | ||
1369 | { | 1416 | { |
1370 | GNUNET_break (0); | 1417 | GNUNET_break (0); |
1371 | goto cleanup; | 1418 | goto cleanup; |
@@ -1380,7 +1427,8 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1380 | switch (b) | 1427 | switch (b) |
1381 | { | 1428 | { |
1382 | case 0: /* file-insert */ | 1429 | case 0: /* file-insert */ |
1383 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) | 1430 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size", |
1431 | fi->data.file.file_size)) | ||
1384 | { | 1432 | { |
1385 | GNUNET_break (0); | 1433 | GNUNET_break (0); |
1386 | goto cleanup; | 1434 | goto cleanup; |
@@ -1399,7 +1447,8 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1399 | GNUNET_break (0); | 1447 | GNUNET_break (0); |
1400 | goto cleanup; | 1448 | goto cleanup; |
1401 | } | 1449 | } |
1402 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) | 1450 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size", |
1451 | fi->data.file.file_size)) | ||
1403 | { | 1452 | { |
1404 | GNUNET_break (0); | 1453 | GNUNET_break (0); |
1405 | goto cleanup; | 1454 | goto cleanup; |
@@ -1413,8 +1462,10 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1413 | GNUNET_break (0); | 1462 | GNUNET_break (0); |
1414 | goto cleanup; | 1463 | goto cleanup; |
1415 | } | 1464 | } |
1416 | if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) || | 1465 | if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size", |
1466 | fi->data.file.file_size)) || | ||
1417 | (GNUNET_OK != GNUNET_BIO_write (wh, | 1467 | (GNUNET_OK != GNUNET_BIO_write (wh, |
1468 | "file id", | ||
1418 | &fi->data.file.file_id, | 1469 | &fi->data.file.file_id, |
1419 | sizeof(struct GNUNET_HashCode)))) | 1470 | sizeof(struct GNUNET_HashCode)))) |
1420 | { | 1471 | { |
@@ -1427,19 +1478,24 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1427 | if ((NULL != fi->data.dir.entries) && | 1478 | if ((NULL != fi->data.dir.entries) && |
1428 | (NULL == fi->data.dir.entries->serialization)) | 1479 | (NULL == fi->data.dir.entries->serialization)) |
1429 | GNUNET_FS_file_information_sync_ (fi->data.dir.entries); | 1480 | GNUNET_FS_file_information_sync_ (fi->data.dir.entries); |
1430 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) || | 1481 | struct GNUNET_BIO_WriteSpec ws[] = { |
1431 | (GNUNET_OK != | 1482 | GNUNET_BIO_write_spec_int32 ("dir size", |
1432 | GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) || | 1483 | (int32_t *) &fi->data.dir.dir_size), |
1433 | (GNUNET_OK != | 1484 | GNUNET_BIO_write_spec_int64 ( |
1434 | GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) || | 1485 | "contents completed", |
1435 | (GNUNET_OK != GNUNET_BIO_write (wh, | 1486 | (int64_t *) &fi->data.dir.contents_completed), |
1436 | fi->data.dir.dir_data, | 1487 | GNUNET_BIO_write_spec_int64 ("contents size", |
1437 | (uint32_t) fi->data.dir.dir_size)) || | 1488 | (int64_t *) &fi->data.dir.contents_size), |
1438 | (GNUNET_OK != | 1489 | GNUNET_BIO_write_spec_object ("dir data", |
1439 | GNUNET_BIO_write_string (wh, | 1490 | fi->data.dir.dir_data, |
1440 | (fi->data.dir.entries == NULL) | 1491 | (uint32_t) fi->data.dir.dir_size), |
1441 | ? NULL | 1492 | GNUNET_BIO_write_spec_string ("dir entries", |
1442 | : fi->data.dir.entries->serialization))) | 1493 | (fi->data.dir.entries == NULL) |
1494 | ? NULL | ||
1495 | : fi->data.dir.entries->serialization), | ||
1496 | GNUNET_BIO_write_spec_end (), | ||
1497 | }; | ||
1498 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws))) | ||
1443 | { | 1499 | { |
1444 | GNUNET_break (0); | 1500 | GNUNET_break (0); |
1445 | goto cleanup; | 1501 | goto cleanup; |
@@ -1453,6 +1509,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1453 | if ((NULL != fi->next) && (NULL == fi->next->serialization)) | 1509 | if ((NULL != fi->next) && (NULL == fi->next->serialization)) |
1454 | GNUNET_FS_file_information_sync_ (fi->next); | 1510 | GNUNET_FS_file_information_sync_ (fi->next); |
1455 | if (GNUNET_OK != GNUNET_BIO_write_string (wh, | 1511 | if (GNUNET_OK != GNUNET_BIO_write_string (wh, |
1512 | "serialization", | ||
1456 | (fi->next != NULL) | 1513 | (fi->next != NULL) |
1457 | ? fi->next->serialization | 1514 | ? fi->next->serialization |
1458 | : NULL)) | 1515 | : NULL)) |
@@ -1460,7 +1517,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1460 | GNUNET_break (0); | 1517 | GNUNET_break (0); |
1461 | goto cleanup; | 1518 | goto cleanup; |
1462 | } | 1519 | } |
1463 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1520 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
1464 | { | 1521 | { |
1465 | wh = NULL; | 1522 | wh = NULL; |
1466 | GNUNET_break (0); | 1523 | GNUNET_break (0); |
@@ -1469,7 +1526,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1469 | return; /* done! */ | 1526 | return; /* done! */ |
1470 | cleanup: | 1527 | cleanup: |
1471 | if (NULL != wh) | 1528 | if (NULL != wh) |
1472 | (void) GNUNET_BIO_write_close (wh); | 1529 | (void) GNUNET_BIO_write_close (wh, NULL); |
1473 | GNUNET_free_non_null (chks); | 1530 | GNUNET_free_non_null (chks); |
1474 | GNUNET_free_non_null (ksks); | 1531 | GNUNET_free_non_null (ksks); |
1475 | GNUNET_free_non_null (skss); | 1532 | GNUNET_free_non_null (skss); |
@@ -1586,23 +1643,23 @@ deserialize_publish_file (void *cls, const char *filename) | |||
1586 | pc->serialization = get_serialization_short_name (filename); | 1643 | pc->serialization = get_serialization_short_name (filename); |
1587 | fi_root = NULL; | 1644 | fi_root = NULL; |
1588 | fi_pos = NULL; | 1645 | fi_pos = NULL; |
1589 | rh = GNUNET_BIO_read_open (filename); | 1646 | rh = GNUNET_BIO_read_open_file (filename); |
1590 | if (NULL == rh) | 1647 | if (NULL == rh) |
1591 | { | 1648 | { |
1592 | GNUNET_break (0); | 1649 | GNUNET_break (0); |
1593 | goto cleanup; | 1650 | goto cleanup; |
1594 | } | 1651 | } |
1595 | if ((GNUNET_OK != | 1652 | struct GNUNET_BIO_ReadSpec rs[] = { |
1596 | GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) || | 1653 | GNUNET_BIO_read_spec_string ("publish-nid", &pc->nid, 1024), |
1597 | (GNUNET_OK != | 1654 | GNUNET_BIO_read_spec_string ("publish-nuid", &pc->nuid, 1024), |
1598 | GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || | 1655 | GNUNET_BIO_read_spec_int32 ("options", &options), |
1599 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 1656 | GNUNET_BIO_read_spec_int32 ("all done", &all_done), |
1600 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) || | 1657 | GNUNET_BIO_read_spec_int32 ("have ns", &have_ns), |
1601 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) || | 1658 | GNUNET_BIO_read_spec_string ("publish-firoot", &fi_root, 128), |
1602 | (GNUNET_OK != | 1659 | GNUNET_BIO_read_spec_string ("publish-fipos", &fi_pos, 128), |
1603 | GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || | 1660 | GNUNET_BIO_read_spec_end (), |
1604 | (GNUNET_OK != | 1661 | }; |
1605 | GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) || | 1662 | if ((GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) || |
1606 | ((GNUNET_YES == have_ns) && | 1663 | ((GNUNET_YES == have_ns) && |
1607 | (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof(ns))))) | 1664 | (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof(ns))))) |
1608 | { | 1665 | { |
@@ -1729,26 +1786,29 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | |||
1729 | goto cleanup; | 1786 | goto cleanup; |
1730 | } | 1787 | } |
1731 | have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO; | 1788 | have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO; |
1732 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nid)) || | 1789 | struct GNUNET_BIO_WriteSpec ws[] = { |
1733 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nuid)) || | 1790 | GNUNET_BIO_write_spec_string ("nid", pc->nid), |
1734 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->options)) || | 1791 | GNUNET_BIO_write_spec_string ("nuid", pc->nuid), |
1735 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) || | 1792 | GNUNET_BIO_write_spec_int32 ("options", (int32_t *) &pc->options), |
1736 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) || | 1793 | GNUNET_BIO_write_spec_int32 ("all done", &pc->all_done), |
1737 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) || | 1794 | GNUNET_BIO_write_spec_int32 ("have ns", &have_ns), |
1738 | (GNUNET_OK != GNUNET_BIO_write_string (wh, | 1795 | GNUNET_BIO_write_spec_string ("serialization", pc->fi->serialization), |
1739 | (NULL == pc->fi_pos) | 1796 | GNUNET_BIO_write_spec_string ("pos serialization", (NULL == pc->fi_pos) |
1740 | ? NULL | 1797 | ? NULL |
1741 | : pc->fi_pos->serialization)) || | 1798 | : pc->fi_pos->serialization) |
1799 | }; | ||
1800 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)) || | ||
1742 | ((NULL != pc->ns) && | 1801 | ((NULL != pc->ns) && |
1743 | (GNUNET_OK != | 1802 | (GNUNET_OK != |
1744 | GNUNET_BIO_write (wh, | 1803 | GNUNET_BIO_write (wh, |
1804 | "ns", | ||
1745 | pc->ns, | 1805 | pc->ns, |
1746 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey))))) | 1806 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey))))) |
1747 | { | 1807 | { |
1748 | GNUNET_break (0); | 1808 | GNUNET_break (0); |
1749 | goto cleanup; | 1809 | goto cleanup; |
1750 | } | 1810 | } |
1751 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1811 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
1752 | { | 1812 | { |
1753 | wh = NULL; | 1813 | wh = NULL; |
1754 | GNUNET_break (0); | 1814 | GNUNET_break (0); |
@@ -1757,7 +1817,7 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | |||
1757 | return; | 1817 | return; |
1758 | cleanup: | 1818 | cleanup: |
1759 | if (NULL != wh) | 1819 | if (NULL != wh) |
1760 | (void) GNUNET_BIO_write_close (wh); | 1820 | (void) GNUNET_BIO_write_close (wh, NULL); |
1761 | GNUNET_FS_remove_sync_file_ (pc->h, | 1821 | GNUNET_FS_remove_sync_file_ (pc->h, |
1762 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1822 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
1763 | pc->serialization); | 1823 | pc->serialization); |
@@ -1797,25 +1857,34 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) | |||
1797 | uris = GNUNET_FS_uri_to_string (uc->ksk_uri); | 1857 | uris = GNUNET_FS_uri_to_string (uc->ksk_uri); |
1798 | else | 1858 | else |
1799 | uris = NULL; | 1859 | uris = NULL; |
1800 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uc->filename)) || | 1860 | struct GNUNET_BIO_WriteSpec ws1[] = { |
1801 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, uc->file_size)) || | 1861 | GNUNET_BIO_write_spec_string ("filename", uc->filename), |
1862 | GNUNET_BIO_write_spec_int64 ("file size", (int64_t *) &uc->file_size), | ||
1863 | GNUNET_BIO_write_spec_end (), | ||
1864 | }; | ||
1865 | struct GNUNET_BIO_WriteSpec ws2[] = { | ||
1866 | GNUNET_BIO_write_spec_int32 ("state", (int32_t *) &uc->state), | ||
1867 | GNUNET_BIO_write_spec_object ("hashkey", &uc->chk, | ||
1868 | sizeof (struct ContentHashKey)), | ||
1869 | GNUNET_BIO_write_spec_string ("uris", uris), | ||
1870 | GNUNET_BIO_write_spec_int32 ("ksk offset", (int32_t *) &uc->ksk_offset), | ||
1871 | GNUNET_BIO_write_spec_end (), | ||
1872 | }; | ||
1873 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) || | ||
1802 | (GNUNET_OK != write_start_time (wh, uc->start_time)) || | 1874 | (GNUNET_OK != write_start_time (wh, uc->start_time)) || |
1803 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) || | 1875 | (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws2)) || |
1804 | (GNUNET_OK != | ||
1805 | GNUNET_BIO_write (wh, &uc->chk, sizeof(struct ContentHashKey))) || | ||
1806 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | ||
1807 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) || | ||
1808 | ((uc->state == UNINDEX_STATE_FS_NOTIFY) && | 1876 | ((uc->state == UNINDEX_STATE_FS_NOTIFY) && |
1809 | (GNUNET_OK != GNUNET_BIO_write (wh, | 1877 | (GNUNET_OK != GNUNET_BIO_write (wh, |
1878 | "file id", | ||
1810 | &uc->file_id, | 1879 | &uc->file_id, |
1811 | sizeof(struct GNUNET_HashCode)))) || | 1880 | sizeof(struct GNUNET_HashCode)))) || |
1812 | ((uc->state == UNINDEX_STATE_ERROR) && | 1881 | ((uc->state == UNINDEX_STATE_ERROR) && |
1813 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg)))) | 1882 | (GNUNET_OK != GNUNET_BIO_write_string (wh, "emsg", uc->emsg)))) |
1814 | { | 1883 | { |
1815 | GNUNET_break (0); | 1884 | GNUNET_break (0); |
1816 | goto cleanup; | 1885 | goto cleanup; |
1817 | } | 1886 | } |
1818 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1887 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
1819 | { | 1888 | { |
1820 | wh = NULL; | 1889 | wh = NULL; |
1821 | GNUNET_break (0); | 1890 | GNUNET_break (0); |
@@ -1824,7 +1893,7 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) | |||
1824 | return; | 1893 | return; |
1825 | cleanup: | 1894 | cleanup: |
1826 | if (NULL != wh) | 1895 | if (NULL != wh) |
1827 | (void) GNUNET_BIO_write_close (wh); | 1896 | (void) GNUNET_BIO_write_close (wh, NULL); |
1828 | GNUNET_FS_remove_sync_file_ (uc->h, | 1897 | GNUNET_FS_remove_sync_file_ (uc->h, |
1829 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 1898 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
1830 | uc->serialization); | 1899 | uc->serialization); |
@@ -1845,15 +1914,20 @@ write_download_request (struct GNUNET_BIO_WriteHandle *wh, | |||
1845 | struct DownloadRequest *dr) | 1914 | struct DownloadRequest *dr) |
1846 | { | 1915 | { |
1847 | unsigned int i; | 1916 | unsigned int i; |
1848 | 1917 | struct GNUNET_BIO_WriteSpec ws[] = { | |
1849 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->state)) || | 1918 | GNUNET_BIO_write_spec_int32 ("state", (int32_t *) &dr->state), |
1850 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dr->offset)) || | 1919 | GNUNET_BIO_write_spec_int64 ("offset", (int64_t *) &dr->offset), |
1851 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->num_children)) || | 1920 | GNUNET_BIO_write_spec_int32 ("num children", (int32_t *) &dr->num_children), |
1852 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth))) | 1921 | GNUNET_BIO_write_spec_int32 ("depth", (int32_t *) &dr->depth), |
1922 | GNUNET_BIO_write_spec_end (), | ||
1923 | }; | ||
1924 | |||
1925 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws))) | ||
1853 | return GNUNET_NO; | 1926 | return GNUNET_NO; |
1854 | if ((BRS_CHK_SET == dr->state) && | 1927 | if ((BRS_CHK_SET == dr->state) && |
1855 | (GNUNET_OK != | 1928 | (GNUNET_OK != |
1856 | GNUNET_BIO_write (wh, &dr->chk, sizeof(struct ContentHashKey)))) | 1929 | GNUNET_BIO_write (wh, "hashkey", |
1930 | &dr->chk, sizeof(struct ContentHashKey)))) | ||
1857 | return GNUNET_NO; | 1931 | return GNUNET_NO; |
1858 | for (i = 0; i < dr->num_children; i++) | 1932 | for (i = 0; i < dr->num_children; i++) |
1859 | if (GNUNET_NO == write_download_request (wh, dr->children[i])) | 1933 | if (GNUNET_NO == write_download_request (wh, dr->children[i])) |
@@ -1875,11 +1949,16 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh) | |||
1875 | unsigned int i; | 1949 | unsigned int i; |
1876 | 1950 | ||
1877 | dr = GNUNET_new (struct DownloadRequest); | 1951 | dr = GNUNET_new (struct DownloadRequest); |
1878 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->state)) || | 1952 | struct GNUNET_BIO_ReadSpec rs[] = { |
1879 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dr->offset)) || | 1953 | GNUNET_BIO_read_spec_int32 ("state", (int32_t *) &dr->state), |
1880 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) || | 1954 | GNUNET_BIO_read_spec_int64 ("offset", (int64_t *) &dr->offset), |
1955 | GNUNET_BIO_read_spec_int32 ("num children", (int32_t *) &dr->num_children), | ||
1956 | GNUNET_BIO_read_spec_end (), | ||
1957 | }; | ||
1958 | if ((GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) || | ||
1881 | (dr->num_children > CHK_PER_INODE) || | 1959 | (dr->num_children > CHK_PER_INODE) || |
1882 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) || | 1960 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "depth", |
1961 | (int32_t *) &dr->depth)) || | ||
1883 | ((0 == dr->depth) && (dr->num_children > 0)) || | 1962 | ((0 == dr->depth) && (dr->num_children > 0)) || |
1884 | ((dr->depth > 0) && (0 == dr->num_children))) | 1963 | ((dr->depth > 0) && (0 == dr->num_children))) |
1885 | { | 1964 | { |
@@ -2005,7 +2084,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) | |||
2005 | return; | 2084 | return; |
2006 | } | 2085 | } |
2007 | } | 2086 | } |
2008 | wh = GNUNET_BIO_write_open (fn); | 2087 | wh = GNUNET_BIO_write_open_file (fn); |
2009 | if (NULL == wh) | 2088 | if (NULL == wh) |
2010 | { | 2089 | { |
2011 | GNUNET_free (dc->serialization); | 2090 | GNUNET_free (dc->serialization); |
@@ -2016,19 +2095,28 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) | |||
2016 | GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) || | 2095 | GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) || |
2017 | (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri))); | 2096 | (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri))); |
2018 | uris = GNUNET_FS_uri_to_string (dc->uri); | 2097 | uris = GNUNET_FS_uri_to_string (dc->uri); |
2019 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2098 | struct GNUNET_BIO_WriteSpec ws1[] = { |
2020 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, dc->meta)) || | 2099 | GNUNET_BIO_write_spec_string ("uris", uris), |
2021 | (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->emsg)) || | 2100 | GNUNET_BIO_write_spec_meta_data ("metadata", dc->meta), |
2022 | (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->filename)) || | 2101 | GNUNET_BIO_write_spec_string ("emsg", dc->emsg), |
2023 | (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->temp_filename)) || | 2102 | GNUNET_BIO_write_spec_string ("filename", dc->filename), |
2024 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->old_file_size)) || | 2103 | GNUNET_BIO_write_spec_string ("temp filename", dc->temp_filename), |
2025 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->offset)) || | 2104 | GNUNET_BIO_write_spec_int64 ("old file size", |
2026 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->length)) || | 2105 | (int64_t *) &dc->old_file_size), |
2027 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->completed)) || | 2106 | GNUNET_BIO_write_spec_int64 ("offset", (int64_t *) &dc->offset), |
2107 | GNUNET_BIO_write_spec_int64 ("length", (int64_t *) &dc->length), | ||
2108 | GNUNET_BIO_write_spec_int64 ("completed", (int64_t *) &dc->completed), | ||
2109 | GNUNET_BIO_write_spec_end (), | ||
2110 | }; | ||
2111 | struct GNUNET_BIO_WriteSpec ws2[] = { | ||
2112 | GNUNET_BIO_write_spec_int32 ("anonymity", (int32_t *) &dc->anonymity), | ||
2113 | GNUNET_BIO_write_spec_int32 ("options", (int32_t *) &dc->options), | ||
2114 | GNUNET_BIO_write_spec_int32 ("has finished", (int32_t *) &dc->has_finished), | ||
2115 | GNUNET_BIO_write_spec_end (), | ||
2116 | }; | ||
2117 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) || | ||
2028 | (GNUNET_OK != write_start_time (wh, dc->start_time)) || | 2118 | (GNUNET_OK != write_start_time (wh, dc->start_time)) || |
2029 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dc->anonymity)) || | 2119 | (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws2))) |
2030 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) || | ||
2031 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished))) | ||
2032 | { | 2120 | { |
2033 | GNUNET_break (0); | 2121 | GNUNET_break (0); |
2034 | goto cleanup; | 2122 | goto cleanup; |
@@ -2044,7 +2132,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) | |||
2044 | } | 2132 | } |
2045 | GNUNET_free_non_null (uris); | 2133 | GNUNET_free_non_null (uris); |
2046 | uris = NULL; | 2134 | uris = NULL; |
2047 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 2135 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
2048 | { | 2136 | { |
2049 | wh = NULL; | 2137 | wh = NULL; |
2050 | GNUNET_break (0); | 2138 | GNUNET_break (0); |
@@ -2054,7 +2142,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) | |||
2054 | return; | 2142 | return; |
2055 | cleanup: | 2143 | cleanup: |
2056 | if (NULL != wh) | 2144 | if (NULL != wh) |
2057 | (void) GNUNET_BIO_write_close (wh); | 2145 | (void) GNUNET_BIO_write_close (wh, NULL); |
2058 | GNUNET_free_non_null (uris); | 2146 | GNUNET_free_non_null (uris); |
2059 | if (0 != unlink (fn)) | 2147 | if (0 != unlink (fn)) |
2060 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 2148 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
@@ -2102,23 +2190,30 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | |||
2102 | goto cleanup; | 2190 | goto cleanup; |
2103 | } | 2191 | } |
2104 | uris = GNUNET_FS_uri_to_string (sr->uri); | 2192 | uris = GNUNET_FS_uri_to_string (sr->uri); |
2105 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2193 | struct GNUNET_BIO_WriteSpec ws[] = { |
2106 | (GNUNET_OK != GNUNET_BIO_write_string (wh, | 2194 | GNUNET_BIO_write_spec_string ("uris", uris), |
2107 | (sr->download != NULL) | 2195 | GNUNET_BIO_write_spec_string ("download serialization", |
2108 | ? sr->download->serialization | 2196 | (sr->download != NULL) |
2109 | : NULL)) || | 2197 | ? sr->download->serialization |
2110 | (GNUNET_OK != | 2198 | : NULL), |
2111 | GNUNET_BIO_write_string (wh, | 2199 | GNUNET_BIO_write_spec_string ("update search serialization", |
2112 | (sr->update_search != NULL) | 2200 | (sr->update_search != NULL) |
2113 | ? sr->update_search->serialization | 2201 | ? sr->update_search->serialization |
2114 | : NULL)) || | 2202 | : NULL), |
2115 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) || | 2203 | GNUNET_BIO_write_spec_meta_data ("metadata", sr->meta), |
2116 | (GNUNET_OK != | 2204 | GNUNET_BIO_write_spec_object ("key", &sr->key, |
2117 | GNUNET_BIO_write (wh, &sr->key, sizeof(struct GNUNET_HashCode))) || | 2205 | sizeof(struct GNUNET_HashCode)), |
2118 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || | 2206 | GNUNET_BIO_write_spec_int32 ("mandatory missing", |
2119 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) || | 2207 | (int32_t *) &sr->mandatory_missing), |
2120 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) || | 2208 | GNUNET_BIO_write_spec_int32 ("optional support", |
2121 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials))) | 2209 | (int32_t *) &sr->optional_support), |
2210 | GNUNET_BIO_write_spec_int32 ("availability success", | ||
2211 | (int32_t *) &sr->availability_success), | ||
2212 | GNUNET_BIO_write_spec_int32 ("availability trials", | ||
2213 | (int32_t *) &sr->availability_trials), | ||
2214 | GNUNET_BIO_write_spec_end (), | ||
2215 | }; | ||
2216 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws))) | ||
2122 | { | 2217 | { |
2123 | GNUNET_break (0); | 2218 | GNUNET_break (0); |
2124 | goto cleanup; | 2219 | goto cleanup; |
@@ -2126,13 +2221,14 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | |||
2126 | if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) && | 2221 | if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) && |
2127 | (GNUNET_OK != | 2222 | (GNUNET_OK != |
2128 | GNUNET_BIO_write (wh, | 2223 | GNUNET_BIO_write (wh, |
2224 | "keyword bitmap", | ||
2129 | sr->keyword_bitmap, | 2225 | sr->keyword_bitmap, |
2130 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) | 2226 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) |
2131 | { | 2227 | { |
2132 | GNUNET_break (0); | 2228 | GNUNET_break (0); |
2133 | goto cleanup; | 2229 | goto cleanup; |
2134 | } | 2230 | } |
2135 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 2231 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
2136 | { | 2232 | { |
2137 | wh = NULL; | 2233 | wh = NULL; |
2138 | GNUNET_break (0); | 2234 | GNUNET_break (0); |
@@ -2143,7 +2239,7 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | |||
2143 | cleanup: | 2239 | cleanup: |
2144 | GNUNET_free_non_null (uris); | 2240 | GNUNET_free_non_null (uris); |
2145 | if (NULL != wh) | 2241 | if (NULL != wh) |
2146 | (void) GNUNET_BIO_write_close (wh); | 2242 | (void) GNUNET_BIO_write_close (wh, NULL); |
2147 | remove_sync_file_in_dir (sr->h, | 2243 | remove_sync_file_in_dir (sr->h, |
2148 | (NULL == sr->sc->psearch_result) | 2244 | (NULL == sr->sc->psearch_result) |
2149 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2245 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
@@ -2188,19 +2284,21 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) | |||
2188 | (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri))); | 2284 | (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri))); |
2189 | uris = GNUNET_FS_uri_to_string (sc->uri); | 2285 | uris = GNUNET_FS_uri_to_string (sc->uri); |
2190 | in_pause = (sc->task != NULL) ? 'r' : '\0'; | 2286 | in_pause = (sc->task != NULL) ? 'r' : '\0'; |
2191 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2287 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, "uris", uris)) || |
2192 | (GNUNET_OK != write_start_time (wh, sc->start_time)) || | 2288 | (GNUNET_OK != write_start_time (wh, sc->start_time)) || |
2193 | (GNUNET_OK != GNUNET_BIO_write_string (wh, sc->emsg)) || | 2289 | (GNUNET_OK != GNUNET_BIO_write_string (wh, "emsg", sc->emsg)) || |
2194 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) || | 2290 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "options", |
2195 | (GNUNET_OK != GNUNET_BIO_write (wh, &in_pause, sizeof(in_pause))) || | 2291 | (uint32_t) sc->options)) || |
2196 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sc->anonymity))) | 2292 | (GNUNET_OK != GNUNET_BIO_write (wh, "in pause", |
2293 | &in_pause, sizeof(in_pause))) || | ||
2294 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "anonymity", sc->anonymity))) | ||
2197 | { | 2295 | { |
2198 | GNUNET_break (0); | 2296 | GNUNET_break (0); |
2199 | goto cleanup; | 2297 | goto cleanup; |
2200 | } | 2298 | } |
2201 | GNUNET_free (uris); | 2299 | GNUNET_free (uris); |
2202 | uris = NULL; | 2300 | uris = NULL; |
2203 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 2301 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
2204 | { | 2302 | { |
2205 | wh = NULL; | 2303 | wh = NULL; |
2206 | GNUNET_break (0); | 2304 | GNUNET_break (0); |
@@ -2209,7 +2307,7 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) | |||
2209 | return; | 2307 | return; |
2210 | cleanup: | 2308 | cleanup: |
2211 | if (NULL != wh) | 2309 | if (NULL != wh) |
2212 | (void) GNUNET_BIO_write_close (wh); | 2310 | (void) GNUNET_BIO_write_close (wh, NULL); |
2213 | GNUNET_free_non_null (uris); | 2311 | GNUNET_free_non_null (uris); |
2214 | GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization); | 2312 | GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization); |
2215 | GNUNET_free (sc->serialization); | 2313 | GNUNET_free (sc->serialization); |
@@ -2239,7 +2337,7 @@ deserialize_unindex_file (void *cls, const char *filename) | |||
2239 | uc = GNUNET_new (struct GNUNET_FS_UnindexContext); | 2337 | uc = GNUNET_new (struct GNUNET_FS_UnindexContext); |
2240 | uc->h = h; | 2338 | uc->h = h; |
2241 | uc->serialization = get_serialization_short_name (filename); | 2339 | uc->serialization = get_serialization_short_name (filename); |
2242 | rh = GNUNET_BIO_read_open (filename); | 2340 | rh = GNUNET_BIO_read_open_file (filename); |
2243 | if (NULL == rh) | 2341 | if (NULL == rh) |
2244 | { | 2342 | { |
2245 | GNUNET_break (0); | 2343 | GNUNET_break (0); |
@@ -2248,14 +2346,17 @@ deserialize_unindex_file (void *cls, const char *filename) | |||
2248 | uris = NULL; | 2346 | uris = NULL; |
2249 | if ((GNUNET_OK != | 2347 | if ((GNUNET_OK != |
2250 | GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) || | 2348 | GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) || |
2251 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) || | 2349 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, "file size", |
2350 | (int64_t *) &uc->file_size)) || | ||
2252 | (GNUNET_OK != read_start_time (rh, &uc->start_time)) || | 2351 | (GNUNET_OK != read_start_time (rh, &uc->start_time)) || |
2253 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) || | 2352 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "state", |
2353 | (int32_t *) &state)) || | ||
2254 | (GNUNET_OK != | 2354 | (GNUNET_OK != |
2255 | GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) || | 2355 | GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) || |
2256 | (GNUNET_OK != | 2356 | (GNUNET_OK != |
2257 | GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || | 2357 | GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || |
2258 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset))) | 2358 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "ksk offset", |
2359 | (int32_t *) &uc->ksk_offset))) | ||
2259 | { | 2360 | { |
2260 | GNUNET_free_non_null (uris); | 2361 | GNUNET_free_non_null (uris); |
2261 | GNUNET_break (0); | 2362 | GNUNET_break (0); |
@@ -2443,7 +2544,7 @@ deserialize_search_result (void *cls, const char *filename) | |||
2443 | struct GNUNET_FS_SearchResult *sr; | 2544 | struct GNUNET_FS_SearchResult *sr; |
2444 | 2545 | ||
2445 | ser = get_serialization_short_name (filename); | 2546 | ser = get_serialization_short_name (filename); |
2446 | rh = GNUNET_BIO_read_open (filename); | 2547 | rh = GNUNET_BIO_read_open_file (filename); |
2447 | if (NULL == rh) | 2548 | if (NULL == rh) |
2448 | { | 2549 | { |
2449 | if (NULL != ser) | 2550 | if (NULL != ser) |
@@ -2478,10 +2579,22 @@ deserialize_search_result (void *cls, const char *filename) | |||
2478 | "result-key", | 2579 | "result-key", |
2479 | &sr->key, | 2580 | &sr->key, |
2480 | sizeof(struct GNUNET_HashCode))) || | 2581 | sizeof(struct GNUNET_HashCode))) || |
2481 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || | 2582 | (GNUNET_OK != GNUNET_BIO_read_int32 ( |
2482 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || | 2583 | rh, |
2483 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || | 2584 | "mandatory missing", |
2484 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials))) | 2585 | (int32_t *) &sr->mandatory_missing)) || |
2586 | (GNUNET_OK != GNUNET_BIO_read_int32 ( | ||
2587 | rh, | ||
2588 | "optional support", | ||
2589 | (int32_t *) &sr->optional_support)) || | ||
2590 | (GNUNET_OK != GNUNET_BIO_read_int32 ( | ||
2591 | rh, | ||
2592 | "availability success", | ||
2593 | (int32_t *) &sr->availability_success)) || | ||
2594 | (GNUNET_OK != GNUNET_BIO_read_int32 ( | ||
2595 | rh, | ||
2596 | "availability trials", | ||
2597 | (int32_t *) &sr->availability_trials))) | ||
2485 | { | 2598 | { |
2486 | GNUNET_break (0); | 2599 | GNUNET_break (0); |
2487 | goto cleanup; | 2600 | goto cleanup; |
@@ -2741,7 +2854,7 @@ deserialize_subdownload (void *cls, const char *filename) | |||
2741 | struct GNUNET_BIO_ReadHandle *rh; | 2854 | struct GNUNET_BIO_ReadHandle *rh; |
2742 | 2855 | ||
2743 | ser = get_serialization_short_name (filename); | 2856 | ser = get_serialization_short_name (filename); |
2744 | rh = GNUNET_BIO_read_open (filename); | 2857 | rh = GNUNET_BIO_read_open_file (filename); |
2745 | if (NULL == rh) | 2858 | if (NULL == rh) |
2746 | { | 2859 | { |
2747 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2860 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -2827,29 +2940,35 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2827 | dc->parent = parent; | 2940 | dc->parent = parent; |
2828 | dc->h = h; | 2941 | dc->h = h; |
2829 | dc->serialization = GNUNET_strdup (serialization); | 2942 | dc->serialization = GNUNET_strdup (serialization); |
2943 | struct GNUNET_BIO_ReadSpec rs[] = { | ||
2944 | GNUNET_BIO_read_spec_meta_data ("download-meta", &dc->meta), | ||
2945 | GNUNET_BIO_read_spec_string ("download-emsg", &dc->emsg, 10 * 1024), | ||
2946 | GNUNET_BIO_read_spec_string ("download-fn", &dc->filename, 10 * 1024), | ||
2947 | GNUNET_BIO_read_spec_string ("download-tfn", | ||
2948 | &dc->temp_filename, 10 * 1024), | ||
2949 | GNUNET_BIO_read_spec_int64 ("old file size", | ||
2950 | (int64_t *) &dc->old_file_size), | ||
2951 | GNUNET_BIO_read_spec_int64 ("offset", | ||
2952 | (int64_t *) &dc->offset), | ||
2953 | GNUNET_BIO_read_spec_int64 ("length", | ||
2954 | (int64_t *) &dc->length), | ||
2955 | GNUNET_BIO_read_spec_int64 ("completed", | ||
2956 | (int64_t *) &dc->completed), | ||
2957 | GNUNET_BIO_read_spec_end (), | ||
2958 | }; | ||
2830 | if ((GNUNET_OK != | 2959 | if ((GNUNET_OK != |
2831 | GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) || | 2960 | GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) || |
2832 | (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || | 2961 | (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || |
2833 | ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && | 2962 | ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && |
2834 | (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || | 2963 | (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || |
2835 | (GNUNET_OK != | 2964 | (GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) || |
2836 | GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) || | ||
2837 | (GNUNET_OK != | ||
2838 | GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) || | ||
2839 | (GNUNET_OK != | ||
2840 | GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || | ||
2841 | (GNUNET_OK != GNUNET_BIO_read_string (rh, | ||
2842 | "download-tfn", | ||
2843 | &dc->temp_filename, | ||
2844 | 10 * 1024)) || | ||
2845 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || | ||
2846 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) || | ||
2847 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) || | ||
2848 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->completed)) || | ||
2849 | (GNUNET_OK != read_start_time (rh, &dc->start_time)) || | 2965 | (GNUNET_OK != read_start_time (rh, &dc->start_time)) || |
2850 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dc->anonymity)) || | 2966 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "anonymity", |
2851 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 2967 | (int32_t *) &dc->anonymity)) || |
2852 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &status))) | 2968 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "options", |
2969 | (int32_t *) &options)) || | ||
2970 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "status", | ||
2971 | (int32_t *) &status))) | ||
2853 | { | 2972 | { |
2854 | GNUNET_break (0); | 2973 | GNUNET_break (0); |
2855 | goto cleanup; | 2974 | goto cleanup; |
@@ -2972,10 +3091,12 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2972 | (GNUNET_OK != read_start_time (rh, &sc->start_time)) || | 3091 | (GNUNET_OK != read_start_time (rh, &sc->start_time)) || |
2973 | (GNUNET_OK != | 3092 | (GNUNET_OK != |
2974 | GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) || | 3093 | GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) || |
2975 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 3094 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "options", |
3095 | (int32_t *) &options)) || | ||
2976 | (GNUNET_OK != | 3096 | (GNUNET_OK != |
2977 | GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof(in_pause))) || | 3097 | GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof(in_pause))) || |
2978 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sc->anonymity))) | 3098 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "anonymity", |
3099 | (int32_t *) &sc->anonymity))) | ||
2979 | { | 3100 | { |
2980 | GNUNET_break (0); | 3101 | GNUNET_break (0); |
2981 | goto cleanup; | 3102 | goto cleanup; |
@@ -3038,7 +3159,7 @@ deserialize_search_file (void *cls, const char *filename) | |||
3038 | if (S_ISDIR (buf.st_mode)) | 3159 | if (S_ISDIR (buf.st_mode)) |
3039 | return GNUNET_OK; /* skip directories */ | 3160 | return GNUNET_OK; /* skip directories */ |
3040 | ser = get_serialization_short_name (filename); | 3161 | ser = get_serialization_short_name (filename); |
3041 | rh = GNUNET_BIO_read_open (filename); | 3162 | rh = GNUNET_BIO_read_open_file (filename); |
3042 | if (NULL == rh) | 3163 | if (NULL == rh) |
3043 | { | 3164 | { |
3044 | if (NULL != ser) | 3165 | if (NULL != ser) |
@@ -3081,7 +3202,7 @@ deserialize_download_file (void *cls, const char *filename) | |||
3081 | struct GNUNET_BIO_ReadHandle *rh; | 3202 | struct GNUNET_BIO_ReadHandle *rh; |
3082 | 3203 | ||
3083 | ser = get_serialization_short_name (filename); | 3204 | ser = get_serialization_short_name (filename); |
3084 | rh = GNUNET_BIO_read_open (filename); | 3205 | rh = GNUNET_BIO_read_open_file (filename); |
3085 | if (NULL == rh) | 3206 | if (NULL == rh) |
3086 | { | 3207 | { |
3087 | if (0 != unlink (filename)) | 3208 | if (0 != unlink (filename)) |