More work on storage and cleanup

Added flatfs, as well as fixed some memory leaks. Valgrind across tests
now reports 0 memory leaks.
This commit is contained in:
John Jones 2016-11-28 08:09:00 -05:00
parent 63c7bd72e2
commit 50ffade515
28 changed files with 580 additions and 93 deletions

View file

@ -0,0 +1,38 @@
/**
* a datastore implementation that stores all
* objects in a 2 level directory structure in
* the local file system, regardless of the
* hierarchy of the keys. Modeled after go-ds-flatfs
*/
/**
* Given a filename (usually a long hash), derive a subdirectory name
* @param datastore_path the path to the datastore
* @param proposed_filename the filename to use
* @param derived_path the complete pathname to the directory that should contain the proposed_filename
* @param max_derived_path_length the maximum memory allocated for derived_path
* @returns true(1) on success
*/
int ipfs_flatfs_get_directory(const char* datastore_path, const char* proposed_filename,
char* derived_path, size_t max_derived_path_length);
/**
* Given the proposed filename, return the acutal filename on the disk (clean the name and add .data suffix)
* @param proposed_filename the start
* @param derived_filename the results
* @param max_derived_filename_length the buffer size
* @returns true(1) on success
*/
int ipfs_flatfs_get_filename(const char* proposed_filename, char* derived_filename, size_t max_derived_filename_length);
/**
* Combines the datastore path, the directory (derived from the filename itself), the proposed
* filename, and the suffix (.data) to build a complete filename on the disk
* @param datastore_path where the datastore is
* @param proposed_filename the filename we want to use
* @param derived_full_filename where the results will be put
* @param max_derived_filename_length the size of memory allocated for "derived_full_filename"
* @returns true(1) on success
*/
int ipfs_flatfs_get_full_filename(const char* datastore_path, const char* proposed_filename,
char* derived_full_filename, size_t max_derived_filename_length);

View file

@ -36,4 +36,6 @@ int os_utils_file_size(const char* file_name);
int os_utils_directory_writeable(const char* path);
int os_utils_directory_exists(const char* path);
#endif /* utils_h */

View file

@ -12,7 +12,7 @@
#include "swarm.h"
struct Addresses {
struct SwarmAddresses swarm;
struct SwarmAddresses* swarm;
char* api;
char* gateway;
};
@ -24,10 +24,10 @@ struct Addresses {
* @param gateway the gateway address (like "ip4/127.0.0.1/tcp/8080")
* @returns true(1) on success, otherwise false(0)
*/
int repo_config_addresses_init(struct Addresses* addresses, char* api, char* gateway);
int repo_config_addresses_new(struct Addresses** addresses, char* api, char* gateway);
/**
* clear any memory allocated by a address_init call
* clear any memory allocated by a address_new call
* @param addresses the struct
* @returns true(1)
*/

View file

@ -31,15 +31,15 @@ struct Reprovider {
};
struct RepoConfig {
struct Identity identity;
struct Datastore datastore;
struct Addresses addresses;
struct Identity* identity;
struct Datastore* datastore;
struct Addresses* addresses;
struct Mounts mounts;
struct Discovery discovery;
struct Ipns ipns;
struct BootstrapPeers peer_addresses;
//struct tour tour;
struct Gateway gateway;
struct Gateway* gateway;
//struct supernode_routing supernode_client_config;
//struct api api;
struct Reprovider reprovider;

View file

@ -28,9 +28,13 @@ struct Gateway {
char* root_redirect;
int writable;
struct PathPrefixes path_prefixes;
struct HTTPHeaders http_headers;
struct HTTPHeaders* http_headers;
};
int repo_config_gateway_http_header_init(struct HTTPHeaders* http_headers, char** headers, char** values, int num_elements);
int repo_config_gateway_new(struct Gateway** gateway);
int repo_config_gateway_free(struct Gateway* gateway);
#endif /* gateway_h */

View file

@ -23,8 +23,9 @@ struct SwarmAddresses {
*/
int repo_config_swarm_address_init(struct SwarmAddresses* swarm_addresses, char** addresses, int array_length);
int repo_config_swarm_address_new(struct SwarmAddresses** swarm_addresses);
/***
* free up memory from repo_config_swarm_address_init
* free up memory from repo_config_swarm_address_new
* @param swarm_addresses the structure
* @returns true(1)
*/