2016-11-02 18:09:38 +00:00
|
|
|
//
|
|
|
|
// datastore.c
|
|
|
|
// c-ipfs
|
|
|
|
//
|
|
|
|
// Created by John Jones on 11/2/16.
|
|
|
|
// Copyright © 2016 JMJAtlanta. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "ipfs/repo/config/datastore.h"
|
|
|
|
#include "ipfs/os/utils.h"
|
|
|
|
|
|
|
|
/***
|
|
|
|
* initialize the structure of the datastore
|
|
|
|
* @param datastore the struct to initialize
|
|
|
|
* @returns true(1) on success
|
|
|
|
*/
|
2016-11-17 20:07:59 +00:00
|
|
|
int ipfs_repo_config_datastore_init(struct Datastore* datastore, char* config_root) {
|
2016-11-02 18:09:38 +00:00
|
|
|
unsigned long stringLength = strlen(config_root) + 12;
|
|
|
|
datastore->path = malloc(sizeof(char) * stringLength);
|
2016-11-17 20:07:59 +00:00
|
|
|
os_utils_filepath_join(config_root, "datastore", datastore->path, stringLength);
|
|
|
|
datastore->type = "lmdb";
|
2016-11-02 18:09:38 +00:00
|
|
|
datastore->storage_max = "10GB";
|
|
|
|
datastore->storage_gc_watermark = 90;
|
|
|
|
datastore->gc_period = "1h";
|
|
|
|
datastore->hash_on_read = 0;
|
|
|
|
datastore->bloom_filter_size = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-11-17 20:07:59 +00:00
|
|
|
/***
|
|
|
|
* 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) {
|
|
|
|
*datastore = malloc(sizeof(struct Datastore));
|
|
|
|
if (*datastore == NULL)
|
|
|
|
return 0;
|
|
|
|
(*datastore)->path = NULL;
|
2016-11-30 16:46:41 +00:00
|
|
|
(*datastore)->handle = NULL;
|
2016-11-17 20:07:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
/***
|
|
|
|
* deallocate the memory and clear resources from a datastore_init
|
|
|
|
* @param datastore the struct to deallocate
|
|
|
|
* @returns true(1)
|
|
|
|
*/
|
2016-11-17 20:07:59 +00:00
|
|
|
int ipfs_repo_config_datastore_free(struct Datastore* datastore) {
|
|
|
|
if (datastore != NULL)
|
|
|
|
{
|
|
|
|
if (datastore->path != NULL)
|
|
|
|
free(datastore->path);
|
|
|
|
free(datastore);
|
|
|
|
}
|
2016-11-02 18:09:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|