Config file is now closer to completion. Still need to figure out ASN.1 DER for private key, and add peer id to config file

xethyrion-master
jmjatlanta 2016-11-02 13:09:38 -05:00
parent 772857312f
commit 0d8f599ac9
22 changed files with 606 additions and 102 deletions

View File

@ -56,7 +56,7 @@ int do_init(FILE* out_file, char* repo_root, int empty, int num_bits_for_keypair
return 0;
//TODO: If the conf is null, make one
if (conf == NULL)
repo_config_init(conf, num_bits_for_keypair);
repo_config_init(conf, num_bits_for_keypair, repo_root);
//TODO: initialize the fs repo
//TODO: add default assets
return initialize_ipns_keyspace(repo_root);

View File

@ -0,0 +1,36 @@
//
// addresses.h
// c-ipfs
//
// Created by John Jones on 11/2/16.
// Copyright © 2016 JMJAtlanta. All rights reserved.
//
#ifndef addresses_h
#define addresses_h
#include "swarm.h"
struct Addresses {
struct SwarmAddresses swarm;
char* api;
char* gateway;
};
/**
* initialize the Addresses struct with data. Must add the SwarmAddresses later
* @param addresses the struct
* @param api the API address (like "/ip4/127.0.0.1/tcp/5001")
* @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);
/**
* clear any memory allocated by a address_init call
* @param addresses the struct
* @returns true(1)
*/
int repo_config_addresses_free(struct Addresses* addresses);
#endif /* addresses_h */

View File

@ -0,0 +1,33 @@
//
// bootstrap_peer.h
// c-ipfs
//
// Created by John Jones on 11/2/16.
// Copyright © 2016 JMJAtlanta. All rights reserved.
//
#ifndef bootstrap_peer_h
#define bootstrap_peer_h
#include "ipfs/thirdparty/ipfsaddr/ipfs_addr.h"
struct BootstrapPeers {
int num_peers;
struct IPFSAddr** peers;
};
/***
* get a list of peers to use to bootstrap the instance
* @param bootstrap_peers an array of IPFSAddr structs, will be allocated by this function
* @returns true(1) on success, otherwise false(0)
*/
int repo_config_bootstrap_peers_retrieve(struct BootstrapPeers* bootstrap_peers);
/***
* frees up memory caused by call to repo_config_bootstrap_peers_retrieve
* @param list the list to free
* @returns true(1)
*/
int repo_config_bootstrap_peers_free(struct BootstrapPeers* list);
#endif /* bootstrap_peer_h */

View File

@ -3,21 +3,46 @@
#include "datastore.h"
#include "identity.h"
#include "swarm.h"
#include "bootstrap_peers.h"
#include "addresses.h"
#include "gateway.h"
struct MDNS {
int enabled;
int interval;
};
struct Discovery {
struct MDNS mdns;
};
struct Mounts {
char* ipfs;
char* ipns;
};
struct Ipns {
int resolve_cache_size;
};
struct Reprovider {
char* interval;
};
struct RepoConfig {
struct Identity identity;
struct Datastore datastore;
//struct address* addresses;
//struct mount* mounts;
//struct discovery discovery;
//struct ipns ipns;
//struct bootstrap* peer_addresses;
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 swarm swarm;
//struct reprovider reprovider;
struct Reprovider reprovider;
};
/**
@ -47,6 +72,6 @@ int config_path(char* config_root, char* extension, char* result, int max_len);
* @param num_bits_for_keypair number of bits for the key pair
* @returns true(1) on success, otherwise 0
*/
int repo_config_init(struct RepoConfig* config, unsigned int num_bits_for_keypair);
int repo_config_init(struct RepoConfig* config, unsigned int num_bits_for_keypair, char* repo_path);
#endif

View File

@ -9,7 +9,7 @@ struct Datastore {
char* type;
char* path;
char* storage_max;
int64_t storage_gc_watermark;
int storage_gc_watermark;
char* gc_period;
char* params;
@ -18,4 +18,20 @@ struct Datastore {
int bloom_filter_size;
};
/***
* initialize the structure of the datastore
* @param datastore the struct to initialize
* @param config_root the path to the root of IPFS
* @returns true(1) on success
*/
int repo_config_datastore_init(struct Datastore* datastore, char* config_root);
/***
* deallocate the memory and clear resources from a datastore_init
* @param datastore the struct to deallocate
* @returns true(1)
*/
int repo_config_datastore_free(struct Datastore* datastore);
#endif

View File

@ -0,0 +1,36 @@
//
// gateway.h
// c-ipfs
//
// Created by John Jones on 11/2/16.
// Copyright © 2016 JMJAtlanta. All rights reserved.
//
#ifndef gateway_h
#define gateway_h
struct HTTPHeader {
char* header;
char* value;
};
struct HTTPHeaders {
struct HTTPHeader** headers;
int num_elements;
};
struct PathPrefixes {
int num_elements;
char** prefixes;
};
struct Gateway {
char* root_redirect;
int writable;
struct PathPrefixes path_prefixes;
struct HTTPHeaders http_headers;
};
int repo_config_gateway_http_header_init(struct HTTPHeaders* http_headers, char** headers, char** values, int num_elements);
#endif /* gateway_h */

View File

@ -0,0 +1,33 @@
//
// swarm.h
// c-ipfs
//
// Created by John Jones on 11/2/16.
// Copyright © 2016 JMJAtlanta. All rights reserved.
//
#ifndef swarm_h
#define swarm_h
struct SwarmAddresses {
int num_addresses;
char** addresses;
};
/**
* add addresses to the SwarmAddresses struct
* @param swarm_addresses the structure
* @param addresses the array of addresses to store
* @param array_length the number of elements in addresses array
* @returns true(1) on success
*/
int repo_config_swarm_address_init(struct SwarmAddresses* swarm_addresses, char** addresses, int array_length);
/***
* free up memory from repo_config_swarm_address_init
* @param swarm_addresses the structure
* @returns true(1)
*/
int repo_config_swarm_address_free(struct SwarmAddresses* swarm_addresses);
#endif /* swarm_h */

View File

@ -0,0 +1,31 @@
//
// ipfs_addr.h
// c-ipfs
//
// Created by John Jones on 11/2/16.
// Copyright © 2016 JMJAtlanta. All rights reserved.
//
#ifndef ipfs_addr_h
#define ipfs_addr_h
struct IPFSAddr {
char* entire_string;
};
/**
* initialize a new IPFSAddr struct. NOTE: be sure to use ipfsaddr_free()
* @param addr the struct to initialize
* @param string the string that contains the address
* @returns true(1) on success, false(0) otherwise
*/
int ipfsaddr_init_new(struct IPFSAddr** addr, char* string);
/***
* frees allocated memory in the struct
* @param addr the struct that is going away
* @returns true(1) on success, false(0) otherwise
*/
int ipfsaddr_free(struct IPFSAddr* addr);
#endif /* ipfs_addr_h */

36
repo/config/addresses.c Normal file
View File

@ -0,0 +1,36 @@
//
// addresses.c
// c-ipfs
//
// Created by John Jones on 11/2/16.
// Copyright © 2016 JMJAtlanta. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ipfs/repo/config/addresses.h"
char* alloc_and_copy(char* source) {
unsigned long strLen = strlen(source);
char* result = malloc(sizeof(char) * (strLen + 1));
strncpy(result, source, strLen);
result[strLen] = 0;
return result;
}
int repo_config_addresses_init(struct Addresses* addresses, char* api, char* gateway) {
// allocate memory to store api and gateway
addresses->api = alloc_and_copy(api);
addresses->gateway = alloc_and_copy(gateway);
if (addresses->api == NULL || addresses->gateway == NULL)
return 0;
return 1;
}
int repo_config_addresses_free(struct Addresses* addresses) {
free(addresses->api);
free(addresses->gateway);
return 1;
}

View File

@ -0,0 +1,54 @@
//
// bootstrap_peers.c
// c-ipfs
//
// Created by John Jones on 11/2/16.
// Copyright © 2016 JMJAtlanta. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include "ipfs/thirdparty/ipfsaddr/ipfs_addr.h"
#include "ipfs/repo/config/bootstrap_peers.h"
int repo_config_bootstrap_peers_retrieve(struct BootstrapPeers* list) {
char* default_bootstrap_addresses[] = {
"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
"/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z", // neptune.i.ipfs.io
"/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM", // pluto.i.ipfs.io
"/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm", // uranus.i.ipfs.io
"/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", // saturn.i.ipfs.io
"/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", // venus.i.ipfs.io
"/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd", // earth.i.ipfs.io
"/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3", // mercury.i.ipfs.io
"/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx", // jupiter.i.ipfs.io
};
list->num_peers = 9;
// allocate memory for list
list->peers = malloc(sizeof(struct IPFSAddr*) * list->num_peers);
for(int i = 0; i < list->num_peers; i++) {
// allocate memory for struct
struct IPFSAddr* currAddr = malloc(sizeof(struct IPFSAddr));
if (currAddr == NULL)
return 0;
// allocate memory for string
if (ipfsaddr_init_new(&currAddr, default_bootstrap_addresses[i]) == 0)
return 0;
list->peers[i] = currAddr;
}
return 1;
}
int repo_config_bootstrap_peers_free(struct BootstrapPeers* list) {
int array_size = sizeof(list);
for(int i = 0; i < array_size; i++) {
ipfsaddr_free(list->peers[i]);
free(list->peers[i]);
}
return 1;
}

View File

@ -12,7 +12,8 @@
#include "config.h"
#include "ipfs/os/utils.h"
#include "ipfs/repo/config/bootstrap_peers.h"
#include "ipfs/repo/config/swarm.h"
/***
* public
@ -81,76 +82,55 @@ int config_get_file_name(char* path, char* result) {
* @param num_bits_for_keypair number of bits for the key pair
* @returns true(1) on success, otherwise 0
*/
int repo_config_init(struct RepoConfig* config, unsigned int num_bits_for_keypair) {
//TODO: convert to c
struct Identity* identity;
repo_config_identity_new(identity, num_bits_for_keypair);
return 0;
//TODO
/*
identity, err := identityConfig(out, nBitsForKeypair)
if err != nil {
return nil, err
}
int repo_config_init(struct RepoConfig* config, unsigned int num_bits_for_keypair, char* repo_path) {
bootstrapPeers, err := DefaultBootstrapPeers()
if err != nil {
return nil, err
}
// identity
int retVal = repo_config_identity_new(&(config->identity), num_bits_for_keypair);
if (retVal == 0)
return 0;
datastore, err := datastoreConfig()
if err != nil {
return nil, err
}
// bootstrap peers
retVal = repo_config_bootstrap_peers_retrieve(&(config->peer_addresses));
if (retVal == 0)
return 0;
conf := &Config{
// setup the node's default addresses.
// NOTE: two swarm listen addrs, one tcp, one utp.
Addresses: Addresses{
Swarm: []string{
"/ip4/0.0.0.0/tcp/4001",
// "/ip4/0.0.0.0/udp/4002/utp", // disabled for now.
"/ip6/::/tcp/4001",
},
API: "/ip4/127.0.0.1/tcp/5001",
Gateway: "/ip4/127.0.0.1/tcp/8080",
},
Datastore: datastore,
Bootstrap: BootstrapPeerStrings(bootstrapPeers),
Identity: identity,
Discovery: Discovery{MDNS{
Enabled: true,
Interval: 10,
}},
// setup the node mount points.
Mounts: Mounts{
IPFS: "/ipfs",
IPNS: "/ipns",
},
Ipns: Ipns{
ResolveCacheSize: 128,
},
Gateway: Gateway{
RootRedirect: "",
Writable: false,
PathPrefixes: []string{},
HTTPHeaders: map[string][]string{
"Access-Control-Allow-Origin": []string{"*"},
"Access-Control-Allow-Methods": []string{"GET"},
"Access-Control-Allow-Headers": []string{"X-Requested-With"},
},
},
Reprovider: Reprovider{
Interval: "12h",
},
}
// datastore
retVal = repo_config_datastore_init(&(config->datastore), repo_path);
if (retVal == 0)
return 0;
retVal = repo_config_addresses_init(&(config->addresses), "/ip4/127.0.0.1/tcp/5001", "/ip4/127.0.0.1/tcp/8080");
if (retVal == 0)
return 0;
return conf, nil
*/
// swarm addresses
char** address_array = (char * []){ "/ip4/0.0.0.0/tcp/4001", "/ip6/::/tcp/4001" };
retVal = repo_config_swarm_address_init(&(config->addresses.swarm), address_array, 2);
if (retVal == 0)
return 0;
config->discovery.mdns.enabled = 1;
config->discovery.mdns.interval = 10;
config->mounts.ipfs = "/ipfs";
config->mounts.ipns = "/ipns";
config->ipns.resolve_cache_size = 128;
config->reprovider.interval = "12h";
config->gateway.root_redirect = "";
config->gateway.writable = 0;
config->gateway.path_prefixes.num_elements = 0;
// gateway http headers
char** header_array = (char * []) { "Access-Control-Allow-Origin", "Access-Control-Allow-Methods", "Access-Control-Allow-Headers" };
char** header_values = (char*[]) { "*", "GET", "X-Requested-With" };
retVal = repo_config_gateway_http_header_init(&(config->gateway.http_headers), header_array, header_values, 3);
if (retVal == 0)
return 0;
return 1;
}

41
repo/config/datastore.c Normal file
View File

@ -0,0 +1,41 @@
//
// 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
*/
int repo_config_datastore_init(struct Datastore* datastore, char* config_root) {
unsigned long stringLength = strlen(config_root) + 12;
datastore->path = malloc(sizeof(char) * stringLength);
os_utils_filepath_join(config_root, "/datastore", datastore->path, stringLength);
datastore->type = "leveldb";
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;
}
/***
* deallocate the memory and clear resources from a datastore_init
* @param datastore the struct to deallocate
* @returns true(1)
*/
int repo_config_datastore_free(struct Datastore* datastore) {
//free(datastore);
return 1;
}

43
repo/config/gateway.c Normal file
View File

@ -0,0 +1,43 @@
//
// gateway.c
// c-ipfs
//
// Created by John Jones on 11/2/16.
// Copyright © 2016 JMJAtlanta. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ipfs/repo/config/gateway.h"
char* alloc_and_fill(char* source) {
char* newString = malloc(sizeof(char) * (strlen(source) + 1));
strncpy(newString, source, strlen(source));
newString[strlen(source)] = 0;
return newString;
}
int repo_config_gateway_http_header_init(struct HTTPHeaders* http_headers, char** headers, char** values, int num_elements) {
// allocate memory for array
http_headers->headers = malloc(sizeof(struct HTTPHeader*) * num_elements);
if (http_headers->headers == NULL) {
http_headers->num_elements = 0;
return 0;
}
// now fill in the array
for(int i = 0; i < num_elements; i++) {
http_headers->headers[i] = malloc(sizeof(struct HTTPHeader));
if (http_headers->headers[i] == NULL) {
http_headers->num_elements = i;
return 0;
}
http_headers->headers[i]->header = alloc_and_fill(headers[i]);
http_headers->headers[i]->value = alloc_and_fill(values[i]);
}
http_headers->num_elements = num_elements;
return 1;
}

View File

@ -84,20 +84,19 @@ exit:
*/
/***
* initializes a new Identity (this should be moved to identity.h)
* initializes a new Identity
* @param identity the identity to fill
* @param num_bits_for_keypair the number of bits for the keypair
* @returns true(1) on success, false(0) otherwise
*/
int repo_config_identity_new(struct Identity* identity, unsigned long num_bits_for_keypair) {
identity = malloc(sizeof(struct Identity));
if (num_bits_for_keypair < 1024)
return 0;
// generate the private key (& public)
if (!repo_config_identity_generate_keypair(&identity->private_key, num_bits_for_keypair))
if (!repo_config_identity_generate_keypair( &(identity->private_key), num_bits_for_keypair))
return 0;
// TODO: Get ID from public key
// TODO: Store peer id in identity struct
return 0;
return 1;
}

40
repo/config/swarm.c Normal file
View File

@ -0,0 +1,40 @@
//
// swarm.c
// c-ipfs
//
// Created by John Jones on 11/2/16.
// Copyright © 2016 JMJAtlanta. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ipfs/repo/config/swarm.h"
int repo_config_swarm_address_init(struct SwarmAddresses* swarm_addresses, char** addresses, int array_length) {
// allocate memory for the addresses array
swarm_addresses->addresses = malloc(sizeof(char*) * array_length);
if (swarm_addresses->addresses == NULL)
return 0;
// copy in all the strings
for(int i = 0; i < array_length; i++) {
char* newString = malloc(sizeof(char) * (strlen(addresses[i]) + 1));
if (newString == NULL)
return 0;
strncpy(newString, addresses[i], strlen(addresses[i]));
newString[strlen(addresses[i])] = 0;
swarm_addresses->addresses[i] = newString;
}
return 1;
}
int repo_config_swarm_address_free(struct SwarmAddresses* swarm_addresses) {
for (int i = 0; i < swarm_addresses->num_addresses; i++) {
free(swarm_addresses->addresses[i]);
}
free(swarm_addresses->addresses);
return 1;
}

View File

@ -8,7 +8,7 @@
#include "ipfs/commands/argument.h"
#include <stdio.h>
#include <string.h>
//#include <string.h>
int test_get_init_command() {
struct Command cmd = { 0 };

View File

@ -1,13 +0,0 @@
#ifndef __TEST_REPO_H__
#define __TEST_REPO_H__
#include "ipfs/repo/repo.h"
#include <stdio.h>
int test_config_repo() {
return 0;
}
#endif

View File

@ -0,0 +1,46 @@
//
// test_repo_bootstrap_peers.h
// c-ipfs
//
// Created by John Jones on 11/2/16.
// Copyright © 2016 JMJAtlanta. All rights reserved.
//
#ifndef test_repo_bootstrap_peers_h
#define test_repo_bootstrap_peers_h
//#include <string.h>
#include "ipfs/repo/config/bootstrap_peers.h"
int test_repo_bootstrap_peers_init() {
char* default_bootstrap_addresses[] = {
"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
"/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z", // neptune.i.ipfs.io
"/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM", // pluto.i.ipfs.io
"/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm", // uranus.i.ipfs.io
"/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", // saturn.i.ipfs.io
"/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", // venus.i.ipfs.io
"/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd", // earth.i.ipfs.io
"/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3", // mercury.i.ipfs.io
"/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx", // jupiter.i.ipfs.io
};
struct BootstrapPeers list;
int retVal = 1;
repo_config_bootstrap_peers_retrieve(&list);
if ( list.num_peers != 9) {
printf("Size does not equal 9 in test_repo_bootstrap_peers_init");
retVal = 0;
}
for(int i = 0; i < list.num_peers; i++) {
unsigned long strLen = strlen(default_bootstrap_addresses[i]);
if (strncmp(list.peers[i]->entire_string, default_bootstrap_addresses[i], strLen) != 0)
printf("The value of element %d is: %s\n", i, list.peers[i]->entire_string);
}
repo_config_bootstrap_peers_free(&list);
return retVal;
}
#endif /* test_repo_bootstrap_peers_h */

View File

@ -9,6 +9,29 @@
#ifndef test_repo_config_h
#define test_repo_config_h
#include "ipfs/repo/config/config.h"
int test_repo_config_init() {
struct RepoConfig repoConfig;
int retVal = repo_config_init(&repoConfig, 2048, "/Users/JohnJones/.ipfs");
if (retVal == 0)
return 0;
// now tear it apart to check for anything broken
// addresses
retVal = strncmp(repoConfig.addresses.api, "/ip4/127.0.0.1/tcp/5001", 23);
if (retVal != 0)
return 0;
retVal = strncmp(repoConfig.addresses.gateway, "/ip4/127.0.0.1/tcp/8080", 23);
if (retVal != 0)
return 0;
// datastore
retVal = strncmp(repoConfig.datastore.path, "/Users/JohnJones/.ipfs/datastore", 32);
if (retVal != 0)
return 0;
return 1;
}
#endif /* test_repo_config_h */

View File

@ -15,8 +15,15 @@
#include "ipfs/repo/config/base64.h"
int test_repo_config_identity_new() {
struct Identity* identity;
return repo_config_identity_new(identity, 2046);
struct Identity identity;
int retVal = repo_config_identity_new(&identity, 2046);
// now examine it
int privateKeySize = sizeof(identity.private_key);
if (privateKeySize != 72) {
printf("Private key structure size should be 72");
retVal = 0;
}
return retVal;
}
// test this key
@ -25,9 +32,17 @@ int test_repo_config_identity_private_key() {
size_t decoded_len = base64_decode_length(priv_b64, strlen(priv_b64));
char* out_buff = malloc(sizeof(char) * decoded_len);
base64_decode(priv_b64, strlen(priv_b64), out_buff, decoded_len, &decoded_len);
char str[decoded_len];
int j = 0;
for (int i = 0; i < decoded_len; i++) {
printf("%hhX ", out_buff[i]);
if (out_buff[i] >= 32 && out_buff[i] <= 127) {
str[j] = out_buff[i];
j++;
}
printf("%hhX-%c ", out_buff[i], out_buff[i]);
}
out_buff[j] = 0;
printf("String: %s", str);
// now test
return 0;

View File

@ -1,6 +1,7 @@
#include "testit.h"
#include "repo/test_repo.h"
#include "repo/test_repo_config.h"
#include "repo/test_repo_identity.h"
#include "repo/test_repo_bootstrap_peers.h"
#include "cmd/ipfs/test_init.h"
int testit(const char* name, int (*func)(void)) {
@ -14,9 +15,11 @@ int testit(const char* name, int (*func)(void)) {
}
int main(int argc, char** argv) {
testit("config_repo", test_config_repo);
testit("test_repo_config_init", test_repo_config_init);
testit("test_repo_config_identity_new", test_repo_config_identity_new);
testit("test_repo_config_identity_private_key", test_repo_config_identity_private_key);
testit("test_reop_bootstrap_peers_init", test_repo_bootstrap_peers_init);
testit("get_init_command", test_get_init_command);
return 1;
}

27
thirdparty/ipfsaddr/ipfs_addr.c vendored Normal file
View File

@ -0,0 +1,27 @@
//
// ipfs_addr.c
// c-ipfs
//
// Created by John Jones on 11/2/16.
// Copyright © 2016 JMJAtlanta. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ipfs/thirdparty/ipfsaddr/ipfs_addr.h"
int ipfsaddr_init_new(struct IPFSAddr** addr, char* string) {
(*addr)->entire_string = malloc(sizeof(char) * (strlen(string) + 1));
if ((*addr)->entire_string == NULL)
return 0;
strncpy((*addr)->entire_string, string, strlen(string));
return 1;
}
int ipfsaddr_free(struct IPFSAddr* addr) {
if (addr->entire_string != NULL)
free(addr->entire_string);
return 1;
}