Compare commits

...

10 commits

47 changed files with 155 additions and 67 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,6 @@
MIT License MIT License
Copyright (c) 2017 AGORISE, LTD. Copyright (c) 2019 AGORISE, LTD.
An International Business Company, Cyprus Reg# ΗΕ375959 An International Business Company, Cyprus Reg# ΗΕ375959
Contains works from BitShares Munich IVS Contains works from BitShares Munich IVS

View file

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

View file

@ -12,7 +12,7 @@ IPFS implementation in C, (not just an API client library).
* [getting started](https://github.com/ipfs/community/issues/177) * [getting started](https://github.com/ipfs/community/issues/177)
* [libp2p](https://github.com/libp2p/specs) * [libp2p](https://github.com/libp2p/specs)
## Prerequisites: To compile the C version you will need: ## Prerequisites: To compile the C version you will need, all included as submodules:
* [lmdb](https://github.com/jmjatlanta/lmdb) * [lmdb](https://github.com/jmjatlanta/lmdb)
* [c-protobuf](https://github.com/Agorise/c-protobuf) * [c-protobuf](https://github.com/Agorise/c-protobuf)
* [c-multihash](https://github.com/Agorise/c-multihash) * [c-multihash](https://github.com/Agorise/c-multihash)
@ -21,4 +21,8 @@ IPFS implementation in C, (not just an API client library).
And of course this project at https://github.com/Agorise/c-ipfs And of course this project at https://github.com/Agorise/c-ipfs
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". ## How to compile the C version:
```
git submodule update --init --recursive
make all
```

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

1
c-libp2p Submodule

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

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3
@ -20,4 +20,4 @@ all: $(OBJS)
clean: clean:
rm -f *.o rm -f *.o
cd ipfs; make clean; cd ipfs; make clean;

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3
@ -19,4 +19,4 @@ all: $(OBJS)
clean: clean:
rm -f *.o rm -f *.o
rm -f ipfs rm -f ipfs

View file

@ -1,5 +1,5 @@
CC = gcc 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 = LFLAGS =
DEPS = ../include/ipfs/commands/argument.h ../include/ipfs/commands/command_option.h \ DEPS = ../include/ipfs/commands/argument.h ../include/ipfs/commands/command_option.h \
../include/ipfs/commands/command.h ../include/ipfs/commands/context.h \ ../include/ipfs/commands/command.h ../include/ipfs/commands/context.h \

View file

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

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

@ -750,7 +750,7 @@ int api_start (struct IpfsNode* local_node, int max_conns, int timeout)
return 0; 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; return 1;
} }

View file

@ -70,8 +70,9 @@ int ipfs_daemon (int argc, char **argv)
{ {
char* repo_path = NULL; char* repo_path = NULL;
libp2p_logger_add_class("daemon");
if (!ipfs_repo_get_directory(argc, argv, &repo_path)) { 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; return 0;
} }

View file

@ -47,7 +47,7 @@ struct Libp2pVector* ipfs_node_online_build_protocol_handlers(struct IpfsNode* n
// yamux // yamux
libp2p_utils_vector_add(retVal, libp2p_yamux_build_protocol_handler()); libp2p_utils_vector_add(retVal, libp2p_yamux_build_protocol_handler());
// identify // 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; return retVal;
} }

View file

@ -165,7 +165,7 @@ void* ipfs_null_listen (void *ptr)
return (void*) 2; 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 // when we have nothing to do, check on the connections to see if we're still connected
struct Libp2pLinkedList* current_peer_entry = NULL; struct Libp2pLinkedList* current_peer_entry = NULL;

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

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

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

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

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

@ -11,6 +11,8 @@
#include "ipfs/repo/init.h" #include "ipfs/repo/init.h"
#include "ipfs/core/ipfs_node.h" #include "ipfs/core/ipfs_node.h"
#include "libp2p/utils/logger.h" #include "libp2p/utils/logger.h"
#include "ipfs/namesys/name.h"
#include "ipfs/repo/fsrepo/jsmn.h"
/** /**
* pull objects from ipfs * 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) { 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]; 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); 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(); struct HttpRequest* request = ipfs_core_http_request_new();
char* response = NULL; char* response = NULL;
request->command = "object"; request->command = "object";

View file

@ -2,6 +2,16 @@
#include "ipfs/cmd/cli.h" #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. * We received a cli command "ipfs name". Do the right thing.
* @param argc number of arguments on the command line * @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, int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
jsmntok_t *tokens, unsigned int num_tokens); jsmntok_t *tokens, unsigned int num_tokens);
char *jsmn_simple_parser(char *full_json, int json_len, char *key);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

1
lmdb Submodule

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

View file

@ -1,6 +1,6 @@
CC = gcc 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 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-multihash -L../../c-multiaddr -lp2p -lm -lmultihash -lmultiaddr -lpthread -lresolv -lcurl 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 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 \ OBJS = main.o \
../blocks/block.o ../blocks/blockstore.o \ ../blocks/block.o ../blocks/blockstore.o \
@ -27,7 +27,7 @@ OBJS = main.o \
../routing/*.o \ ../routing/*.o \
../thirdparty/ipfsaddr/ipfs_addr.o \ ../thirdparty/ipfsaddr/ipfs_addr.o \
../unixfs/unixfs.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/errs.o \
../util/time.o \ ../util/time.o \
../util/thread_pool.o ../util/thread_pool.o
@ -36,7 +36,7 @@ OBJS = main.o \
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)
ipfs: $(OBJS) ipfs: $(OBJS)
$(CC) -o $@ $^ $(LFLAGS) ../../lmdb/libraries/liblmdb/liblmdb.a $(CC) -o $@ $^ $(LFLAGS) ../lmdb/libraries/liblmdb/liblmdb.a
all: ipfs all: ipfs

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

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

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

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

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

@ -13,7 +13,7 @@
#include "ipfs/repo/fsrepo/fs_repo.h" #include "ipfs/repo/fsrepo/fs_repo.h"
#include "libp2p/os/utils.h" #include "libp2p/os/utils.h"
#include "ipfs/repo/fsrepo/lmdb_datastore.h" #include "ipfs/repo/fsrepo/lmdb_datastore.h"
#include "jsmn.h" #include "ipfs/repo/fsrepo/jsmn.h"
#include "multiaddr/multiaddr.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. * Allocates a fresh unused token from the token pull.
@ -311,3 +313,32 @@ void jsmn_init(jsmn_parser *parser) {
parser->toknext = 0; parser->toknext = 0;
parser->toksuper = -1; 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 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

@ -1,6 +1,6 @@
CC = gcc 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 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-multihash -L../../c-multiaddr -lp2p -lm -lmultihash -lmultiaddr -lpthread -lcurl 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 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 \ OBJS = testit.o test_helper.o \
../blocks/block.o ../blocks/blockstore.o \ ../blocks/block.o ../blocks/blockstore.o \
@ -30,13 +30,13 @@ OBJS = testit.o test_helper.o \
../thirdparty/ipfsaddr/ipfs_addr.o \ ../thirdparty/ipfsaddr/ipfs_addr.o \
../unixfs/unixfs.o \ ../unixfs/unixfs.o \
../util/thread_pool.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) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)
test_ipfs: $(OBJS) test_ipfs: $(OBJS)
$(CC) -o $@ $^ $(LFLAGS) ../../lmdb/libraries/liblmdb/liblmdb.a $(CC) -o $@ $^ $(LFLAGS) ../lmdb/libraries/liblmdb/liblmdb.a
all: test_ipfs 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("test_api");
libp2p_logger_add_class("identify"); libp2p_logger_add_class("identify");
libp2p_logger_add_class("null"); libp2p_logger_add_class("null");
libp2p_logger_add_class("multistream");
libp2p_logger_add_class("swarm"); libp2p_logger_add_class("swarm");
libp2p_logger_add_class("secio"); libp2p_logger_add_class("secio");
*/ */
libp2p_logger_add_class("dialer"); libp2p_logger_add_class("dialer");
libp2p_logger_add_class("yamux"); 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: // Here is the connection information for the GO version:
char* remote_string = "/ip4/10.211.55.2/tcp/4001/ipfs/QmacSE6bCZiAu7nrYkhPATaSoL2q9BszkKzbX6fCiXuBGA"; char* remote_string = "/ip4/10.211.55.2/tcp/4001/ipfs/QmacSE6bCZiAu7nrYkhPATaSoL2q9BszkKzbX6fCiXuBGA";

View file

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

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3

View file

@ -1,5 +1,5 @@
CC = gcc 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 ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3