More storage implementation
Successfully writing to lightningdb. Now to pull it back out. Also need to write to the blockstore.
This commit is contained in:
parent
4626b69381
commit
b462d9ef53
29 changed files with 448 additions and 123 deletions
|
@ -5,9 +5,12 @@
|
|||
#ifndef __IPFS_BLOCKS_BLOCK_H__
|
||||
#define __IPFS_BLOCKS_BLOCK_H__
|
||||
|
||||
#include "ipfs/cid/cid.h"
|
||||
|
||||
struct Block {
|
||||
struct Cid* cid;
|
||||
unsigned char* data;
|
||||
size_t data_length;
|
||||
};
|
||||
|
||||
/***
|
||||
|
@ -17,7 +20,7 @@ struct Block {
|
|||
* @param block a pointer to the struct Block that will be created
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_blocks_block_new(unsigned char* data, size_t data_size, struct Block** block);
|
||||
int ipfs_blocks_block_new(const unsigned char* data, size_t data_size, struct Block** block);
|
||||
|
||||
/***
|
||||
* Free resources used by the creation of a block
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
* @param cid the Cid to look for
|
||||
* @param returns true(1) on success
|
||||
*/
|
||||
int ipfs_blockstore_delete(struct Cid* cid);
|
||||
int ipfs_blockstore_delete(struct Cid* cid, struct FSRepo* fs_repo);
|
||||
|
||||
/***
|
||||
* Determine if the Cid can be found
|
||||
* @param cid the Cid to look for
|
||||
* @returns true(1) if found
|
||||
*/
|
||||
int ipfs_blockstore_has(struct Cid* cid);
|
||||
int ipfs_blockstore_has(struct Cid* cid, struct FSRepo* fs_repo);
|
||||
|
||||
/***
|
||||
* Find a block based on its Cid
|
||||
|
@ -25,14 +25,14 @@ int ipfs_blockstore_has(struct Cid* cid);
|
|||
* @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);
|
||||
int ipfs_blockstore_get(struct Cid* cid, struct Block* block, 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);
|
||||
int ipfs_blockstore_put(struct Block* block, struct FSRepo* fs_repo);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef __IPFS_CID_CID_H
|
||||
#define __IPFS_CID_CID_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define CID_PROTOBUF 0x70
|
||||
#define CID_CBOR 0x71
|
||||
#define CID_RAW 0x72
|
||||
|
|
14
include/ipfs/datastore/key.h
Normal file
14
include/ipfs/datastore/key.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef __IPFS_DATASTORE_KEY_H__
|
||||
#define __IPFS_DATASTORE_KEY_H__
|
||||
|
||||
/**
|
||||
* Constructs a new "clean" key. Will remove things like slashes
|
||||
* @param input the input
|
||||
* @param output the output
|
||||
* @param max_output_length the amount of memory allocated for output
|
||||
* @param actual_output_length the amount of bytes written to output
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_datastore_key_new(const char* input, char* output, size_t max_output_length, size_t* actual_output_length);
|
||||
|
||||
#endif
|
|
@ -72,7 +72,7 @@ int config_path(char* config_root, char* extension, char* result, int max_len);
|
|||
* @param num_bits_for_keypair number of bits for the key pair
|
||||
* @returns true(1) on success, otherwise 0
|
||||
*/
|
||||
int repo_config_init(struct RepoConfig* config, unsigned int num_bits_for_keypair, char* repo_path);
|
||||
int ipfs_repo_config_init(struct RepoConfig* config, unsigned int num_bits_for_keypair, char* repo_path);
|
||||
|
||||
/***
|
||||
* Initialize memory for a RepoConfig struct
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define __DATASTORE_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ipfs/blocks/block.h"
|
||||
|
||||
//const char* datastore_default_directory = "datastore";
|
||||
|
||||
|
@ -19,6 +20,8 @@ struct Datastore {
|
|||
// function pointers for datastore operations
|
||||
int (*datastore_open)(int argc, char** argv, struct Datastore* datastore);
|
||||
int (*datastore_close)(int argc, char** argv, struct Datastore* datastore);
|
||||
int (*datastore_put)(const char* key, struct Block* block, struct Datastore* datastore);
|
||||
//int (*datastore_get)(const char* key, struct Block* block);
|
||||
// a handle to the datastore "context" used by the datastore
|
||||
void* handle;
|
||||
};
|
||||
|
|
|
@ -16,13 +16,11 @@ struct FSRepo {
|
|||
char* path;
|
||||
struct IOCloser* lock_file;
|
||||
struct RepoConfig* config;
|
||||
struct Datastore* data_store;
|
||||
};
|
||||
|
||||
/**
|
||||
* opens a fsrepo
|
||||
* @param repo_path the path to the repo
|
||||
* @param repo where to store the repo info
|
||||
* @param repo the repo struct. Should contain the path. This method will do the rest
|
||||
* @return 0 if there was a problem, otherwise 1
|
||||
*/
|
||||
int ipfs_repo_fsrepo_open(struct FSRepo* repo);
|
||||
|
@ -43,10 +41,12 @@ int fs_repo_is_initialized(char* repo_path);
|
|||
int fs_repo_write_config_file(char* path, struct RepoConfig* config);
|
||||
|
||||
/**
|
||||
* Initializes a new FSRepo at the given path with the provided config
|
||||
* @param repo_path the path to use
|
||||
* @param config the information for the config file
|
||||
* @returns true(1) on success
|
||||
* constructs the FSRepo struct.
|
||||
* Remember: ipfs_repo_fsrepo_free must be called
|
||||
* @param repo_path the path to the repo
|
||||
* @param config the optional config file. NOTE: if passed, fsrepo_free will free resources of the RepoConfig.
|
||||
* @param repo the struct to allocate memory for
|
||||
* @returns false(0) if something bad happened, otherwise true(1)
|
||||
*/
|
||||
int ipfs_repo_fsrepo_new(char* repo_path, struct RepoConfig* config, struct FSRepo** fs_repo);
|
||||
|
||||
|
|
|
@ -27,4 +27,11 @@ int repo_fsrepro_lmdb_open(int argc, char** argv, struct Datastore* datastore);
|
|||
*/
|
||||
int repo_fsrepo_lmdb_close(int argc, char** argv, struct Datastore* datastore);
|
||||
|
||||
/***
|
||||
* Creates the directory
|
||||
* @param datastore contains the path that needs to be created
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int repo_fsrepo_lmdb_create_directory(struct Datastore* datastore);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
#ifndef __REPO_H__
|
||||
#define __REPO_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "config/config.h"
|
||||
|
||||
/**
|
||||
* Get the config
|
||||
* @param config a place to put the buffer (must have been pre-allocated)
|
||||
* @returns 0 on error
|
||||
*/
|
||||
int repo_get_config(struct RepoConfig* config);
|
||||
|
||||
/**
|
||||
* Retrieves the config
|
||||
* @param config a place to get the information
|
||||
* @returns 0 on error
|
||||
*/
|
||||
int repo_set_config(struct RepoConfig* config);
|
||||
int repo_set_config_key(char* key, void* value);
|
||||
int repo_get_config_key(char* key, void* value);
|
||||
int repo_get_datastore(struct Datastore* datastore);
|
||||
int repo_get_storage_usage(uint64_t* usage);
|
||||
|
||||
#endif // __REPO_H__
|
Loading…
Add table
Add a link
Reference in a new issue