Intermidiate commit with big changes to storage formats
I am attempting to match the storage format of the reference implementation, so as to generate the same hashes.
This commit is contained in:
parent
a569159cc2
commit
914d3caaed
19 changed files with 437 additions and 85 deletions
|
@ -37,5 +37,28 @@ int ipfs_blockstore_get(const unsigned char* hash, size_t hash_length, struct Bl
|
|||
*/
|
||||
int ipfs_blockstore_put(struct Block* block, const struct FSRepo* fs_repo);
|
||||
|
||||
/***
|
||||
* Put a struct UnixFS in the blockstore
|
||||
* @param unix_fs the structure
|
||||
* @param fs_repo the repo to place the strucure in
|
||||
* @param bytes_written the number of bytes written to the blockstore
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_blockstore_put_unixfs(const struct UnixFS* unix_fs, const struct FSRepo* fs_repo, size_t* bytes_written);
|
||||
|
||||
/***
|
||||
* Find a UnixFS struct based on its hash
|
||||
* @param hash the hash to look for
|
||||
* @param hash_length the length of the hash
|
||||
* @param unix_fs the struct to fill
|
||||
* @param fs_repo where to look for the data
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_blockstore_get_unixfs(const unsigned char* hash, size_t hash_length, struct UnixFS** block, const struct FSRepo* fs_repo);
|
||||
|
||||
/**
|
||||
* Put a struct Node in the blockstore
|
||||
*/
|
||||
int ipfs_blockstore_put_node(const struct Node* node, const struct FSRepo* fs_repo, size_t* bytes_written);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -10,10 +10,11 @@
|
|||
/***
|
||||
* Adds a node to the dagService and blockService
|
||||
* @param node the node to add
|
||||
* @param cid the resultant cid that was added
|
||||
* @param fs_repo the repo to add to
|
||||
* @param bytes_written the number of bytes written
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_merkledag_add(struct Node* node, struct FSRepo* fs_repo);
|
||||
int ipfs_merkledag_add(struct Node* node, struct FSRepo* fs_repo, size_t* bytes_written);
|
||||
|
||||
/***
|
||||
* Retrieves a node from the datastore based on the cid
|
||||
|
|
|
@ -74,7 +74,7 @@ int ipfs_node_link_free(struct NodeLink * node_link);
|
|||
* @param link the link to examine
|
||||
* @returns the maximum size that should be needed
|
||||
*/
|
||||
size_t ipfs_node_link_protobuf_encode_size(struct NodeLink* link);
|
||||
size_t ipfs_node_link_protobuf_encode_size(const struct NodeLink* link);
|
||||
|
||||
/***
|
||||
* Encode a NodeLink into protobuf format
|
||||
|
@ -84,7 +84,7 @@ size_t ipfs_node_link_protobuf_encode_size(struct NodeLink* link);
|
|||
* @pram bytes_written the amount of the buffer used
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_node_link_protobuf_encode(struct NodeLink* link, unsigned char* buffer, size_t max_buffer_length, size_t* bytes_written);
|
||||
int ipfs_node_link_protobuf_encode(const struct NodeLink* link, unsigned char* buffer, size_t max_buffer_length, size_t* bytes_written);
|
||||
|
||||
/****
|
||||
* Decode from a byte array into a NodeLink
|
||||
|
@ -102,7 +102,7 @@ int ipfs_node_link_protobuf_decode(unsigned char* buffer, size_t buffer_length,
|
|||
* @param node the node to examine
|
||||
* @returns the max size of an encoded stream of bytes, if it were encoded
|
||||
*/
|
||||
size_t ipfs_node_protobuf_encode_size(struct Node* node);
|
||||
size_t ipfs_node_protobuf_encode_size(const struct Node* node);
|
||||
|
||||
/***
|
||||
* Encode a node into a protobuf byte stream
|
||||
|
@ -112,7 +112,7 @@ size_t ipfs_node_protobuf_encode_size(struct Node* node);
|
|||
* @param bytes_written how much of buffer was used
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_node_protobuf_encode(struct Node* node, unsigned char* buffer, size_t max_buffer_length, size_t* bytes_written);
|
||||
int ipfs_node_protobuf_encode(const struct Node* node, unsigned char* buffer, size_t max_buffer_length, size_t* bytes_written);
|
||||
|
||||
/***
|
||||
* Decode a stream of bytes into a Node structure
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
#define fs_repo_h
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ipfs/repo/config/config.h"
|
||||
|
||||
#include "ipfs/repo/config/config.h"
|
||||
#include "ipfs/unixfs/unixfs.h"
|
||||
#include "ipfs/merkledag/node.h"
|
||||
|
||||
/**
|
||||
* a structure to hold the repo info
|
||||
|
@ -73,4 +75,23 @@ int ipfs_repo_fsrepo_init(struct FSRepo* config);
|
|||
int ipfs_repo_fsrepo_block_write(struct Block* block, const struct FSRepo* fs_repo);
|
||||
int ipfs_repo_fsrepo_block_read(const unsigned char* hash, size_t hash_length, struct Block** block, const struct FSRepo* fs_repo);
|
||||
|
||||
/***
|
||||
* Write a unixfs to the datastore and blockstore
|
||||
* @param unix_fs the struct to write
|
||||
* @param fs_repo the repo to write to
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_repo_fsrepo_unixfs_write(const struct UnixFS* unix_fs, const struct FSRepo* fs_repo, size_t* bytes_written);
|
||||
int ipfs_repo_fsrepo_unixfs_read(const unsigned char* hash, size_t hash_length, struct UnixFS** unix_fs, const struct FSRepo* fs_repo);
|
||||
|
||||
/***
|
||||
* Write a struct Node to the datastore and blockstore
|
||||
* @param node the struct to write
|
||||
* @param fs_repo the repo to write to
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_repo_fsrepo_node_write(const struct Node* unix_fs, const struct FSRepo* fs_repo, size_t* bytes_written);
|
||||
int ipfs_repo_fsrepo_node_read(const unsigned char* hash, size_t hash_length, struct Node** node, const struct FSRepo* fs_repo);
|
||||
|
||||
|
||||
#endif /* fs_repo_h */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
enum UnixFSFormatType { RAW, FILE, DIRECTORY, METADATA, SYMLINK };
|
||||
enum UnixFSFormatType { RAW, UNIXFS_FILE, DIRECTORY, METADATA, SYMLINK };
|
||||
|
||||
struct UnixFSData {
|
||||
enum UnixFSFormatType type;
|
||||
|
|
|
@ -43,8 +43,10 @@ struct UnixFS {
|
|||
enum UnixFSDataType data_type;
|
||||
size_t bytes_size; // the size of the bytes array
|
||||
unsigned char* bytes; // an array of bytes
|
||||
size_t file_size; // the file size
|
||||
// size_t file_size; // the file size - I mimick this one
|
||||
struct UnixFSBlockSizeNode* block_size_head; // a linked list of block sizes
|
||||
unsigned char* hash; // not saved
|
||||
size_t hash_length; // not saved
|
||||
};
|
||||
|
||||
struct UnixFSMetaData {
|
||||
|
@ -65,6 +67,15 @@ int ipfs_unixfs_new(struct UnixFS** obj);
|
|||
*/
|
||||
int ipfs_unixfs_free(struct UnixFS* obj);
|
||||
|
||||
/***
|
||||
* Write data to data section of a UnixFS stuct. NOTE: this also calculates a sha256 hash
|
||||
* @param data the data to write
|
||||
* @param data_length the length of the data
|
||||
* @param unix_fs the struct to add to
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_unixfs_add_data(unsigned char* data, size_t data_length, struct UnixFS* unix_fs);
|
||||
|
||||
/**
|
||||
* Protobuf functions
|
||||
*/
|
||||
|
@ -74,7 +85,7 @@ int ipfs_unixfs_free(struct UnixFS* obj);
|
|||
* @param obj what will be encoded
|
||||
* @returns the size of the buffer necessary to encode the object
|
||||
*/
|
||||
size_t ipfs_unixfs_protobuf_encode_size(struct UnixFS* obj);
|
||||
size_t ipfs_unixfs_protobuf_encode_size(const struct UnixFS* obj);
|
||||
|
||||
/***
|
||||
* Encode a UnixFS object into protobuf format
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue