Removed compiler warnings, starting to import large files
This commit is contained in:
parent
9ec06749f2
commit
bf0cbfb412
21 changed files with 143 additions and 82 deletions
2
Makefile
2
Makefile
|
@ -8,6 +8,7 @@ all:
|
|||
cd cmd; make all;
|
||||
cd commands; make all;
|
||||
cd core; make all;
|
||||
cd importer; make all;
|
||||
cd merkledag; make all;
|
||||
cd multibase; make all;
|
||||
cd node; make all;
|
||||
|
@ -24,6 +25,7 @@ clean:
|
|||
cd cmd; make clean;
|
||||
cd commands; make clean;
|
||||
cd core; make clean;
|
||||
cd importer; make clean;
|
||||
cd merkledag; make clean;
|
||||
cd multibase; make clean;
|
||||
cd node; make clean;
|
||||
|
|
|
@ -30,7 +30,7 @@ int ipfs_cid_protobuf_encode(struct Cid* cid, unsigned char* buffer, size_t buff
|
|||
*bytes_written += bytes_used;
|
||||
retVal = protobuf_encode_varint(2, ipfs_cid_message_fields[1], cid->codec, &buffer[*bytes_written], buffer_length - (*bytes_written), &bytes_used);
|
||||
*bytes_written += bytes_used;
|
||||
retVal = protobuf_encode_length_delimited(3, ipfs_cid_message_fields[2], cid->hash, cid->hash_length, &buffer[*bytes_written], buffer_length - (*bytes_written), &bytes_used);
|
||||
retVal = protobuf_encode_length_delimited(3, ipfs_cid_message_fields[2], (char*)cid->hash, cid->hash_length, &buffer[*bytes_written], buffer_length - (*bytes_written), &bytes_used);
|
||||
*bytes_written += bytes_used;
|
||||
}
|
||||
return 1;
|
||||
|
@ -68,7 +68,7 @@ int ipfs_cid_protobuf_decode(unsigned char* buffer, size_t buffer_length, struct
|
|||
pos += bytes_read;
|
||||
break;
|
||||
case (3):
|
||||
retVal = protobuf_decode_length_delimited(&buffer[pos], buffer_length - pos, &hash, &hash_length, &bytes_read);
|
||||
retVal = protobuf_decode_length_delimited(&buffer[pos], buffer_length - pos, (char**)&hash, &hash_length, &bytes_read);
|
||||
if (retVal == 0)
|
||||
return 0;
|
||||
pos += bytes_read;
|
||||
|
|
|
@ -34,9 +34,9 @@ int initialize_ipns_keyspace(struct FSRepo* repo) {
|
|||
return 0;
|
||||
//TODO: make a new node, then close it
|
||||
//TODO: setup offline routing on new node
|
||||
struct IpfsNode* ipfs_node;
|
||||
struct Context* ctx;
|
||||
struct BuildCfg* bld_cfg;
|
||||
struct IpfsNode* ipfs_node = NULL;
|
||||
struct Context* ctx = NULL;
|
||||
struct BuildCfg* bld_cfg = NULL;
|
||||
//TODO: see line 185 of init.go, what does core.BldCfg{Repo: r} do? BldCfg is a structure
|
||||
retVal = ipfs_core_builder_new_node(ctx, bld_cfg, ipfs_node);
|
||||
//return namesys_initialize_keyspace(ctx, ipfs_node->DAG, ipfs_node->Namesys, ipfs_node->pinning, ipfs_node->private_key);
|
||||
|
@ -88,7 +88,8 @@ int init_run(struct Request* request) {
|
|||
// TODO: check parameters for logic errors
|
||||
// TODO: Initialize
|
||||
struct RepoConfig* conf;
|
||||
int retVal = ipfs_repo_config_new(&conf);
|
||||
if (ipfs_repo_config_new(&conf) == 0)
|
||||
return 0;
|
||||
// TODO: handle files in request
|
||||
// do the heavy lifting
|
||||
int num_bits_for_key_pair = request->cmd.options[0]->default_int_val;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_datastore_helper_ds_key_from_binary(unsigned char* binary_array, size_t array_length,
|
||||
char* results, size_t max_results_length, size_t* results_length) {
|
||||
unsigned char* results, size_t max_results_length, size_t* results_length) {
|
||||
|
||||
size_t encoded_length = libp2p_crypto_encoding_base32_encode_size(array_length);
|
||||
if (encoded_length > max_results_length)
|
||||
|
|
18
importer/Makefile
Normal file
18
importer/Makefile
Normal file
|
@ -0,0 +1,18 @@
|
|||
CC = gcc
|
||||
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -Wall
|
||||
|
||||
ifdef DEBUG
|
||||
CFLAGS += -g3
|
||||
endif
|
||||
|
||||
LFLAGS =
|
||||
DEPS =
|
||||
OBJS = importer.o
|
||||
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
|
@ -4,24 +4,35 @@
|
|||
|
||||
#define MAX_DATA_SIZE 262144 // 1024 * 256;
|
||||
|
||||
/***
|
||||
* Imports OS files into the datastore
|
||||
*/
|
||||
|
||||
/**
|
||||
* read the next chunk of bytes, create a node, and add a link to the node in the passed-in node
|
||||
* @param file the file handle
|
||||
* @param node the node to add to
|
||||
* @returns number of bytes read
|
||||
*/
|
||||
int ipfs_import_chunk(FILE* file, struct Node* node) {
|
||||
size_t ipfs_import_chunk(FILE* file, struct Node* node) {
|
||||
unsigned char buffer[MAX_DATA_SIZE];
|
||||
size_t bytes_read = fread(buffer, MAX_DATA_SIZE, 1, file);
|
||||
if (node->data_size == 0) {
|
||||
Node_Set_Data(node, buffer, bytes_read);
|
||||
ipfs_node_set_data(node, buffer, bytes_read);
|
||||
if (bytes_read != MAX_DATA_SIZE) {
|
||||
// persist
|
||||
}
|
||||
} else {
|
||||
// create a new node, and link to the parent
|
||||
struct Node* new_node = N_Create_From_Data(buffer, bytes_read);
|
||||
struct Node* new_node = NULL;
|
||||
ipfs_node_new_from_data(buffer, bytes_read, &new_node);
|
||||
// persist
|
||||
|
||||
// put link in node
|
||||
Node_Add_Link(node, Create_Link("", new_node->cached->hash));
|
||||
Node_Delete(new_node);
|
||||
struct NodeLink* new_link = NULL;
|
||||
ipfs_node_link_new("", new_node->cached->hash, &new_link);
|
||||
ipfs_node_add_link(node, new_link);
|
||||
ipfs_node_free(new_node);
|
||||
}
|
||||
return bytes_read;
|
||||
}
|
||||
|
@ -34,12 +45,17 @@ int ipfs_import_chunk(FILE* file, struct Node* node) {
|
|||
*/
|
||||
int ipfs_import_file(const char* fileName, struct Node** node) {
|
||||
int retVal = 1;
|
||||
int bytes_read = MAX_DATA_SIZE;
|
||||
|
||||
FILE* file = fopen(fileName, "rb");
|
||||
*node = (struct Node)malloc(sizeof(struct Node));
|
||||
retVal = ipfs_node_new(node);
|
||||
if (retVal == 0)
|
||||
return 0;
|
||||
|
||||
// add all nodes
|
||||
while (ipfs_import_chunk(file, *node) == MAX_DATA_SIZE) {}
|
||||
while ( bytes_read == MAX_DATA_SIZE) {
|
||||
bytes_read = ipfs_import_chunk(file, *node);
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_datastore_helper_ds_key_from_binary(unsigned char* binary_array, size_t array_length,
|
||||
char* results, size_t max_results_length, size_t* results_length);
|
||||
unsigned char* results, size_t max_results_length, size_t* results_length);
|
||||
|
||||
/**
|
||||
* Generate a binary array based on the passed in datastore key
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef __IPFS_IMPORTER_IMPORTER_H__
|
||||
#define __IPFS_IMPORTER_IMPORTER_H__
|
||||
|
||||
#include "ipfs/node/node.h"
|
||||
|
||||
/**
|
||||
* Creates a node based on an incoming file
|
||||
* @param file_name the file to import
|
||||
|
|
|
@ -56,6 +56,34 @@ int ipfs_node_link_free(struct NodeLink * node_link);
|
|||
* Node protobuf functions
|
||||
*/
|
||||
|
||||
/***
|
||||
* Get the approximate size needed to protobuf encode this link
|
||||
* @param link the link to examine
|
||||
* @returns the maximum size that should be needed
|
||||
*/
|
||||
size_t ipfs_node_link_protobuf_encode_size(struct NodeLink* link);
|
||||
|
||||
/***
|
||||
* Encode a NodeLink into protobuf format
|
||||
* @param link the link
|
||||
* @param buffer where to put the encoded results
|
||||
* @param max_buffer_length the max size that should be put in buffer
|
||||
* @pram bytes_written the amount of the buffer used
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_node_link_protobuf_encode(struct NodeLink* link, unsigned char* buffer, size_t max_buffer_length, size_t* bytes_written);
|
||||
|
||||
/****
|
||||
* Decode from a byte array into a NodeLink
|
||||
* @param buffer the byte array
|
||||
* @param buffer_length the length of the byte array
|
||||
* @param link the pointer to the new NodeLink (NOTE: Will be allocated in this function)
|
||||
* @param bytes_read the amount of bytes read by this function
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_node_link_protobuf_decode(unsigned char* buffer, size_t buffer_length, struct NodeLink** link, size_t* bytes_read);
|
||||
|
||||
|
||||
/***
|
||||
* return an approximate size of the encoded node
|
||||
* @param node the node to examine
|
||||
|
@ -71,7 +99,7 @@ size_t ipfs_node_protobuf_encode_size(struct Node* node);
|
|||
* @param bytes_written how much of buffer was used
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
ipfs_node_protobuf_encode(struct Node* node, unsigned char* buffer, size_t max_buffer_length, size_t* bytes_written);
|
||||
int ipfs_node_protobuf_encode(struct Node* node, unsigned char* buffer, size_t max_buffer_length, size_t* bytes_written);
|
||||
|
||||
/***
|
||||
* Decode a stream of bytes into a Node structure
|
||||
|
@ -80,7 +108,7 @@ ipfs_node_protobuf_encode(struct Node* node, unsigned char* buffer, size_t max_b
|
|||
* @param node pointer to the Node to be created
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
ipfs_node_protobuf_decode(unsigned char* buffer, size_t buffer_length, struct Node** node);
|
||||
int ipfs_node_protobuf_decode(unsigned char* buffer, size_t buffer_length, struct Node** node);
|
||||
|
||||
/*====================================================================================
|
||||
* Node Functions
|
||||
|
@ -98,7 +126,7 @@ int ipfs_node_new(struct Node** node);
|
|||
* @param cid the cid
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_node_set_cached(struct Node* node, struct Cid* cid);
|
||||
int ipfs_node_set_cached(struct Node* node, const struct Cid* cid);
|
||||
|
||||
/*ipfs_node_set_data
|
||||
* Sets the data of a node
|
||||
|
|
23
node/node.c
23
node/node.c
|
@ -29,7 +29,12 @@ int ipfs_node_link_new(char * name, unsigned char * ahash, struct NodeLink** nod
|
|||
*node_link = malloc(sizeof(struct NodeLink));
|
||||
if (*node_link == NULL)
|
||||
return 0;
|
||||
(*node_link)->name = name;
|
||||
(*node_link)->name = malloc(strlen(name) + 1);
|
||||
if ( (*node_link)->name == NULL) {
|
||||
free(*node_link);
|
||||
return 0;
|
||||
}
|
||||
strcpy((*node_link)->name, name);
|
||||
(*node_link)->next = NULL;
|
||||
int ver = 0;
|
||||
size_t lenhash = strlen((char*)ahash);
|
||||
|
@ -55,7 +60,7 @@ int ipfs_node_link_free(struct NodeLink * node_link)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int ipfs_node_link_protobuf_encode_size(struct NodeLink* link) {
|
||||
size_t ipfs_node_link_protobuf_encode_size(struct NodeLink* link) {
|
||||
if (link == NULL)
|
||||
return 0;
|
||||
|
||||
|
@ -75,7 +80,7 @@ int ipfs_node_link_protobuf_encode(struct NodeLink* link, unsigned char* buffer,
|
|||
size_t cid_size = ipfs_cid_protobuf_encode_size(link->cid);
|
||||
unsigned char cid_buffer[cid_size];
|
||||
retVal = ipfs_cid_protobuf_encode(link->cid, cid_buffer, cid_size, &bytes_used);
|
||||
retVal = protobuf_encode_length_delimited(2, ipfs_node_link_message_fields[1], cid_buffer, bytes_used, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
|
||||
retVal = protobuf_encode_length_delimited(2, ipfs_node_link_message_fields[1], (char*)&cid_buffer[0], bytes_used, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
|
||||
*bytes_written += bytes_used;
|
||||
return 1;
|
||||
}
|
||||
|
@ -166,18 +171,18 @@ int ipfs_node_protobuf_encode(struct Node* node, unsigned char* buffer, size_t m
|
|||
size_t bytes_used = 0;
|
||||
*bytes_written = 0;
|
||||
int retVal = 0;
|
||||
retVal = protobuf_encode_length_delimited(1, ipfs_node_message_fields[0], node->data, node->data_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
|
||||
retVal = protobuf_encode_length_delimited(1, ipfs_node_message_fields[0], (char*)node->data, node->data_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
|
||||
*bytes_written += bytes_used;
|
||||
int sz = 0;
|
||||
if (node->encoded != NULL)
|
||||
sz = strlen(node->encoded);
|
||||
retVal = protobuf_encode_length_delimited(2, ipfs_node_message_fields[1], node->encoded, sz, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
|
||||
sz = strlen((char*)node->encoded);
|
||||
retVal = protobuf_encode_length_delimited(2, ipfs_node_message_fields[1], (char*)node->encoded, sz, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
|
||||
*bytes_written += bytes_used;
|
||||
// cid
|
||||
size_t cid_size = ipfs_cid_protobuf_encode_size(node->cached);
|
||||
unsigned char cid[cid_size];
|
||||
retVal = ipfs_cid_protobuf_encode(node->cached, cid, cid_size, &cid_size);
|
||||
retVal = protobuf_encode_length_delimited(3, ipfs_node_message_fields[2], cid, cid_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
|
||||
retVal = protobuf_encode_length_delimited(3, ipfs_node_message_fields[2], (char*)cid, cid_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
|
||||
*bytes_written += bytes_used;
|
||||
// links
|
||||
struct NodeLink* current = node->head_link;
|
||||
|
@ -186,7 +191,7 @@ int ipfs_node_protobuf_encode(struct Node* node, unsigned char* buffer, size_t m
|
|||
size_t link_buffer_size = 11 + ipfs_node_link_protobuf_encode_size(current);
|
||||
unsigned char link_buffer[link_buffer_size];
|
||||
retVal = ipfs_node_link_protobuf_encode(current, link_buffer, link_buffer_size, &link_buffer_size);
|
||||
protobuf_encode_length_delimited(4, ipfs_node_message_fields[3], link_buffer, link_buffer_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
|
||||
protobuf_encode_length_delimited(4, ipfs_node_message_fields[3], (char*)link_buffer, link_buffer_size, &buffer[*bytes_written], max_buffer_length - *bytes_written, &bytes_used);
|
||||
*bytes_written += bytes_used;
|
||||
current = current->next;
|
||||
}
|
||||
|
@ -295,7 +300,7 @@ int ipfs_node_new(struct Node** node)
|
|||
* @param cid the Cid to be copied into the Node->cached element
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_node_set_cached(struct Node* node, struct Cid* cid)
|
||||
int ipfs_node_set_cached(struct Node* node, const struct Cid* cid)
|
||||
{
|
||||
if (node->cached != NULL)
|
||||
ipfs_cid_free(node->cached);
|
||||
|
|
|
@ -17,20 +17,20 @@
|
|||
* @param result where the result string will reside.
|
||||
* @returns true(1) on success, or false(0)
|
||||
*/
|
||||
int config_get_default_path_root(char* result) {
|
||||
int config_get_default_path_root(char** result) {
|
||||
char* root = os_utils_getenv("IPFS_PATH");
|
||||
if (root == NULL) {
|
||||
root = os_utils_getenv("HOME");
|
||||
result = malloc( strlen(root) + 7);
|
||||
if (result == NULL)
|
||||
*result = malloc( strlen(root) + 7);
|
||||
if (*result == NULL)
|
||||
return 0;
|
||||
strncpy(result, root, strlen(root)+1);
|
||||
strncat(result, "/.ipfs", 7);
|
||||
strncpy(*result, root, strlen(root)+1);
|
||||
strncat(*result, "/.ipfs", 7);
|
||||
} else {
|
||||
char* result = malloc(strlen(root)+1);
|
||||
if (result == NULL)
|
||||
*result = malloc(strlen(root)+1);
|
||||
if (*result == NULL)
|
||||
return 0;
|
||||
strncpy(result, root, strlen(root)+1);
|
||||
strncpy(*result, root, strlen(root)+1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -46,8 +46,8 @@ int config_get_default_path_root(char* result) {
|
|||
*/
|
||||
int config_path(char* config_root, char* extension, char* result, int max_len) {
|
||||
if (strlen(config_root) == 0) {
|
||||
char* default_path;
|
||||
int retVal = config_get_default_path_root(default_path);
|
||||
char* default_path = NULL;
|
||||
int retVal = config_get_default_path_root(&default_path);
|
||||
if (!retVal)
|
||||
return retVal;
|
||||
retVal = os_utils_filepath_join(default_path, extension, result, max_len);
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
*/
|
||||
int repo_config_identity_build_peer_id(struct Identity* identity) {
|
||||
// ic key and PeerID
|
||||
char hash[32];
|
||||
ID_FromPK_non_null_terminated(hash, identity->private_key.der, identity->private_key.der_length);
|
||||
unsigned char hash[32];
|
||||
ID_FromPK_non_null_terminated((char*)hash, (unsigned char*)identity->private_key.der, identity->private_key.der_length);
|
||||
|
||||
// peer id is multihashed
|
||||
size_t sz = 255;
|
||||
char results[sz];
|
||||
unsigned char results[sz];
|
||||
if (PrettyID(results, &sz, hash, 32) == 0)
|
||||
return 0;
|
||||
|
||||
|
@ -35,7 +35,7 @@ int repo_config_identity_build_peer_id(struct Identity* identity) {
|
|||
if (identity->peer_id == NULL)
|
||||
return 0;
|
||||
|
||||
strncpy(identity->peer_id, results, sz);
|
||||
strncpy(identity->peer_id, (char*)results, sz);
|
||||
identity->peer_id[sz] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ int repo_config_identity_build_private_key(struct Identity* identity, const char
|
|||
size_t decoded_size = libp2p_crypto_encoding_base64_decode_size(strlen(base64));
|
||||
unsigned char decoded[decoded_size];
|
||||
|
||||
int retVal = libp2p_crypto_encoding_base64_decode(base64, strlen(base64), decoded, decoded_size, &decoded_size);
|
||||
int retVal = libp2p_crypto_encoding_base64_decode((unsigned char*)base64, strlen(base64), decoded, decoded_size, &decoded_size);
|
||||
if (retVal == 0)
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ int repo_config_write_config_file(char* full_filename, struct RepoConfig* config
|
|||
// first base 64 it
|
||||
size_t encoded_size = libp2p_crypto_encoding_base64_encode_size(config->identity->private_key.der_length);
|
||||
unsigned char encoded_buffer[encoded_size + 1];
|
||||
int retVal = libp2p_crypto_encoding_base64_encode(config->identity->private_key.der, config->identity->private_key.der_length, encoded_buffer, encoded_size, &encoded_size);
|
||||
int retVal = libp2p_crypto_encoding_base64_encode((unsigned char*)config->identity->private_key.der, config->identity->private_key.der_length, encoded_buffer, encoded_size, &encoded_size);
|
||||
if (retVal == 0)
|
||||
return 0;
|
||||
encoded_buffer[encoded_size] = 0;
|
||||
|
@ -357,7 +357,7 @@ int fs_repo_open_config(struct FSRepo* repo) {
|
|||
return 0;
|
||||
}
|
||||
// now the datastore
|
||||
int datastore_position = _find_token(data, tokens, num_tokens, 0, "Datastore");
|
||||
//int datastore_position = _find_token(data, tokens, num_tokens, 0, "Datastore");
|
||||
_get_json_string_value(data, tokens, num_tokens, curr_pos, "Type", &repo->config->datastore->type);
|
||||
_get_json_string_value(data, tokens, num_tokens, curr_pos, "Path", &repo->config->datastore->path);
|
||||
_get_json_string_value(data, tokens, num_tokens, curr_pos, "StorageMax", &repo->config->datastore->storage_max);
|
||||
|
@ -453,10 +453,11 @@ int fs_repo_is_initialized(char* repo_path) {
|
|||
|
||||
int ipfs_repo_fsrepo_datastore_init(struct FSRepo* fs_repo) {
|
||||
// make the directory
|
||||
repo_fsrepo_lmdb_create_directory(fs_repo->config->datastore);
|
||||
if (repo_fsrepo_lmdb_create_directory(fs_repo->config->datastore) == 0)
|
||||
return 0;
|
||||
|
||||
// fill in the function prototypes
|
||||
repo_fsrepo_lmdb_cast(fs_repo->config->datastore);
|
||||
return repo_fsrepo_lmdb_cast(fs_repo->config->datastore);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -178,14 +178,6 @@ int repo_fsrepo_lmdb_put_block(const struct Block* block, const struct Datastore
|
|||
return repo_fsrepo_lmdb_put(block->cid->hash, block->cid->hash_length, block->data, block->data_length, datastore);
|
||||
}
|
||||
|
||||
/***
|
||||
* Save a node in the datastore
|
||||
*/
|
||||
int repo_fsrepo_lmdb_put_node(const struct Node* node, const struct Datastore* datastore) {
|
||||
// first the links, then the data
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Open an lmdb database with the given parameters.
|
||||
* Note: for now, the parameters are not used
|
||||
|
|
|
@ -10,6 +10,7 @@ OBJS = testit.o test_helper.o \
|
|||
../core/builder.o \
|
||||
../datastore/ds_helper.o \
|
||||
../flatfs/flatfs.o \
|
||||
../importer/importer.o \
|
||||
../merkledag/merkledag.o \
|
||||
../multibase/multibase.o \
|
||||
../node/node.o \
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
int test_cid_new_free() {
|
||||
|
||||
struct Cid* cid;
|
||||
const unsigned char* hash = "ABC123";
|
||||
int retVal = ipfs_cid_new(0, (unsigned char*)hash, strlen((char*)hash), CID_PROTOBUF, &cid);
|
||||
unsigned char* hash = (unsigned char*)"ABC123";
|
||||
int retVal = ipfs_cid_new(0, hash, strlen((char*)hash), CID_PROTOBUF, &cid);
|
||||
if (retVal == 0)
|
||||
return 0;
|
||||
|
||||
|
@ -37,11 +37,11 @@ int test_cid_new_free() {
|
|||
*/
|
||||
int test_cid_cast_multihash() {
|
||||
// first, build a multihash
|
||||
char* string_to_hash = "Hello, World!";
|
||||
unsigned char* string_to_hash = (unsigned char*)"Hello, World!";
|
||||
unsigned char hashed[32];
|
||||
memset(hashed, 0, 32);
|
||||
// hash the string
|
||||
libp2p_crypto_hashing_sha256(string_to_hash, strlen(string_to_hash), hashed);
|
||||
libp2p_crypto_hashing_sha256(string_to_hash, strlen((char*)string_to_hash), hashed);
|
||||
size_t multihash_size = mh_new_length(MH_H_SHA2_256, 32);
|
||||
unsigned char multihash[multihash_size];
|
||||
memset(multihash, 0, multihash_size);
|
||||
|
@ -63,7 +63,7 @@ int test_cid_cast_multihash() {
|
|||
return 0;
|
||||
if (cid.codec != CID_PROTOBUF)
|
||||
return 0;
|
||||
if (strncmp(hashed, cid.hash, 32) != 0)
|
||||
if (strncmp((char*)hashed, (char*)cid.hash, 32) != 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
@ -71,11 +71,11 @@ int test_cid_cast_multihash() {
|
|||
|
||||
int test_cid_cast_non_multihash() {
|
||||
// first, build a hash
|
||||
char* string_to_hash = "Hello, World!";
|
||||
unsigned char* string_to_hash = (unsigned char*)"Hello, World!";
|
||||
unsigned char hashed[32];
|
||||
memset(hashed, 0, 32);
|
||||
// hash the string
|
||||
libp2p_crypto_hashing_sha256(string_to_hash, strlen(string_to_hash), hashed);
|
||||
libp2p_crypto_hashing_sha256(string_to_hash, strlen((char*)string_to_hash), hashed);
|
||||
|
||||
// now make it a hash with a version and codec embedded in varints before the hash
|
||||
size_t array_size = 34; // 32 for the hash, 2 for the 2 varints
|
||||
|
@ -100,7 +100,7 @@ int test_cid_cast_non_multihash() {
|
|||
return 0;
|
||||
if (cid.codec != CID_PROTOBUF)
|
||||
return 0;
|
||||
if (strncmp(hashed, cid.hash, 32) != 0)
|
||||
if (strncmp((char*)hashed, (char*)cid.hash, 32) != 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
@ -110,7 +110,7 @@ int test_cid_protobuf_encode_decode() {
|
|||
struct Cid tester;
|
||||
tester.version = 1;
|
||||
tester.codec = CID_ETHEREUM_BLOCK;
|
||||
tester.hash = "ABC123";
|
||||
tester.hash = (unsigned char*)"ABC123";
|
||||
tester.hash_length = 6;
|
||||
size_t bytes_written_to_buffer;
|
||||
|
||||
|
@ -137,7 +137,7 @@ int test_cid_protobuf_encode_decode() {
|
|||
}
|
||||
|
||||
if (tester.hash_length != results->hash_length) {
|
||||
printf("Hash length %d does not match %d\n", tester.hash_length, results->hash_length);
|
||||
printf("Hash length %d does not match %d\n", (int)tester.hash_length, (int)results->hash_length);
|
||||
ipfs_cid_free(results);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -195,7 +195,7 @@ int test_merkledag_add_data() {
|
|||
*/
|
||||
int test_merkledag_add_node_with_links() {
|
||||
int retVal = 0;
|
||||
struct Link* link = NULL;
|
||||
struct NodeLink* link = NULL;
|
||||
struct Node* node1 = NULL;
|
||||
|
||||
struct FSRepo* fs_repo = createAndOpenRepo("/tmp/.ipfs");
|
||||
|
@ -205,7 +205,7 @@ int test_merkledag_add_node_with_links() {
|
|||
}
|
||||
|
||||
// make link
|
||||
retVal = ipfs_node_link_new("", "abc123", &link);
|
||||
retVal = ipfs_node_link_new("", (unsigned char*)"abc123", &link);
|
||||
retVal = ipfs_node_new_from_link(link, &node1);
|
||||
|
||||
retVal = ipfs_merkledag_add(node1, fs_repo);
|
||||
|
|
|
@ -19,7 +19,7 @@ int test_node() {
|
|||
//mylink->name = "HAHA";//Testing for valid node creation
|
||||
retVal = ipfs_node_add_link(Mynode, mylink2);
|
||||
//mylink2->name = "HAHA";//Testing for valid node creation
|
||||
struct NodeLink * ResultLink = ipfs_node_get_link_by_name(Mynode, "Simo");
|
||||
//struct NodeLink * ResultLink = ipfs_node_get_link_by_name(Mynode, "Simo");
|
||||
ipfs_node_remove_link_by_name("Simo", Mynode);
|
||||
ipfs_node_free(Mynode);
|
||||
return 1;
|
||||
|
@ -35,7 +35,7 @@ int compare_link(struct NodeLink* link1, struct NodeLink* link2) {
|
|||
return 0;
|
||||
}
|
||||
if (link1->cid->hash_length != link2->cid->hash_length) {
|
||||
printf("Link cid hash lengths are different. Expected %d but got %d\n", link1->cid->hash_length, link2->cid->hash_length);
|
||||
printf("Link cid hash lengths are different. Expected %d but got %d\n", (int)link1->cid->hash_length, (int)link2->cid->hash_length);
|
||||
return 0;
|
||||
}
|
||||
if (link1->cid->version != link2->cid->version) {
|
||||
|
@ -57,7 +57,7 @@ int test_node_link_encode_decode() {
|
|||
int retVal = 0;
|
||||
|
||||
// make a NodeLink
|
||||
if (ipfs_node_link_new("My Name", "QmMyHash", &control) == 0)
|
||||
if (ipfs_node_link_new("My Name", (unsigned char*)"QmMyHash", &control) == 0)
|
||||
goto l_exit;
|
||||
|
||||
// encode it
|
||||
|
@ -70,7 +70,7 @@ int test_node_link_encode_decode() {
|
|||
}
|
||||
|
||||
// decode it
|
||||
if (ipfs_node_link_protobuf_decode(buffer, nl_size, &results) == 0) {
|
||||
if (ipfs_node_link_protobuf_decode(buffer, nl_size, &results, &nl_size) == 0) {
|
||||
goto l_exit;
|
||||
}
|
||||
|
||||
|
@ -110,13 +110,10 @@ int test_node_encode_decode() {
|
|||
goto ed_exit;
|
||||
|
||||
// second link
|
||||
// TODO: put here to diagnose a memory leak. Remove the comments!
|
||||
/*
|
||||
if (ipfs_node_link_new((char*)"Link2", (unsigned char*)"QmLink2", &link2) == 0)
|
||||
goto ed_exit;
|
||||
if ( ipfs_node_add_link(control, link2) == 0)
|
||||
goto ed_exit;
|
||||
*/
|
||||
// encode
|
||||
buffer_length = ipfs_node_protobuf_encode_size(control);
|
||||
buffer = (unsigned char*)malloc(buffer_length);
|
||||
|
|
|
@ -30,12 +30,10 @@ int test_repo_config_identity_new() {
|
|||
|
||||
// test this key
|
||||
int test_repo_config_identity_private_key() {
|
||||
const char* priv_b64 = "CAASpwkwggSjAgEAAoIBAQDTDJBWjDzS/HxDNOHazvzH2bu9CPMVHUrrvKRdBUM5ansL6/CC3MVZ6HVm4O6QHRapN6EF2CbrTgI4KBOXIL125Xo8MlROnyfXYk3O5q2tgwL/MbW8kXjtkyCfBak7MUoLOdLU7Svg0gkl3l+uDAiDcCLnwJVcFfq9ch6z4wMOhYJqE5dtx0uXxn6IuKWl1B69FTvBXCc0thw8Rw54b941FDcsBH5ttV9mRNCJym3poZ5qalNgXlxoIIB+PUx5QD+aq7KMJdpAX8HkapBntCOahP/QUceRmma0grlZLeYkH6/oi/hIrM6se3KUZ+F6tBuDFys8UAZy/X2BCUbKjbxtAgMBAAECggEANWfQfpYuLhXGPBt9q6kFPm1SnJtPJ+CpvM2XqhJS2IyhZnrl+bd0GTRBwS7aL42s1lVFYf04nAK5fQxnKK8YQqX/MIxr2RldM5ukpN6qxGWKtJkXrAgD2dqJPrRoBpqKahzPxSHfIJ0Fw5dqDtjsrpYJvyt0oEDPmnDuZAbmFx4sJqnesPNhKxtRMBx1+yxGVuRVJjHcqAgqPqwNiuoMEaYMY+G9yzT6vza8ovCpbX7BBIgM5fAT9PD8TBG//Vu9THvj/ZomiVG2qv6RL0qQyVb+DUzPZz1amBsSvahtXCl72jA3JwAZ943RxSR66P934S0ashkVwLUi46z/EAbJ4QKBgQDojGIO07BEVL2+7VxlGL9XGZQp4Y3qlhh2zDDQGwkCq/KQ+BdNYWitPwqRl9GqFLgpmeQIhyHTOa/IThx+AXGKVQ24ROH+skUs4IbO6R3qY7BKtb5lkZE/Yln09x70BBngUYAzh/rtnsXO3cl1x2XDDqUbCwlGcDAs8Jh/6UnvQwKBgQDoVSQs7Uq9MJCGIUM2bixX89tHzSxq5mn9wMD3/XRVfT5Ua8YkYBuzcmlcT39N7L5BwuyFqX3Vi7lv/Ya/qaQP6XkrZ8W1OAaTlYewfE5ZgknJqSpXcNWhABKeNmqndvqyQ/8HNCv/j8AdraGB2DGO57Xso5J0CQ43W/U9+QIyjwKBgHLL2hw3o+wXaRO3WMUPUmVM2zdRgR0suybp5a7Vqb0H5NZrohUw4NulIzJ8H6Q2VjMzJL6Q9sGu2HepF6ecTtBa7ErqtiVlG4Dr1aCOs5XhYEWBMlwxX+JKSt4Cn+UVoTB7Cy5lEhn7JurX0Xuy0ylXMWoIKKv89cs5eg6quzTBAoGAaq9eEztLjKCWXOE9SetBdYnG8aunb9cqaJlwgu/h0bfXPVDYBbAUSEyLURY4MQI7Q1tM3Pu9iqfEmUZj7/LoIV5mg6X9RX/alT6etk3+dF+9nlqN1OU9U9cCtZ/rTcb2y5EptJcidRH/eCFY/pTV/PcttOJPx/S4kHcroC+N8MUCgYEA6DA5QHxHfNN6Nxv+pEzy2DIxFe9RrBxS+KPBsra1C8jgdeMf4EmfU0Nox92V0q0bRrD5ztqQwSONI0hSRb1iiMWR6MuFnAFajUJfASjjIlZ6nIQjQslI7vjlvYyyHS/p/Codxap+yJlTLWwVEOXp2D9pWwiMq1xEyf0TH1BosvM=";
|
||||
size_t decoded_len = libp2p_crypto_encoding_base64_decode_size(strlen(priv_b64));
|
||||
char* out_buff = malloc(sizeof(char) * decoded_len);
|
||||
libp2p_crypto_encoding_base64_decode(priv_b64, strlen(priv_b64), out_buff, decoded_len, &decoded_len);
|
||||
char str[decoded_len];
|
||||
int j = 0;
|
||||
const unsigned char* priv_b64 = (unsigned char*)"CAASpwkwggSjAgEAAoIBAQDTDJBWjDzS/HxDNOHazvzH2bu9CPMVHUrrvKRdBUM5ansL6/CC3MVZ6HVm4O6QHRapN6EF2CbrTgI4KBOXIL125Xo8MlROnyfXYk3O5q2tgwL/MbW8kXjtkyCfBak7MUoLOdLU7Svg0gkl3l+uDAiDcCLnwJVcFfq9ch6z4wMOhYJqE5dtx0uXxn6IuKWl1B69FTvBXCc0thw8Rw54b941FDcsBH5ttV9mRNCJym3poZ5qalNgXlxoIIB+PUx5QD+aq7KMJdpAX8HkapBntCOahP/QUceRmma0grlZLeYkH6/oi/hIrM6se3KUZ+F6tBuDFys8UAZy/X2BCUbKjbxtAgMBAAECggEANWfQfpYuLhXGPBt9q6kFPm1SnJtPJ+CpvM2XqhJS2IyhZnrl+bd0GTRBwS7aL42s1lVFYf04nAK5fQxnKK8YQqX/MIxr2RldM5ukpN6qxGWKtJkXrAgD2dqJPrRoBpqKahzPxSHfIJ0Fw5dqDtjsrpYJvyt0oEDPmnDuZAbmFx4sJqnesPNhKxtRMBx1+yxGVuRVJjHcqAgqPqwNiuoMEaYMY+G9yzT6vza8ovCpbX7BBIgM5fAT9PD8TBG//Vu9THvj/ZomiVG2qv6RL0qQyVb+DUzPZz1amBsSvahtXCl72jA3JwAZ943RxSR66P934S0ashkVwLUi46z/EAbJ4QKBgQDojGIO07BEVL2+7VxlGL9XGZQp4Y3qlhh2zDDQGwkCq/KQ+BdNYWitPwqRl9GqFLgpmeQIhyHTOa/IThx+AXGKVQ24ROH+skUs4IbO6R3qY7BKtb5lkZE/Yln09x70BBngUYAzh/rtnsXO3cl1x2XDDqUbCwlGcDAs8Jh/6UnvQwKBgQDoVSQs7Uq9MJCGIUM2bixX89tHzSxq5mn9wMD3/XRVfT5Ua8YkYBuzcmlcT39N7L5BwuyFqX3Vi7lv/Ya/qaQP6XkrZ8W1OAaTlYewfE5ZgknJqSpXcNWhABKeNmqndvqyQ/8HNCv/j8AdraGB2DGO57Xso5J0CQ43W/U9+QIyjwKBgHLL2hw3o+wXaRO3WMUPUmVM2zdRgR0suybp5a7Vqb0H5NZrohUw4NulIzJ8H6Q2VjMzJL6Q9sGu2HepF6ecTtBa7ErqtiVlG4Dr1aCOs5XhYEWBMlwxX+JKSt4Cn+UVoTB7Cy5lEhn7JurX0Xuy0ylXMWoIKKv89cs5eg6quzTBAoGAaq9eEztLjKCWXOE9SetBdYnG8aunb9cqaJlwgu/h0bfXPVDYBbAUSEyLURY4MQI7Q1tM3Pu9iqfEmUZj7/LoIV5mg6X9RX/alT6etk3+dF+9nlqN1OU9U9cCtZ/rTcb2y5EptJcidRH/eCFY/pTV/PcttOJPx/S4kHcroC+N8MUCgYEA6DA5QHxHfNN6Nxv+pEzy2DIxFe9RrBxS+KPBsra1C8jgdeMf4EmfU0Nox92V0q0bRrD5ztqQwSONI0hSRb1iiMWR6MuFnAFajUJfASjjIlZ6nIQjQslI7vjlvYyyHS/p/Codxap+yJlTLWwVEOXp2D9pWwiMq1xEyf0TH1BosvM=";
|
||||
size_t decoded_len = libp2p_crypto_encoding_base64_decode_size(strlen((char*)priv_b64));
|
||||
unsigned char* out_buff = malloc(sizeof(char) * decoded_len);
|
||||
libp2p_crypto_encoding_base64_decode(priv_b64, strlen((char*)priv_b64), out_buff, decoded_len, &decoded_len);
|
||||
free(out_buff);
|
||||
// now test
|
||||
return 1;
|
||||
|
|
|
@ -12,8 +12,8 @@ int test_ds_key_from_binary() {
|
|||
}
|
||||
|
||||
size_t outgoing_length = 100;
|
||||
char outgoing[outgoing_length];
|
||||
char* ptrOutgoing = &outgoing[0];
|
||||
unsigned char outgoing[outgoing_length];
|
||||
unsigned char* ptrOutgoing = &outgoing[0];
|
||||
|
||||
memset(outgoing, 0, outgoing_length);
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ int main(int argc, char** argv) {
|
|||
int array_length = sizeof(funcs) / sizeof(funcs[0]);
|
||||
for (int i = 0; i < array_length; i++) {
|
||||
if (only_one) {
|
||||
char* currName = names[i];
|
||||
const char* currName = names[i];
|
||||
if (strcmp(currName, test_wanted) == 0) {
|
||||
tests_ran++;
|
||||
counter += testit(names[i], funcs[i]);
|
||||
|
|
Loading…
Reference in a new issue