2016-11-17 20:07:59 +00:00
|
|
|
/***
|
|
|
|
* a thin wrapper over a datastore for getting and putting block objects
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __IPFS_BLOCKS_BLOCKSTORE_H__
|
2016-12-14 17:07:43 +00:00
|
|
|
#define __IPFS_BLOCKS_BLOCKSTORE_H__
|
|
|
|
|
|
|
|
#include "ipfs/cid/cid.h"
|
|
|
|
#include "ipfs/repo/fsrepo/fs_repo.h"
|
2016-11-17 20:07:59 +00:00
|
|
|
|
2017-07-24 19:56:30 +00:00
|
|
|
struct BlockstoreContext {
|
|
|
|
const struct FSRepo* fs_repo;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Blockstore {
|
|
|
|
struct BlockstoreContext* blockstoreContext;
|
|
|
|
int (*Delete)(const struct BlockstoreContext* context, struct Cid* cid);
|
|
|
|
int (*Has)(const struct BlockstoreContext* context, struct Cid* cid);
|
2017-07-27 13:38:57 +00:00
|
|
|
/**
|
|
|
|
* Retrieve a block from the blockstore
|
|
|
|
*/
|
2017-07-24 19:56:30 +00:00
|
|
|
int (*Get)(const struct BlockstoreContext* context, struct Cid* cid, struct Block** block);
|
2017-09-13 17:40:48 +00:00
|
|
|
int (*Put)(const struct BlockstoreContext* context, struct Block* block, size_t* bytes_written);
|
2017-07-24 19:56:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/***
|
|
|
|
* Create a new Blockstore struct
|
|
|
|
* @param fs_repo the FSRepo to use
|
|
|
|
* @returns the new Blockstore struct, or NULL if there was a problem.
|
|
|
|
*/
|
|
|
|
struct Blockstore* ipfs_blockstore_new(const struct FSRepo* fs_repo);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release resources of a Blockstore struct
|
|
|
|
* @param blockstore the struct to free
|
|
|
|
* @returns true(1)
|
|
|
|
*/
|
|
|
|
int ipfs_blockstore_free(struct Blockstore* blockstore);
|
|
|
|
|
2016-11-17 20:07:59 +00:00
|
|
|
/**
|
|
|
|
* Delete a block based on its Cid
|
2017-07-24 19:56:30 +00:00
|
|
|
* @param context the context
|
2016-11-17 20:07:59 +00:00
|
|
|
* @param cid the Cid to look for
|
|
|
|
* @param returns true(1) on success
|
|
|
|
*/
|
2017-07-24 19:56:30 +00:00
|
|
|
int ipfs_blockstore_delete(const struct BlockstoreContext* context, struct Cid* cid);
|
2016-11-17 20:07:59 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
* Determine if the Cid can be found
|
2017-07-24 19:56:30 +00:00
|
|
|
* @param context the context
|
2016-11-17 20:07:59 +00:00
|
|
|
* @param cid the Cid to look for
|
|
|
|
* @returns true(1) if found
|
|
|
|
*/
|
2017-07-24 19:56:30 +00:00
|
|
|
int ipfs_blockstore_has(const struct BlockstoreContext* context, struct Cid* cid);
|
2016-11-17 20:07:59 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
* Find a block based on its Cid
|
2017-07-24 19:56:30 +00:00
|
|
|
* @param context the context
|
2016-11-17 20:07:59 +00:00
|
|
|
* @param cid the Cid to look for
|
|
|
|
* @param block where to put the data to be returned
|
|
|
|
* @returns true(1) on success
|
|
|
|
*/
|
2017-07-24 19:56:30 +00:00
|
|
|
int ipfs_blockstore_get(const struct BlockstoreContext* context, struct Cid* cid, struct Block** block);
|
2016-11-17 20:07:59 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
* Put a block in the blockstore
|
|
|
|
* @param block the block to store
|
|
|
|
* @returns true(1) on success
|
|
|
|
*/
|
2017-09-13 17:40:48 +00:00
|
|
|
int ipfs_blockstore_put(const struct BlockstoreContext* context, struct Block* block, size_t* bytes_written);
|
2016-11-17 20:07:59 +00:00
|
|
|
|
2016-12-23 14:37:43 +00:00
|
|
|
/***
|
|
|
|
* 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
|
|
|
|
*/
|
2017-04-20 22:56:03 +00:00
|
|
|
int ipfs_blockstore_put_node(const struct HashtableNode* node, const struct FSRepo* fs_repo, size_t* bytes_written);
|
|
|
|
int ipfs_blockstore_get_node(const unsigned char* hash, size_t hash_length, struct HashtableNode** node, const struct FSRepo* fs_repo);
|
2016-11-17 20:07:59 +00:00
|
|
|
|
|
|
|
#endif
|