adjusted makefiles, generating config file for new ipfs repository
This commit is contained in:
parent
8d82e8235b
commit
32d187faa4
26 changed files with 276 additions and 79 deletions
|
@ -1,5 +1,10 @@
|
|||
CC = gcc
|
||||
CFLAGS = -O0
|
||||
CFLAGS = -O0 -I../../include -I../../../c-libp2p/include
|
||||
|
||||
ifdef DEBUG
|
||||
CFLAGS += -g3
|
||||
endif
|
||||
|
||||
LFLAGS =
|
||||
DEPS =
|
||||
OBJS = init.o main.o ../../commands/argument.o
|
||||
|
@ -10,7 +15,7 @@ OBJS = init.o main.o ../../commands/argument.o
|
|||
ipfs: $(OBJS)
|
||||
$(CC) -o $@ $^ $(LFLAGS)
|
||||
|
||||
all: $(DEPS)
|
||||
all: $(OBJS)
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "ipfs/cmd/ipfs/init.h"
|
||||
#include "ipfs/commands/request.h"
|
||||
#include "ipfs/commands/command_option.h"
|
||||
//#include "ipfs/commands/request.h"
|
||||
#include "ipfs/os/utils.h"
|
||||
#include "ipfs/core/ipfs_node.h"
|
||||
#include "ipfs/core/builder.h"
|
||||
|
@ -19,7 +19,7 @@ const int nBitsForKeypairDefault = 2048;
|
|||
*/
|
||||
int init_pre_run(struct Request* request) {
|
||||
//TODO: make sure daemon is not running
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int initialize_ipns_keyspace(char* repo_root) {
|
||||
|
@ -35,13 +35,13 @@ int initialize_ipns_keyspace(char* repo_root) {
|
|||
//TODO: see line 185 of init.go, what does core.BldCfg{Repo: r} do? BldCfg is a structure
|
||||
retVal = 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);
|
||||
return 0;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* called by init_run, to do the heavy lifting
|
||||
* @param out_file an output stream (stdout)
|
||||
* @param repo_root a string
|
||||
* @param repo_root a path that is where the .ipfs directory will be put
|
||||
* @param empty true(1) if empty, false(0) if not
|
||||
* @param num_bits_for_keypair number of bits for key pair
|
||||
* @param conf the configuration struct
|
||||
|
@ -52,12 +52,18 @@ int do_init(FILE* out_file, char* repo_root, int empty, int num_bits_for_keypair
|
|||
if (!os_utils_directory_writeable(repo_root))
|
||||
return 0;
|
||||
// verify that it is not already initialized
|
||||
if (!fs_repo_is_initialized(repo_root))
|
||||
if (fs_repo_is_initialized(repo_root))
|
||||
return 0;
|
||||
//TODO: If the conf is null, make one
|
||||
if (conf == NULL)
|
||||
repo_config_init(conf, num_bits_for_keypair, repo_root);
|
||||
//TODO: initialize the fs repo
|
||||
if ( conf->identity.peer_id == NULL) {
|
||||
int retVal = repo_config_init(conf, num_bits_for_keypair, repo_root);
|
||||
if (retVal == 0)
|
||||
return 0;
|
||||
}
|
||||
// initialize the fs repo
|
||||
int retVal = fs_repo_init(repo_root, conf);
|
||||
if (retVal == 0)
|
||||
return 0;
|
||||
//TODO: add default assets
|
||||
return initialize_ipns_keyspace(repo_root);
|
||||
}
|
||||
|
@ -71,13 +77,11 @@ int init_run(struct Request* request) {
|
|||
// TODO: make sure offline
|
||||
// TODO: check parameters for logic errors
|
||||
// TODO: Initialize
|
||||
struct RepoConfig conf;
|
||||
struct RepoConfig conf = {0};
|
||||
// TODO: handle files in request
|
||||
// do the heavy lifting
|
||||
int num_bits_for_key_pair = request->cmd->options[1]->default_int_val;
|
||||
do_init(stdout, request->invoc_context->config_root, 1, num_bits_for_key_pair, &conf);
|
||||
|
||||
return 0;
|
||||
int num_bits_for_key_pair = request->cmd.options[0]->default_int_val;
|
||||
return do_init(stdout, request->invoc_context->config_root, 1, num_bits_for_key_pair, &conf);
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -90,31 +94,35 @@ int init_post_run(struct Request* request) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int get_init_command(struct Command* cmd) {
|
||||
int ipfs_cmd_ipfs_init_command_new(struct Command* cmd) {
|
||||
int retVal = 1;
|
||||
|
||||
// help text
|
||||
cmd->help_text.tagline = "Initializes IPFS config file.";
|
||||
cmd->help_text.short_description = "\nInitializes IPFS configuration files and generates a new keypair.\n\nipfs uses a repository in the local file system. By default, the repo is\nlocated at ~/.ipfs. To change the repo location, set the $IPFS_PATH\nenvironment variable.:\n\n export IPFS_PATH=/path/to/ipfsrepo";
|
||||
|
||||
cmd->argument_count = 1;
|
||||
cmd->option_count = 2;
|
||||
init_command(cmd);
|
||||
commands_command_init(cmd);
|
||||
// allocate memory for array of pointers
|
||||
int retVal = init_string_argument(cmd->arguments[0], "default-config", 0, 0, "Initialize with the given configuration");
|
||||
retVal = commands_argument_init(cmd->arguments[0], "default-config", 0, 0, "Initialize with the given configuration");
|
||||
if (retVal == 0)
|
||||
return 0;
|
||||
cmd->arguments[0]->enable_stdin = 1;
|
||||
|
||||
// options
|
||||
cmd->options[0]->name_count = 2;
|
||||
retVal = init_command_option(cmd->options[0], "Number of bits to use in the generated RSA private key");
|
||||
retVal = commands_command_option_init(cmd->options[0], "Number of bits to use in the generated RSA private key");
|
||||
cmd->options[0]->names[0] = "bits";
|
||||
cmd->options[0]->names[1] = "b";
|
||||
cmd->options[0]->kind = integer;
|
||||
cmd->options[0]->default_int_val = nBitsForKeypairDefault;
|
||||
cmd->options[1]->name_count = 2;
|
||||
retVal = init_command_option(cmd->options[1], "Don't add and pin help files to the local storage");
|
||||
retVal = commands_command_option_init(cmd->options[1], "Don't add and pin help files to the local storage");
|
||||
cmd->options[1]->default_bool_val = 0;
|
||||
cmd->options[1]->names[0] = "empty-repo";
|
||||
cmd->options[1]->names[1] = "e";
|
||||
|
||||
|
||||
// function pointers
|
||||
cmd->pre_run = init_pre_run;
|
||||
cmd->run = init_run;
|
||||
|
@ -123,4 +131,13 @@ int get_init_command(struct Command* cmd) {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* Uninitializes all the dynamic memory caused by get_init_command
|
||||
* @param command the struct
|
||||
* @returns 0 on failure, otherwise 1
|
||||
*/
|
||||
int ipfs_cmd_ipfs_init_command_free(struct Command* command) {
|
||||
// NOTE: commands_command_free takes care of arguments and command_options
|
||||
commands_command_free(command);
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue