Moved datastore interface from ipfs to libp2p

This commit is contained in:
John Jones 2017-04-06 09:33:28 -05:00
parent 950ad31760
commit 94d6005587
23 changed files with 21 additions and 432 deletions

View file

@ -1,7 +1,7 @@
#ifndef __CONFIG_H__
#define __CONFIG_H__
#include "datastore.h"
#include "libp2p/db/datastore.h"
#include "identity.h"
#include "swarm.h"
#include "bootstrap_peers.h"

View file

@ -1,62 +0,0 @@
#ifndef __DATASTORE_H__
#define __DATASTORE_H__
#include <stdint.h>
#include "ipfs/blocks/block.h"
//const char* datastore_default_directory = "datastore";
enum DatastoreCursorOp { CURSOR_FIRST, CURSOR_NEXT };
struct Datastore {
char* type;
char* path;
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)(struct Datastore* datastore);
int (*datastore_put)(const unsigned char* key, size_t key_size, unsigned char* data, size_t data_length, const struct Datastore* datastore);
int (*datastore_get)(const char* key, size_t key_size,
unsigned char* data, size_t max_data_length, size_t* data_length,
const struct Datastore* datastore);
int (*datastore_cursor_open)(struct Datastore* datastore);
int (*datastore_cursor_close)(struct Datastore* datastore);
int (*datastore_cursor_get)(unsigned char** key, int* key_length, unsigned char** value, int* value_length, enum DatastoreCursorOp op, struct Datastore* datastore);
// generic connection and status variables for the datastore
void* handle; // a handle to the database
void* cursor; // a current cursor
};
/***
* 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 ipfs_repo_config_datastore_init(struct Datastore* datastore, const 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 ipfs_repo_config_datastore_free(struct Datastore* datastore);
#endif

View file

@ -9,6 +9,7 @@
#include "ipfs/repo/config/config.h"
#include "ipfs/unixfs/unixfs.h"
#include "ipfs/merkledag/node.h"
#include "ipfs/blocks/block.h"
/**
* a structure to hold the repo info

View file

@ -1,7 +1,7 @@
#ifndef __FS_REPO_LMDB_DATASTORE_H__
#define __FS_REPO_LMDB_DATASTORE_H__
#include "ipfs/repo/config/datastore.h"
#include "libp2p/db/datastore.h"
/***
* Places the LMDB methods into the datastore's function pointers