forked from agorise/c-ipfs
e8b8d06f24
Now attempting to use kademlia to find a hash, and NodeIO to transfer the file
42 lines
1.1 KiB
C
42 lines
1.1 KiB
C
#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_new(struct Addresses** addresses, char* api, char* gateway) {
|
|
*addresses = (struct Addresses*)malloc(sizeof(struct Addresses));
|
|
if (*addresses == NULL)
|
|
return 0;
|
|
|
|
struct Addresses* addr = *addresses;
|
|
// allocate memory to store api and gateway
|
|
addr->api = alloc_and_copy(api);
|
|
addr->gateway = alloc_and_copy(gateway);
|
|
if ( addr->api == NULL || addr->gateway == NULL)
|
|
return 0;
|
|
|
|
// allocate memory for swarm_addresses
|
|
//if (repo_config_swarm_address_new(&((*addresses)->swarm)) == 0)
|
|
// return 0;
|
|
// this is now allocated when it is filled
|
|
addr->swarm_head = NULL;
|
|
|
|
return 1;
|
|
}
|
|
|
|
int repo_config_addresses_free(struct Addresses* addresses) {
|
|
free(addresses->api);
|
|
free(addresses->gateway);
|
|
libp2p_utils_linked_list_free(addresses->swarm_head);
|
|
free(addresses);
|
|
return 1;
|
|
}
|