The beginnings of datastore

A lot of code cleanup, plus beginning the implementation of a datastore.
This commit is contained in:
John Jones 2016-11-17 15:07:59 -05:00
parent 0b765481da
commit c64a700223
28 changed files with 1169 additions and 132 deletions

View file

@ -0,0 +1,29 @@
/***
* IPFS has the notion of storage blocks.
*/
#ifndef __IPFS_BLOCKS_BLOCK_H__
#define __IPFS_BLOCKS_BLOCK_H__
struct Block {
struct Cid* cid;
unsigned char* data;
};
/***
* Create a new block based on the incoming data.
* @param data the data to base the block on
* @param data_size the length of the data array
* @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);
/***
* Free resources used by the creation of a block
* @param block the block to free
* @returns true(1) on success
*/
int ipfs_blocks_block_free(struct Block* block);
#endif

View file

@ -0,0 +1,38 @@
/***
* a thin wrapper over a datastore for getting and putting block objects
*/
#ifndef __IPFS_BLOCKS_BLOCKSTORE_H__
#ifndef __IPFS_BLOCKS_BLOCKSTORE_H__
/**
* Delete a block based on its Cid
* @param cid the Cid to look for
* @param returns true(1) on success
*/
int ipfs_blockstore_delete(struct Cid* cid);
/***
* 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);
/***
* Find a block based on its Cid
* @param cid the Cid to look for
* @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);
/***
* Put a block in the blockstore
* @param block the block to store
* @returns true(1) on success
*/
int ipfs_blockstore_put(struct Block* block);
#endif

View file

@ -13,7 +13,7 @@
* @param variable the variable to look for
* @returns the results
*/
char* os_utils_getenv(char* variable);
char* os_utils_getenv(const char* variable);
/**
* get the user's home directory
@ -28,10 +28,12 @@ char* os_utils_get_homedir();
* @param results where to put the results
* @param max_len throw an error if the total is longer than max_len
*/
int os_utils_filepath_join(char* root, char* extension, char* results, unsigned long max_len);
int os_utils_filepath_join(const char* root, const char* extension, char* results, unsigned long max_len);
int os_utils_file_exists(char* file_name);
int os_utils_file_exists(const char* file_name);
int os_utils_directory_writeable(char* path);
int os_utils_file_size(const char* file_name);
int os_utils_directory_writeable(const char* path);
#endif /* utils_h */

View file

@ -74,11 +74,18 @@ int config_path(char* config_root, char* extension, char* result, int max_len);
*/
int repo_config_init(struct RepoConfig* config, unsigned int num_bits_for_keypair, char* repo_path);
/***
* Initialize memory for a RepoConfig struct
* @param config the structure to initialize
* @returns true(1) on success
*/
int ipfs_repo_config_new(struct RepoConfig** config);
/***
* free all resources that were allocated to store config information
* @param config the config
* @returns true(1)
*/
int repo_config_free(struct RepoConfig* config);
int ipfs_repo_config_free(struct RepoConfig* config);
#endif

View file

@ -11,27 +11,41 @@ struct Datastore {
char* storage_max;
int storage_gc_watermark;
char* gc_period;
char* params;
int no_sync;
int hash_on_read;
int bloom_filter_size;
// 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);
// a handle to the datastore "context" used by the datastore
void* handle;
};
/***
* initialize the structure of the datastore
* Initialize the structure of the datastore to default settings. Used for
* creating a new datastore on the disk.
* @param datastore the struct to initialize
* @param config_root the path to the root of IPFS
* @returns true(1) on success
*/
int repo_config_datastore_init(struct Datastore* datastore, char* config_root);
int ipfs_repo_config_datastore_init(struct Datastore* datastore, char* config_root);
/***
* initialize the structure of the datastore
* @param datastore the struct to initialize
* @returns true(1) on success
*/
int ipfs_repo_config_datastore_new(struct Datastore** datastore);
/***
* deallocate the memory and clear resources from a datastore_init
* @param datastore the struct to deallocate
* @returns true(1)
*/
int repo_config_datastore_free(struct Datastore* datastore);
int ipfs_repo_config_datastore_free(struct Datastore* datastore);
#endif

View file

@ -19,7 +19,15 @@ struct Identity {
/***
* initializes a new keypair, and puts it in the Identity struct
*/
int repo_config_identity_new(struct Identity* identity, unsigned long num_bits_for_keypair);
int repo_config_identity_init(struct Identity* identity, unsigned long num_bits_for_keypair);
/***
* Build a RsaPrivateKey struct from a base64 string of the private key
* @param identity where to put the new struct
* @param base64 the base 64 encoded private key in DER format
* @returns true(1) on success
*/
int repo_config_identity_build_private_key(struct Identity* identity, const char* base64);
/***
* Frees resources held by Identity
@ -28,4 +36,11 @@ int repo_config_identity_new(struct Identity* identity, unsigned long num_bits_f
*/
int repo_config_identity_free(struct Identity* identity);
/***
* Initializes a new identity struct that will need to be identity_free'd
* @param identity the identity to allocate memory for
* @returns true(1) on success
*/
int repo_config_identity_new(struct Identity** identity);
#endif /* identity_h */

View file

@ -15,7 +15,7 @@ struct FSRepo {
int closed;
char* path;
struct IOCloser* lock_file;
struct Config* config;
struct RepoConfig* config;
struct Datastore* data_store;
};
@ -25,7 +25,7 @@ struct FSRepo {
* @param repo where to store the repo info
* @return 0 if there was a problem, otherwise 1
*/
int fs_repo_open(char* repo_path, struct FSRepo* repo);
int ipfs_repo_fsrepo_open(struct FSRepo* repo);
/***
* checks to see if the repo is initialized
@ -48,7 +48,20 @@ int fs_repo_write_config_file(char* path, struct RepoConfig* config);
* @param config the information for the config file
* @returns true(1) on success
*/
int fs_repo_init(char* repo_path, struct RepoConfig* config);
int ipfs_repo_fsrepo_new(char* repo_path, struct RepoConfig* config, struct FSRepo** fs_repo);
/***
* Free all resources used by this struct
* @param repo the repo to clean up
* @returns true(1) on success
*/
int ipfs_repo_fsrepo_free(struct FSRepo* config);
/***
* Initialize a new repo with the specified configuration
* @param config the information in order to build the repo
* @returns true(1) on success
*/
int ipfs_repo_fsrepo_init(struct FSRepo* config);
#endif /* fs_repo_h */

View file

@ -0,0 +1,30 @@
#ifndef __FS_REPO_LMDB_DATASTORE_H__
#define __FS_REPO_LMDB_DATASTORE_H__
#include "ipfs/repo/config/datastore.h"
/***
* Places the LMDB methods into the datastore's function pointers
* @param datastore the datastore to fill
* @returns true(1) on success;
*/
int repo_fsrepo_lmdb_cast(struct Datastore* datastore);
/**
* Open an lmdb database with the given parameters.
* Note: for now, the parameters are not used
* @param argc number of parameters in the following array
* @param argv an array of parameters
*/
int repo_fsrepro_lmdb_open(int argc, char** argv, struct Datastore* datastore);
/***
* Close an LMDB database
* NOTE: for now, argc and argv are not used
* @param argc number of parameters in the argv array
* @param argv parameters to be passed in
* @param datastore the datastore struct that contains information about the opened database
*/
int repo_fsrepo_lmdb_close(int argc, char** argv, struct Datastore* datastore);
#endif