More work on persisting data to disk.

Blockstore now storing the data, whereas datastore is storing the key
and filename. The key should be the multihash (currently the sha256, not
the multihash), and the value is the filename (base32).
This commit is contained in:
jmjatlanta 2016-12-14 12:07:43 -05:00
parent 88d177cf4a
commit 033dd767b4
20 changed files with 564 additions and 57 deletions

View file

@ -1,6 +1,7 @@
#include <stdio.h>
#include "ipfs/importer/importer.h"
#include "ipfs/merkledag/merkledag.h"
#define MAX_DATA_SIZE 262144 // 1024 * 256;
@ -14,26 +15,27 @@
* @param node the node to add to
* @returns number of bytes read
*/
size_t ipfs_import_chunk(FILE* file, struct Node* node) {
size_t ipfs_import_chunk(FILE* file, struct Node* node, struct FSRepo* fs_repo) {
unsigned char buffer[MAX_DATA_SIZE];
size_t bytes_read = fread(buffer, MAX_DATA_SIZE, 1, file);
size_t bytes_read = fread(buffer, 1, MAX_DATA_SIZE, file);
if (node->data_size == 0) {
ipfs_node_set_data(node, buffer, bytes_read);
if (bytes_read != MAX_DATA_SIZE) {
// persist
}
} else {
// create a new node, and link to the parent
struct Node* new_node = NULL;
ipfs_node_new_from_data(buffer, bytes_read, &new_node);
// persist
ipfs_merkledag_add(new_node, fs_repo);
// put link in node
struct NodeLink* new_link = NULL;
ipfs_node_link_new("", new_node->cached->hash, &new_link);
ipfs_node_add_link(node, new_link);
ipfs_node_free(new_node);
}
if (bytes_read != MAX_DATA_SIZE) {
// persist the main node
ipfs_merkledag_add(node, fs_repo);
}
return bytes_read;
}
@ -43,7 +45,7 @@ size_t ipfs_import_chunk(FILE* file, struct Node* node) {
* @param node the root node (could have links to others)
* @returns true(1) on success
*/
int ipfs_import_file(const char* fileName, struct Node** node) {
int ipfs_import_file(const char* fileName, struct Node** node, struct FSRepo* fs_repo) {
int retVal = 1;
int bytes_read = MAX_DATA_SIZE;
@ -54,7 +56,7 @@ int ipfs_import_file(const char* fileName, struct Node** node) {
// add all nodes
while ( bytes_read == MAX_DATA_SIZE) {
bytes_read = ipfs_import_chunk(file, *node);
bytes_read = ipfs_import_chunk(file, *node, fs_repo);
}
fclose(file);