Preparing for name resolve and name publish

This commit is contained in:
jmjatlanta 2017-09-21 09:47:16 -05:00
parent 2051f7714a
commit b301c7e4d2
6 changed files with 69 additions and 24 deletions

View file

@ -1,11 +1,44 @@
#include <stdlib.h>
#include <string.h>
#include "ipfs/cmd/cli.h"
int cli_is_switch(int argc, char** argv, int index) {
char* to_test = argv[index];
if (to_test[0] == '-') {
if (strcmp(to_test, "-c") == 0 || strcmp(to_test, "--config") == 0) {
return 2;
}
return 1;
}
return 0;
}
int cli_get_verb_index(struct CliArguments* args) {
for(int i = 1; i < args->argc; i++) {
int advance_by_more_than_one = cli_is_switch(args->argc, args->argv, i);
if (advance_by_more_than_one == 0) {
// this is the verb
return i;
} else {
if (advance_by_more_than_one == 2) {
// skip the next one
i++;
}
}
}
return 0;
}
char* cli_get_config_dir(struct CliArguments* args) {
for (int i = 1; i < args->argc; i++) {
if (args->argv[i][0] == '-') {
char* param = args->argv[i];
if ((strcmp(param, "-c") == 0 || strcmp(param, "--config") == 0) && args->argc > i + 1) {
return args->argv[i+1];
}
}
}
return NULL;
}

View file

@ -11,6 +11,22 @@
#include "ipfs/exchange/bitswap/bitswap.h"
#include "ipfs/journal/journal.h"
struct IpfsNode* ipfs_node_new() {
struct IpfsNode* node = malloc(sizeof(struct IpfsNode));
if (node != NULL) {
node->blockstore = NULL;
node->exchange = NULL;
node->identity = NULL;
node->mode = MODE_OFFLINE;
node->peerstore = NULL;
node->protocol_handlers = NULL;
node->providerstore = NULL;
node->repo = NULL;
node->routing = NULL;
}
return node;
}
struct Libp2pVector* ipfs_node_online_build_protocol_handlers(struct IpfsNode* node) {
struct Libp2pVector* retVal = libp2p_utils_vector_new(1);
if (retVal != NULL) {
@ -47,17 +63,11 @@ int ipfs_node_online_protocol_handlers_free(struct Libp2pVector* handlers) {
int ipfs_node_online_new(pthread_t *pth_scope, const char* repo_path, struct IpfsNode** node) {
struct FSRepo* fs_repo = NULL;
*node = (struct IpfsNode*)malloc(sizeof(struct IpfsNode));
*node = ipfs_node_new();
if(*node == NULL)
return 0;
struct IpfsNode* local_node = *node;
local_node->identity = NULL;
local_node->peerstore = NULL;
local_node->providerstore = NULL;
local_node->repo = NULL;
local_node->routing = NULL;
local_node->exchange = NULL;
// build the struct
if (!ipfs_repo_fsrepo_new(repo_path, NULL, &fs_repo)) {
@ -98,17 +108,11 @@ int ipfs_node_online_new(pthread_t *pth_scope, const char* repo_path, struct Ipf
int ipfs_node_offline_new(const char* repo_path, struct IpfsNode** node) {
struct FSRepo* fs_repo = NULL;
*node = (struct IpfsNode*)malloc(sizeof(struct IpfsNode));
*node = ipfs_node_new();
if(*node == NULL)
return 0;
struct IpfsNode* local_node = *node;
local_node->identity = NULL;
local_node->peerstore = NULL;
local_node->providerstore = NULL;
local_node->repo = NULL;
local_node->routing = NULL;
local_node->exchange = NULL;
// build the struct
if (!ipfs_repo_fsrepo_new(repo_path, NULL, &fs_repo)) {

View file

@ -38,10 +38,14 @@
#endif // MINGW
void stripit(int argc, char** argv) {
char tmp[strlen(argv[argc])];
strcpy(tmp, &argv[argc][1]);
char* old_arg = argv[argc];
int full_length = strlen(old_arg);
char *tmp = (char*) malloc(full_length + 1);
char* ptr1 = &old_arg[1];
strcpy(tmp, ptr1);
tmp[strlen(tmp)-1] = 0;
strcpy(argv[argc], tmp);
strcpy(old_arg, tmp);
free(tmp);
return;
}

View file

@ -149,6 +149,13 @@ int ipfs_repo_config_init(struct RepoConfig* config, unsigned int num_bits_for_k
config->addresses->swarm_head->next = libp2p_utils_linked_list_new();
config->addresses->swarm_head->next->item = malloc(strlen(addr1) + 1);
strcpy(config->addresses->swarm_head->next->item, addr1);
strcpy(addr1, "/ip4/127.0.0.1/tcp/5001");
config->addresses->api = malloc(strlen(addr1)+1);
strcpy(config->addresses->api, addr1);
strcpy(addr1, "ip4/127.0.0.1/tcp/8080");
config->addresses->gateway = malloc(strlen(addr1+1));
strcpy(config->addresses->gateway, addr1);
free(addr1);
config->discovery.mdns.enabled = 1;

View file

@ -341,6 +341,8 @@ int repo_fsrepro_lmdb_open(int argc, char** argv, struct Datastore* datastore) {
db_context->db_environment = NULL;
return 0;
}
mdb_txn_commit(db_context->current_transaction);
db_context->current_transaction = NULL;
return 1;
}

View file

@ -128,12 +128,7 @@ int ipfs_repo_init(int argc, char** argv) {
return 0;
}
// make the directory
#ifdef __MINGW32__
if (mkdir(repo_directory) == -1) {
#else
if (mkdir(repo_directory, S_IRWXU) == -1) {
#endif
printf("Unable to create the directory: %s\n", repo_directory);
if (!os_mkdir(repo_directory)) {
return 0;
}
// make the repository