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:
parent
88d177cf4a
commit
033dd767b4
20 changed files with 564 additions and 57 deletions
|
@ -1,5 +1,6 @@
|
|||
/***
|
||||
* IPFS has the notion of storage blocks.
|
||||
* Raw data with a multihash key (the Cid)
|
||||
*/
|
||||
|
||||
#ifndef __IPFS_BLOCKS_BLOCK_H__
|
||||
|
@ -20,7 +21,9 @@ struct Block {
|
|||
* @param block a pointer to the struct Block that will be created
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_blocks_block_new(const unsigned char* data, size_t data_size, struct Block** block);
|
||||
int ipfs_blocks_block_new(struct Block** block);
|
||||
|
||||
int ipfs_blocks_block_add_data(const unsigned char* data, size_t data_size, struct Block* block);
|
||||
|
||||
/***
|
||||
* Free resources used by the creation of a block
|
||||
|
@ -29,4 +32,30 @@ int ipfs_blocks_block_new(const unsigned char* data, size_t data_size, struct Bl
|
|||
*/
|
||||
int ipfs_blocks_block_free(struct Block* block);
|
||||
|
||||
/**
|
||||
* Determine the approximate size of an encoded block
|
||||
* @param block the block to measure
|
||||
* @returns the approximate size needed to encode the protobuf
|
||||
*/
|
||||
size_t ipfs_blocks_block_protobuf_encode_size(const struct Block* block);
|
||||
|
||||
/**
|
||||
* Encode the Block into protobuf format
|
||||
* @param block the block to encode
|
||||
* @param buffer the buffer to fill
|
||||
* @param max_buffer_size the max size of the buffer
|
||||
* @param bytes_written the number of bytes used
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_blocks_block_protobuf_encode(const struct Block* block, unsigned char* buffer, size_t max_buffer_size, size_t* bytes_written);
|
||||
|
||||
/***
|
||||
* Decode from a protobuf stream into a Block struct
|
||||
* @param buffer the buffer to pull from
|
||||
* @param buffer_length the length of the buffer
|
||||
* @param block the block to fill
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_blocks_block_protobuf_decode(const unsigned char* buffer, const size_t buffer_length, struct Block** block);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
*/
|
||||
|
||||
#ifndef __IPFS_BLOCKS_BLOCKSTORE_H__
|
||||
#ifndef __IPFS_BLOCKS_BLOCKSTORE_H__
|
||||
#define __IPFS_BLOCKS_BLOCKSTORE_H__
|
||||
|
||||
#include "ipfs/cid/cid.h"
|
||||
#include "ipfs/repo/fsrepo/fs_repo.h"
|
||||
|
||||
/**
|
||||
* Delete a block based on its Cid
|
||||
|
@ -25,14 +28,14 @@ int ipfs_blockstore_has(struct Cid* cid, struct FSRepo* fs_repo);
|
|||
* @param block where to put the data to be returned
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_blockstore_get(struct Cid* cid, struct Block* block, struct FSRepo* fs_repo);
|
||||
int ipfs_blockstore_get(const struct Cid* cid, struct Block** block, const struct FSRepo* fs_repo);
|
||||
|
||||
/***
|
||||
* Put a block in the blockstore
|
||||
* @param block the block to store
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_blockstore_put(struct Block* block, struct FSRepo* fs_repo);
|
||||
int ipfs_blockstore_put(struct Block* block, const struct FSRepo* fs_repo);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue