Compare commits

...

25 Commits

Author SHA1 Message Date
Agorise e599dd2f34
Create FUNDING.yml 2019-06-12 16:54:37 -05:00
Jose Marcial Vieira Bisneto ee0c287a34
Fix compilation reported in issue #16 2019-01-02 21:36:18 -03:00
Jose Marcial Vieira Bisneto 662825493d
Dependencies: add c-libp2p and lmdb as submodules 2019-01-02 12:51:29 -03:00
Agorise 0432315d33
Update LICENSE 2019-01-01 10:39:45 -06:00
Jose Marcial Vieira Bisneto 9491e69d76
Added ipns support for cat/get commands. 2018-10-25 19:14:47 -03:00
Jose Marcial Vieira Bisneto 94b782cfaa
Implemented simple json parsing reusing jsmn. 2018-10-25 19:00:32 -03:00
Jose Marcial Vieira Bisneto 35b20c9a2e
Changed some erroneously labeled messages as an error. 2018-10-25 18:44:19 -03:00
Agorise 0037be0594
Update LICENSE 2018-05-31 09:50:52 +03:00
John Jones a0731525ea Changes for building the identify handler 2017-11-30 15:27:52 -05:00
John Jones 31e6142e68 debugging yamux / identify 2017-11-30 14:33:13 -05:00
John Jones 30a59c950e re-fix from broken merge 2017-11-29 06:45:24 -05:00
John Jones 8644dbbb56 Merge branch 'master' of https://github.com/Agorise/c-ipfs 2017-11-29 06:23:51 -05:00
Agorise d9f8260c6e
Update LICENSE 2017-11-15 13:11:34 +02:00
John M. Jones 5e034f14bc
Update README.md 2017-11-02 06:02:09 -05:00
John M. Jones 01e5222ea7
Update README.md 2017-11-02 06:01:12 -05:00
John M. Jones 0b6add5146
Update README.md 2017-11-02 06:00:14 -05:00
John M. Jones db0a519e66
Update README.md 2017-11-02 05:58:38 -05:00
John M. Jones df7a3e8761
Update README.md 2017-11-02 05:56:21 -05:00
John M. Jones 1fdd490e89
Update README.md 2017-11-02 05:54:03 -05:00
John M. Jones eeabd85bc3
Update README.md 2017-11-02 05:52:19 -05:00
John M. Jones 77dc2f1472
Update README.md 2017-11-02 05:50:58 -05:00
jmjatlanta 80f97f4aff Added quick start to readme 2017-11-02 05:43:45 -05:00
jmjatlanta 8ce3c68b72 Added quick start to readme 2017-11-02 05:43:01 -05:00
jmjatlanta e839163d91 Added quick start to readme 2017-11-02 05:42:17 -05:00
jmjatlanta 711ec1df30 Added quick start to readme 2017-11-02 05:39:03 -05:00
48 changed files with 240 additions and 82 deletions

3
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,3 @@
# These are supported funding model platforms
custom: https://www.blockchain.com/btc/payment_request?address=1AFGT5gVj7xhfjgHTuwEoaV56WTCh7Gjf1#BITCOIN_ONLY

7
.gitmodules vendored Normal file
View File

@ -0,0 +1,7 @@
[submodule "c-libp2p"]
path = c-libp2p
url = https://github.com/Agorise/c-libp2p.git
[submodule "lmdb"]
path = lmdb
url = https://github.com/jmjatlanta/lmdb.git
branch = mdb.master

View File

@ -1,6 +1,8 @@
MIT License
Copyright (c) 2017 Agorise, IBC.
Copyright (c) 2019 AGORISE, LTD.
An International Business Company, Cyprus Reg# ΗΕ375959
Contains works from BitShares Munich IVS
Permission is hereby granted, free of charge, to any person obtaining a copy

View File

@ -3,7 +3,8 @@ DEBUG = true
export DEBUG
all:
#cd ../c-libp2p; make all;
cd c-libp2p; make all;
cd lmdb/libraries/liblmdb; make all;
cd blocks; make all;
cd cid; make all;
cd cmd; make all;
@ -27,8 +28,10 @@ all:
cd util; make all;
cd main; make all;
cd test; make all;
clean:
cd c-libp2p; make clean;
cd lmdb/libraries/liblmdb; make clean;
cd blocks; make clean;
cd cid; make clean;
cd cmd; make clean;

View File

@ -1,18 +1,28 @@
# C-IPFS
IPFS implementation in C, (not just an API client library).<br>
<br>
getting started: https://github.com/ipfs/specs/blob/master/overviews/implement-ipfs.md <br>
specifications: https://github.com/ipfs/specs <br>
getting started: https://github.com/ipfs/community/issues/177 <br>
libp2p: https://github.com/libp2p/specs <br>
<br>
Prerequisites: To compile the C version you will need:<br>
lmdb https://github.com/jmjatlanta/lmdb<br>
c-protobuf https://github.com/Agorise/c-protobuf<br>
c-multihash https://github.com/Agorise/c-multihash<br>
c-multiaddr https://github.com/Agorise/c-multiaddr<br>
c-libp2p https://github.com/Agorise/c-libp2p<br>
<br>
And of course this project at https://github.com/Agorise/c-ipfs<br>
<br>
The compilation at this point is simple, but not very flexible. Place all of these projects in a directory. Compile all (the order above is recommended) by going into each one and running "make all".
IPFS implementation in C, (not just an API client library).
## Quick start for users:
* **ipfs init** to create an ipfs repository on your machine
* **ipfs add MyFile.txt** to add a file to the repository, will return with a hash that can be used to retrieve the file.
* **ipfs cat _hash_** to retrieve a file from the repository
## For techies (ipfs spec docs):
* [getting started](https://github.com/ipfs/specs/blob/master/overviews/implement-ipfs.md)
* [specifications](https://github.com/ipfs/specs)
* [getting started](https://github.com/ipfs/community/issues/177)
* [libp2p](https://github.com/libp2p/specs)
## Prerequisites: To compile the C version you will need, all included as submodules:
* [lmdb](https://github.com/jmjatlanta/lmdb)
* [c-protobuf](https://github.com/Agorise/c-protobuf)
* [c-multihash](https://github.com/Agorise/c-multihash)
* [c-multiaddr](https://github.com/Agorise/c-multiaddr)
* [c-libp2p](https://github.com/Agorise/c-libp2p)
And of course this project at https://github.com/Agorise/c-ipfs
## How to compile the C version:
```
git submodule update --init --recursive
make all
```

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -Wall
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

1
c-libp2p Submodule

@ -0,0 +1 @@
Subproject commit d0c319a88cd1f2cb3a219420b5a0b930e72562e2

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -Wall
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multiaddr/include -I../../c-protobuf -Wall
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3
@ -20,4 +20,4 @@ all: $(OBJS)
clean:
rm -f *.o
cd ipfs; make clean;
cd ipfs; make clean;

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../../include -I../../../c-libp2p/include -I../../../c-multiaddr/include -I../../../c-protobuf -Wall
CFLAGS = -O0 -I../../include -I../../c-libp2p/include -I../../c-libp2p/c-multiaddr/include -I../../c-libp2p/c-protobuf -Wall
ifdef DEBUG
CFLAGS += -g3
@ -19,4 +19,4 @@ all: $(OBJS)
clean:
rm -f *.o
rm -f ipfs
rm -f ipfs

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -Wall -std=c99
CFLAGS = -O0 -I../include -I../c-libp2p/include -Wall -std=gnu99
LFLAGS =
DEPS = ../include/ipfs/commands/argument.h ../include/ipfs/commands/command_option.h \
../include/ipfs/commands/command.h ../include/ipfs/commands/context.h \

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../../include -I../../../c-libp2p/include -Wall
CFLAGS = -O0 -I../../include -I../../c-libp2p/include -Wall
LFLAGS =
DEPS = parse.h
OBJS = parse.o

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multiaddr/include -I../../c-protobuf -Wall -std=c11
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -750,7 +750,7 @@ int api_start (struct IpfsNode* local_node, int max_conns, int timeout)
return 0;
}
libp2p_logger_debug("api", "Started API on localhost port %d.\n", port);
libp2p_logger_info("api", "API server listening on %d.\n", port);
return 1;
}

View File

@ -70,8 +70,9 @@ int ipfs_daemon (int argc, char **argv)
{
char* repo_path = NULL;
libp2p_logger_add_class("daemon");
if (!ipfs_repo_get_directory(argc, argv, &repo_path)) {
fprintf(stderr, "Unable to open repo: %s\n", repo_path);
libp2p_logger_error("daemon", "Unable to open repo: %s\n", repo_path);
return 0;
}

View File

@ -295,6 +295,66 @@ int ipfs_core_http_process_dht(struct IpfsNode* local_node, struct HttpRequest*
return retVal;
}
int ipfs_core_http_process_swarm_connect(struct IpfsNode* local_node, struct HttpRequest* request, struct HttpResponse** resp) {
// get the address
if (request->arguments == NULL || request->arguments->total < 0)
return 0;
const char* address = (char*) libp2p_utils_vector_get(request->arguments, 0);
if (address == NULL)
return 0;
// TODO: see if we are already connected, or at least already have this peer in our peerstore
// attempt to connect
struct MultiAddress* ma = multiaddress_new_from_string(address);
if (ma == NULL) {
libp2p_logger_error("http_request", "swarm_connect: Unable to convert %s to a MultiAddress.\n", address);
return 0;
}
struct Libp2pPeer* new_peer = libp2p_peer_new_from_multiaddress(ma);
if (!libp2p_peer_connect(local_node->dialer, new_peer, local_node->peerstore, local_node->repo->config->datastore, 30)) {
libp2p_logger_error("http_request", "swarm_connect: Unable to connect to peer %s.\n", libp2p_peer_id_to_string(new_peer));
libp2p_peer_free(new_peer);
multiaddress_free(ma);
return 0;
}
*resp = ipfs_core_http_response_new();
struct HttpResponse* response = *resp;
if (response == NULL) {
libp2p_logger_error("http_response", "swarm_connect: Unable to allocate memory for the response.\n");
libp2p_peer_free(new_peer);
multiaddress_free(ma);
return 0;
}
response->content_type = "application/json";
char* json = "{ \"Strings\": [ \"%s\"] }";
response->bytes_size = strlen(json) + strlen(address) + 1;
response->bytes = (uint8_t*) malloc(response->bytes_size);
if (response->bytes == NULL) {
response->bytes_size = 0;
response->content_type = NULL;
libp2p_peer_free(new_peer);
multiaddress_free(ma);
return 0;
}
sprintf((char*)response->bytes, json, address);
// getting rid of the peer here will close the connection. That's not what we want
//libp2p_peer_free(new_peer);
multiaddress_free(ma);
return 1;
}
int ipfs_core_http_process_swarm(struct IpfsNode* local_node, struct HttpRequest* request, struct HttpResponse** response) {
int retVal = 0;
if (strcmp(request->sub_command, "connect") == 0) {
// connect to a peer
retVal = ipfs_core_http_process_swarm_connect(local_node, request, response);
}
return retVal;
}
/***
* Process the parameters passed in from an http request
* @param local_node the context
@ -313,6 +373,8 @@ int ipfs_core_http_request_process(struct IpfsNode* local_node, struct HttpReque
retVal = ipfs_core_http_process_object(local_node, request, response);
} else if (strcmp(request->command, "dht") == 0) {
retVal = ipfs_core_http_process_dht(local_node, request, response);
} else if (strcmp(request->command, "swarm") == 0) {
retVal = ipfs_core_http_process_swarm(local_node, request, response);
}
return retVal;
}

View File

@ -47,7 +47,7 @@ struct Libp2pVector* ipfs_node_online_build_protocol_handlers(struct IpfsNode* n
// yamux
libp2p_utils_vector_add(retVal, libp2p_yamux_build_protocol_handler());
// identify
libp2p_utils_vector_add(retVal, libp2p_identify_build_protocol_handler(retVal));
libp2p_utils_vector_add(retVal, libp2p_identify_build_protocol_handler(node->identity->peer->id, node->identity->peer->id_size));
}
return retVal;
}

View File

@ -165,7 +165,7 @@ void* ipfs_null_listen (void *ptr)
return (void*) 2;
}
libp2p_logger_error("null", "Ipfs listening on %d\n", listen_param->port);
libp2p_logger_info("null", "Ipfs listening on %d\n", listen_param->port);
// when we have nothing to do, check on the connections to see if we're still connected
struct Libp2pLinkedList* current_peer_entry = NULL;

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../lmdb/libraries/liblmdb -I../../c-protobuf -Wall
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../lmdb/libraries/liblmdb -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -Wall
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -std=c99
CFLAGS = -O0 -I../include -I../c-libp2p/include -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../../include -I../../../c-libp2p/include -I../../../c-multiaddr/include -I../../../c-multihash/include -I../../../c-protobuf -Wall -std=c99
CFLAGS = -O0 -I../../include -I../../c-libp2p/include -I../../c-libp2p/c-multiaddr/include -I../../c-libp2p/c-multihash/include -I../../c-libp2p/c-protobuf -Wall -std=c99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,6 +1,6 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -Wall
CFLAGS = -O0 -I../include -I../c-libp2p/include -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -Wall -std=c11
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -11,6 +11,8 @@
#include "ipfs/repo/init.h"
#include "ipfs/core/ipfs_node.h"
#include "libp2p/utils/logger.h"
#include "ipfs/namesys/name.h"
#include "ipfs/repo/fsrepo/jsmn.h"
/**
* pull objects from ipfs
@ -286,8 +288,23 @@ int ipfs_exporter_object_cat(struct CliArguments* args, FILE* output_file) {
}
if (local_node->mode == MODE_API_AVAILABLE) {
const char ipns_prefix[] = "/ipns/";
const char ipfs_prefix[] = "/ipfs/";
char* hash = args->argv[args->verb_index + 1];
libp2p_logger_debug("exporter", "We're attempting to use the API for this object get of %s.\n", hash);
if (memcmp(hash, ipfs_prefix, sizeof(ipfs_prefix)-1) == 0) {
// skip ipfs_prefix;
hash += sizeof(ipfs_prefix)-1;
} else if (memcmp(hash, ipns_prefix, sizeof(ipns_prefix)-1) == 0) {
char *response = NULL;
size_t response_size;
if (ipfs_name_resolve(local_node, hash, &response, &response_size) && response && response_size > 0) {
hash = jsmn_simple_parser(response, response_size, "Path");
if (!hash) {
return 0;
}
}
}
struct HttpRequest* request = ipfs_core_http_request_new();
char* response = NULL;
request->command = "object";

View File

@ -2,6 +2,16 @@
#include "ipfs/cmd/cli.h"
/***
* Publish IPNS name
*/
int ipfs_name_publish(struct IpfsNode* local_node, char* name, char **response, size_t *response_size);
/***
* Resolve IPNS name
*/
int ipfs_name_resolve(struct IpfsNode* local_node, char* name, char **response, size_t *response_size);
/**
* We received a cli command "ipfs name". Do the right thing.
* @param argc number of arguments on the command line

View File

@ -69,6 +69,7 @@ void jsmn_init(jsmn_parser *parser);
int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
jsmntok_t *tokens, unsigned int num_tokens);
char *jsmn_simple_parser(char *full_json, int json_len, char *key);
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multiaddr/include -I../../c-multihash/include -I../../c-protobuf -I../../lmdb/libraries/liblmdb -Wall -std=c99
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-protobuf -I../lmdb/libraries/liblmdb -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

1
lmdb Submodule

@ -0,0 +1 @@
Subproject commit 6b62ada62a10b3185b2dcd51e512dea27e5e3c8e

View File

@ -1,6 +1,6 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -g3 -Wall -std=c99
LFLAGS = -L../../c-libp2p -L../../c-multihash -L../../c-multiaddr -lp2p -lm -lmultihash -lmultiaddr -lpthread -lresolv -lcurl
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -g3 -Wall -std=gnu99
LFLAGS = -L../c-libp2p -L../c-libp2p/c-multihash -L../c-libp2p/c-multiaddr -lp2p -lm -lmultihash -lmultiaddr -lpthread -lresolv -lcurl
DEPS = cmd/ipfs/test_init.h repo/test_repo_bootstrap_peers.h repo/test_repo_config.h repo/test_repo_identity.h cid/test_cid.h
OBJS = main.o \
../blocks/block.o ../blocks/blockstore.o \
@ -27,7 +27,7 @@ OBJS = main.o \
../routing/*.o \
../thirdparty/ipfsaddr/ipfs_addr.o \
../unixfs/unixfs.o \
../../c-protobuf/protobuf.o ../../c-protobuf/varint.o \
../c-libp2p/c-protobuf/protobuf.o ../c-libp2p/c-protobuf/varint.o \
../util/errs.o \
../util/time.o \
../util/thread_pool.o
@ -36,7 +36,7 @@ OBJS = main.o \
$(CC) -c -o $@ $< $(CFLAGS)
ipfs: $(OBJS)
$(CC) -o $@ $^ $(LFLAGS) ../../lmdb/libraries/liblmdb/liblmdb.a
$(CC) -o $@ $^ $(LFLAGS) ../lmdb/libraries/liblmdb/liblmdb.a
all: ipfs

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -Wall -std=c99
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -Wall
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -Wall
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -11,39 +11,43 @@
/***
* Publish IPNS name
*/
int ipfs_name_publish(struct IpfsNode* local_node, char* name) {
int ipfs_name_publish(struct IpfsNode* local_node, char* name, char **response, size_t *response_size) {
// call api.
char* response = NULL;
struct HttpRequest* request = ipfs_core_http_request_new();
if (request == NULL)
return 0;
request->command = "name";
request->sub_command = "publish";
libp2p_utils_vector_add(request->arguments, name);
size_t response_size = 0;
int retVal = ipfs_core_http_request_post(local_node, request, &response, &response_size, "", 0);
if (response != NULL && response_size > 0) {
fwrite(response, 1, response_size, stdout);
free(response);
}
int retVal = ipfs_core_http_request_post(local_node, request, response, response_size, "", 0);
ipfs_core_http_request_free(request);
return retVal;
}
int ipfs_name_resolve(struct IpfsNode* local_node, char* name) {
/***
* Resolve IPNS name
*/
int ipfs_name_resolve(struct IpfsNode* local_node, char* name, char **response, size_t *response_size) {
// ask api
char* response = NULL;
const char prefix[] = "/ipns/";
char *ipns = NULL;
struct HttpRequest* request = ipfs_core_http_request_new();
if (request == NULL)
return 0;
request->command = "name";
request->sub_command = "resolve";
if (memcmp(name, prefix, sizeof(prefix)-1)!=0) {
ipns = malloc(sizeof(prefix) + strlen(name));
if (ipns) {
strcpy(ipns, prefix);
strcat(ipns, name);
name = ipns;
}
}
libp2p_utils_vector_add(request->arguments, name);
size_t response_size = 0;
int retVal = ipfs_core_http_request_post(local_node, request, &response, &response_size, "", 0);
if (response != NULL && response_size > 0) {
fwrite(response, 1, response_size, stdout);
free(response);
int retVal = ipfs_core_http_request_post(local_node, request, response, response_size, "", 0);
if (ipns) {
free(ipns);
}
ipfs_core_http_request_free(request);
return retVal;
@ -77,15 +81,21 @@ int ipfs_name(struct CliArguments* args) {
goto exit;
}
char *response = NULL;
size_t response_size;
// determine what we're doing
if (strcmp(which, "publish") == 0) {
retVal = ipfs_name_publish(client_node, path);
retVal = ipfs_name_publish(client_node, path, &response, &response_size);
} else if (strcmp(which, "resolve") == 0) {
retVal = ipfs_name_resolve(client_node, path);
retVal = ipfs_name_resolve(client_node, path, &response, &response_size);
} else {
libp2p_logger_error("name", "Nothing found on command line. Should be \"name resolve\" or \"name publish\".\n");
goto exit;
}
if (response != NULL && response_size > 0) {
fwrite(response, 1, response_size, stdout);
free(response);
}
exit:
// shut everything down

View File

@ -35,8 +35,6 @@ func NewNameSystem(r routing.ValueStore, ds ds.Datastore, cachesize int) NameSys
}
}*/
const int DefaultResolverCacheTTL = 60;
// ipfs_namesys_resolve implements Resolver.
int ipfs_namesys_resolve(char **path, char *name)
{

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -Wall
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -Wall
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -std=c99
CFLAGS = -O0 -I../include -I../c-libp2p/include -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../../include -I../../../c-libp2p/include -I../../../c-multiaddr/include -I../../../c-multihash/include -I../../../c-protobuf -Wall -std=c99
CFLAGS = -O0 -I../../include -I../../c-libp2p/include -I../../c-libp2p/c-multiaddr/include -I../../c-libp2p/c-multihash/include -I../../c-libp2p/c-protobuf -Wall -std=c99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../../include -I../../../c-libp2p/include -I../../../lmdb/libraries/liblmdb -I../../../c-protobuf -I../../../c-multiaddr/include -Wall -std=c99
CFLAGS = -O0 -I../../include -I../../c-libp2p/include -I../../lmdb/libraries/liblmdb -I../../c-libp2p/c-protobuf -I../../c-libp2p/c-multiaddr/include -Wall -std=c99
ifdef DEBUG
CFLAGS += -g3

View File

@ -13,7 +13,7 @@
#include "ipfs/repo/fsrepo/fs_repo.h"
#include "libp2p/os/utils.h"
#include "ipfs/repo/fsrepo/lmdb_datastore.h"
#include "jsmn.h"
#include "ipfs/repo/fsrepo/jsmn.h"
#include "multiaddr/multiaddr.h"
/**

View File

@ -1,4 +1,6 @@
#include "jsmn.h"
#include "ipfs/repo/fsrepo/jsmn.h"
#include <string.h>
#include <stdlib.h>
/**
* Allocates a fresh unused token from the token pull.
@ -311,3 +313,32 @@ void jsmn_init(jsmn_parser *parser) {
parser->toknext = 0;
parser->toksuper = -1;
}
char *jsmn_simple_parser(char *full_json, int json_len, char *key) {
int num_tokens = 256, len, i;
if (!full_json || !key) {
return NULL;
}
jsmn_parser parser;
jsmn_init(&parser);
jsmntok_t tokens[num_tokens];
num_tokens = jsmn_parse(&parser, full_json, json_len, tokens, 256);
if (num_tokens <= 0) {
return NULL;
}
len = strlen(key);
for (i = 0; i < num_tokens; i++) {
jsmntok_t curr_token = tokens[i];
if (len == (curr_token.end - curr_token.start) && memcmp(full_json + curr_token.start, key, len) == 0) {
curr_token = tokens[i+1];
len = curr_token.end - curr_token.start;
char *ret = malloc(len + 1);
if (!ret) {
return NULL;
}
strncpy(ret, full_json + curr_token.start, len);
return ret;
}
}
return NULL;
}

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multiaddr/include -I../../c-protobuf -Wall -std=c99
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,6 +1,6 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -I../../lmdb/libraries/liblmdb -g3 -Wall -std=c99
LFLAGS = -L../../c-libp2p -L../../c-multihash -L../../c-multiaddr -lp2p -lm -lmultihash -lmultiaddr -lpthread -lcurl
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -I../lmdb/libraries/liblmdb -g3 -Wall -std=gnu99
LFLAGS = -L../c-libp2p -L../c-libp2p/c-multihash -L../c-libp2p/c-multiaddr -lp2p -lm -lmultihash -lmultiaddr -lpthread -lcurl
DEPS = cmd/ipfs/test_init.h repo/test_repo_bootstrap_peers.h repo/test_repo_config.h repo/test_repo_identity.h cid/test_cid.h
OBJS = testit.o test_helper.o \
../blocks/block.o ../blocks/blockstore.o \
@ -30,13 +30,13 @@ OBJS = testit.o test_helper.o \
../thirdparty/ipfsaddr/ipfs_addr.o \
../unixfs/unixfs.o \
../util/thread_pool.o \
../../c-protobuf/protobuf.o ../../c-protobuf/varint.o
../c-libp2p/c-protobuf/protobuf.o ../c-libp2p/c-protobuf/varint.o
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
test_ipfs: $(OBJS)
$(CC) -o $@ $^ $(LFLAGS) ../../lmdb/libraries/liblmdb/liblmdb.a
$(CC) -o $@ $^ $(LFLAGS) ../lmdb/libraries/liblmdb/liblmdb.a
all: test_ipfs

View File

@ -19,12 +19,13 @@ int test_compat_go_join_swarm() {
libp2p_logger_add_class("test_api");
libp2p_logger_add_class("identify");
libp2p_logger_add_class("null");
libp2p_logger_add_class("multistream");
libp2p_logger_add_class("swarm");
libp2p_logger_add_class("secio");
*/
libp2p_logger_add_class("dialer");
libp2p_logger_add_class("yamux");
libp2p_logger_add_class("multistream");
libp2p_logger_add_class("threadsafe_buffer");
// Here is the connection information for the GO version:
char* remote_string = "/ip4/10.211.55.2/tcp/4001/ipfs/QmacSE6bCZiAu7nrYkhPATaSoL2q9BszkKzbX6fCiXuBGA";

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../../include -I../../../c-libp2p/include
CFLAGS = -O0 -I../../include -I../../c-libp2p/include
LFLAGS =
DEPS =
OBJS = ipfs_addr.o

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -Wall
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3

View File

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -Wall
CFLAGS = -O0 -I../include -I../c-libp2p/include -I../c-libp2p/c-multihash/include -I../c-libp2p/c-multiaddr/include -I../c-libp2p/c-protobuf -Wall -std=gnu99
ifdef DEBUG
CFLAGS += -g3