Merge branch 'master' of git://github.com/raduiliescu83/c-libp2p into raduiliescu83-master

This commit is contained in:
Jose Marcial Vieira Bisneto 2019-01-02 11:25:59 -03:00
commit 64a2a902db
No known key found for this signature in database
GPG key ID: 103E935E7E6E831E
29 changed files with 68 additions and 185 deletions

6
.gitignore vendored
View file

@ -1,5 +1,3 @@
*
!.gitignore !.gitignore
!Makefile !Makefile
!**/ !**/
@ -7,4 +5,8 @@
*.o *.o
.settings/language.settings.xml .settings/language.settings.xml
*.a *.a
*.so
*.so.*
test/testit_libp2p test/testit_libp2p
cscope.files
cscope.out

9
.gitmodules vendored Normal file
View file

@ -0,0 +1,9 @@
[submodule "c-multiaddr"]
path = c-multiaddr
url = https://github.com/Agorise/c-multiaddr.git
[submodule "c-multihash"]
path = c-multihash
url = https://github.com/Agorise/c-multihash.git
[submodule "c-protobuf"]
path = c-protobuf
url = https://github.com/Agorise/c-protobuf.git

View file

@ -1,70 +1,38 @@
SUBMODULES = c-multiaddr c-multihash c-protobuf
COMPONENTS = conn crypto db thirdparty hashmap identify net os peer record routing secio swarm utils yamux
DEBUG = true export DEBUG = true
export DEBUG export SHARED = true
LINKER_FLAGS= ROOT= $(shell pwd)
export INCLUDE = -I$(ROOT)/include -I$(ROOT)/c-protobuf -I$(ROOT)/c-multihash/include -I$(ROOT)/c-multiaddr/include
export CFLAGS = $(INCLUDE) -Wall -O0 -fPIC
OBJS = \ ifdef DEBUG
conn/*.o \ CFLAGS += -g3
crypto/*.o \ endif
crypto/encoding/*.o \
db/*.o \
thirdparty/mbedtls/*.o \
hashmap/hashmap.o \
identify/*.o \
net/*.o \
os/*.o \
peer/*.o \
record/*.o \
routing/*.o \
secio/*.o \
utils/*.o \
swarm/*.o \
yamux/*.o
link:
ar rcs libp2p.a $(OBJS) $(LINKER_FLAGS)
compile: OBJS = $(shell (find $(COMPONENTS) -name *.o))
cd conn; make all;
cd crypto; make all;
cd db; make all;
cd thirdparty; make all;
cd hashmap; make all;
cd identify; make all;
cd net; make all;
cd os; make all;
cd peer; make all;
cd record; make all;
cd routing; make all;
cd secio; make all;
cd swarm; make all;
cd utils; make all;
cd yamux; make all;
test: compile link
cd test; make all;
rebuild: clean all
all: test all: test
clean: link: compile
cd conn; make clean; $(AR) rcs libp2p.a $(OBJS) $(LINKER_FLAGS)
cd crypto; make clean; #ifdef SHARED
cd db; make clean; gcc -shared -o libp2p.so $(OBJS) $(LINKER_FLAGS)
cd hashmap; make clean; #endif
cd identify; make clean;
cd net; make clean;
cd os; make clean;
cd peer; make clean;
cd thirdparty; make clean
cd record; make clean;
cd routing; make clean;
cd secio; make clean;
cd swarm; make clean;
cd utils; make clean;
cd test; make clean;
cd yamux; make clean;
rm -rf libp2p.a
compile:
$(foreach dir,$(SUBMODULES), $(MAKE) -C $(dir) all ;)
$(foreach dir,$(COMPONENTS), $(MAKE) -C $(dir) all ;)
test: link
make -C test all;
rebuild: clean all
clean:
$(foreach dir,$(SUBMODULES), $(MAKE) -C $(dir) clean ;)
$(foreach dir,$(COMPONENTS), $(MAKE) -C $(dir) clean ;)
make -C test clean

1
c-multiaddr Submodule

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

1
c-multihash Submodule

@ -0,0 +1 @@
Subproject commit 3a7a71c7fdbbea60498d25a27d9fd63d57f507c0

1
c-protobuf Submodule

@ -0,0 +1 @@
Subproject commit 1472282e313d65afd2a3884bcab9df7c39928c05

View file

@ -1,13 +1,9 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3
LFLAGS =
DEPS = DEPS =
OBJS = dialer.o transport_dialer.o connection.o tcp_transport_dialer.o session.o OBJS = dialer.o transport_dialer.o connection.o tcp_transport_dialer.o session.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)
all: $(OBJS) all: $(OBJS)
clean: clean:

View file

@ -26,7 +26,6 @@ struct TransportDialer* libp2p_conn_tcp_transport_dialer_new();
* @returns a new Dialer struct * @returns a new Dialer struct
*/ */
struct Dialer* libp2p_conn_dialer_new(struct Libp2pPeer* peer, struct Peerstore* peerstore, struct RsaPrivateKey* rsa_private_key, struct SwarmContext* swarm) { struct Dialer* libp2p_conn_dialer_new(struct Libp2pPeer* peer, struct Peerstore* peerstore, struct RsaPrivateKey* rsa_private_key, struct SwarmContext* swarm) {
int success = 0;
struct Dialer* dialer = (struct Dialer*)malloc(sizeof(struct Dialer)); struct Dialer* dialer = (struct Dialer*)malloc(sizeof(struct Dialer));
if (dialer != NULL) { if (dialer != NULL) {
dialer->peerstore = peerstore; dialer->peerstore = peerstore;
@ -166,7 +165,7 @@ int libp2p_conn_dialer_join_swarm(const struct Dialer* dialer, struct Libp2pPeer
return 0; return 0;
} }
// then get an identify // then get an identify
struct Stream* identify_stream = libp2p_identify_stream_new(yamux_multistream, identify, 1); libp2p_identify_stream_new(yamux_multistream, identify, 1);
} }
} else { } else {
libp2p_logger_error("dialer", "Expected a yamux context, but got a context of type %d.\n", peer->sessionContext->default_stream->stream_type); libp2p_logger_error("dialer", "Expected a yamux context, but got a context of type %d.\n", peer->sessionContext->default_stream->stream_type);

View file

@ -1,13 +1,9 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -g3
LFLAGS =
DEPS = DEPS =
OBJS = rsa.o sha256.o sha512.o sha1.o key.o peerutils.o ephemeral.o aes.o OBJS = rsa.o sha256.o sha512.o sha1.o key.o peerutils.o ephemeral.o aes.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)
all: $(OBJS) all: $(OBJS)
cd encoding; make all; cd encoding; make all;

View file

@ -1,5 +1,3 @@
CC = gcc
CFLAGS = -O0 -I../../include -g3 -std=c99
LFLAGS = LFLAGS =
DEPS = ../../include/libp2p/crypto/encoding/base58.h ../../include/libp2p/crypto/encoding/base64.h \ DEPS = ../../include/libp2p/crypto/encoding/base58.h ../../include/libp2p/crypto/encoding/base64.h \
../../include/libp2p/crypto/encoding/x509.h ../../include/libp2p/crypto/encoding/base16.h \ ../../include/libp2p/crypto/encoding/x509.h ../../include/libp2p/crypto/encoding/base16.h \
@ -7,8 +5,7 @@ DEPS = ../../include/libp2p/crypto/encoding/base58.h ../../include/libp2p/crypto
OBJS = base58.o base64.o x509.o base16.o base32.o OBJS = base58.o base64.o x509.o base16.o base32.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS) -std=c99
all: $(OBJS) all: $(OBJS)

View file

@ -1,12 +1,8 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3 -std=c99
LFLAGS =
DEPS = DEPS =
OBJS = datastore.o filestore.o OBJS = datastore.o filestore.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS) -std=c99
all: $(OBJS) all: $(OBJS)

View file

@ -1,13 +1,9 @@
CC = gcc
CFLAGS = -O0 -I../include -g3
LFLAGS =
DEPS = DEPS =
OBJS = hashmap.o OBJS = hashmap.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)
all: $(OBJS) all: $(OBJS)
clean: clean:

View file

@ -1,16 +1,8 @@
CC = gcc
CFLAGS = -O0 -Wall -Werror -I../include -I../../c-protobuf -std=c11
ifdef DEBUG
CFLAGS += -g3
endif
LFLAGS =
DEPS = DEPS =
OBJS = identify.o OBJS = identify.o
%.o: %.c %.o: %.c
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS) -std=c11
all: $(OBJS) all: $(OBJS)

View file

@ -4,7 +4,7 @@
#include <stddef.h> #include <stddef.h>
struct RsaPublicKey { struct RsaPublicKey {
char* der; unsigned char* der;
size_t der_length; size_t der_length;
}; };
@ -20,7 +20,7 @@ struct RsaPrivateKey {
unsigned long long N; unsigned long long N;
// the keys in DER format // the keys in DER format
// private // private
char* der; unsigned char* der;
size_t der_length; size_t der_length;
// public // public
char* public_key_der; char* public_key_der;

View file

@ -1,11 +1,3 @@
CC = gcc
CFLAGS = -O0 -Wall -I../include -I../../c-protobuf -I../../c-multiaddr/include
ifdef DEBUG
CFLAGS += -g3
endif
LFLAGS =
DEPS = DEPS =
OBJS = sctp.o socket.o tcp.o udp.o multistream.o protocol.o connectionstream.o stream.o server.o OBJS = sctp.o socket.o tcp.o udp.o multistream.o protocol.o connectionstream.o stream.o server.o

View file

@ -1,11 +1,3 @@
CC = gcc
CFLAGS = -O0 -Wall -I../include -I../../c-protobuf
ifdef DEBUG
CFLAGS += -g3
endif
LFLAGS =
DEPS = DEPS =
OBJS = nodeio.o OBJS = nodeio.o

View file

@ -1,13 +1,9 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3
LFLAGS =
DEPS = DEPS =
OBJS = utils.o memstream.o OBJS = utils.o memstream.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)
all: $(OBJS) all: $(OBJS)
clean: clean:

View file

@ -1,12 +1,8 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3 -std=c11
LFLAGS =
DEPS = DEPS =
OBJS = peer.o peerstore.o providerstore.o OBJS = peer.o peerstore.o providerstore.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS) -std=c11
all: $(OBJS) all: $(OBJS)

View file

@ -256,9 +256,7 @@ int libp2p_peer_protobuf_decode(unsigned char* in, size_t in_size, struct Libp2p
int retVal = 0; int retVal = 0;
char* buffer = NULL; char* buffer = NULL;
size_t buffer_size = 0; size_t buffer_size = 0;
struct Libp2pLinkedList* current = NULL;
struct Libp2pLinkedList* last = NULL; struct Libp2pLinkedList* last = NULL;
struct MultiAddress* ma = NULL;
*out = libp2p_peer_new(); *out = libp2p_peer_new();
if ( *out == NULL) if ( *out == NULL)

View file

@ -1,13 +1,9 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3
LFLAGS =
DEPS = DEPS =
OBJS = record.o message.o message_handler.o OBJS = record.o message.o message_handler.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)
all: $(OBJS) all: $(OBJS)
clean: clean:

View file

@ -1,12 +1,9 @@
DHT_DIR = dht DHT_DIR = dht
CC = gcc
CFLAGS = -O0 -I../include -I../../c-multiaddr/include -I$(DHT_DIR) -g3
LFLAGS =
DEPS = # $(DHT_DIR)/dht.h DEPS = # $(DHT_DIR)/dht.h
OBJS = kademlia.o dht.o dht_protocol.o OBJS = kademlia.o dht.o dht_protocol.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS) -I$(DHT_DIR)
all: $(OBJS) all: $(OBJS)
@ -21,5 +18,5 @@ kademlia_test: $(OBJS)
clean: clean:
rm -f kademlia_test $(OBJS) rm -f kademlia_test $(OBJS)
#dht.c #dht.c
#rm -rf $(DHT_DIR) #rm -rf $(DHT_DIR)

View file

@ -302,11 +302,6 @@ static int parse_message(const unsigned char *buf, int buflen,
int *want_return); int *want_return);
static const unsigned char zeroes[20] = {0}; static const unsigned char zeroes[20] = {0};
static const unsigned char ones[20] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF
};
static const unsigned char v4prefix[16] = { static const unsigned char v4prefix[16] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0
}; };

View file

@ -334,7 +334,6 @@ int libp2p_routing_dht_handle_add_provider(struct Stream* stream, struct Kademli
int libp2p_routing_dht_handle_get_value(struct Stream* stream, struct KademliaMessage* message, struct DhtContext* dht_context, int libp2p_routing_dht_handle_get_value(struct Stream* stream, struct KademliaMessage* message, struct DhtContext* dht_context,
unsigned char** result_buffer, size_t *result_buffer_size) { unsigned char** result_buffer, size_t *result_buffer_size) {
struct Datastore* datastore = dht_context->datastore;
struct Filestore* filestore = dht_context->filestore; struct Filestore* filestore = dht_context->filestore;
size_t data_size = 0; size_t data_size = 0;
unsigned char* data = NULL; unsigned char* data = NULL;

View file

@ -1,16 +1,8 @@
CC = gcc
CFLAGS = -O0 -Wall -I../include -I../../c-protobuf -I../../c-multiaddr/include -std=c99
ifdef DEBUG
CFLAGS += -g3
endif
LFLAGS =
DEPS = DEPS =
OBJS = exchange.o propose.o secio.o OBJS = exchange.o propose.o secio.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS) -std=c99
all: $(OBJS) all: $(OBJS)

View file

@ -314,7 +314,7 @@ int libp2p_secio_verify_signature(struct PublicKey* public_key, const unsigned c
if (public_key->type == KEYTYPE_RSA) { if (public_key->type == KEYTYPE_RSA) {
struct RsaPublicKey rsa_key = {0}; struct RsaPublicKey rsa_key = {0};
rsa_key.der = (char*)public_key->data; rsa_key.der = public_key->data;
rsa_key.der_length = public_key->data_size; rsa_key.der_length = public_key->data_size;
return libp2p_crypto_rsa_verify(&rsa_key, in, in_length, signature); return libp2p_crypto_rsa_verify(&rsa_key, in, in_length, signature);
} }
@ -335,7 +335,7 @@ int libp2p_secio_sign(struct PrivateKey* private_key, const char* in, size_t in_
if (private_key->type == KEYTYPE_RSA) { if (private_key->type == KEYTYPE_RSA) {
struct RsaPrivateKey rsa_key = {0}; struct RsaPrivateKey rsa_key = {0};
rsa_key.der = (char*)private_key->data; rsa_key.der = private_key->data;
rsa_key.der_length = private_key->data_size; rsa_key.der_length = private_key->data_size;
int retVal = libp2p_crypto_rsa_sign(&rsa_key, in, in_length, signature, signature_size); int retVal = libp2p_crypto_rsa_sign(&rsa_key, in, in_length, signature, signature_size);
// debugging // debugging

View file

@ -1,16 +1,8 @@
CC = gcc
CFLAGS = -O0 -Wall -I../include -I../../c-protobuf -I../../c-multiaddr/include -std=c99
ifdef DEBUG
CFLAGS += -g3
endif
LFLAGS =
DEPS = DEPS =
OBJS = swarm.o OBJS = swarm.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS) -std=c99
all: $(OBJS) all: $(OBJS)

View file

@ -1,13 +1,13 @@
CC = gcc CC = gcc
CFLAGS = -O0 -I../include -I. -I../../c-multihash/include -I../../c-multiaddr/include -std=c11 CFLAGS = $(INCLUDE) -O0 -std=c11
ifdef DEBUG ifdef DEBUG
CFLAGS += -g3 CFLAGS += -g3
endif endif
LFLAGS = -L../ -L../../c-multihash -L../../c-multiaddr LFLAGS = -L../ -L../c-multihash -L../c-multiaddr
DEPS = crypto/test_base58.h crypto/test_rsa.h test_mbedtls.h DEPS = crypto/test_base58.h crypto/test_rsa.h test_mbedtls.h
OBJS = testit.o ../../c-protobuf/protobuf.o ../../c-protobuf/varint.o ../libp2p.a OBJS = testit.o ../c-protobuf/protobuf.o ../c-protobuf/varint.o ../libp2p.a
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View file

@ -1,16 +1,8 @@
CC = gcc
CFLAGS = -O0 -Wall -I../include -I../../c-multiaddr/include -std=c99
ifdef DEBUG
CFLAGS += -g3
endif
LFLAGS =
DEPS = DEPS =
OBJS = string_list.o vector.o linked_list.o logger.o urlencode.o thread_pool.o threadsafe_buffer.o OBJS = string_list.o vector.o linked_list.o logger.o urlencode.o thread_pool.o threadsafe_buffer.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS) -std=c99
all: $(OBJS) all: $(OBJS)

View file

@ -1,16 +1,8 @@
CC = gcc
CFLAGS = -O0 -Wall -Werror -I../include -I../../c-protobuf -std=c11
ifdef DEBUG
CFLAGS += -g3
endif
LFLAGS =
DEPS = DEPS =
OBJS = frame.o session.o stream.o yamux.o ../os/timespec.o OBJS = frame.o session.o stream.o yamux.o ../os/timespec.o
%.o: %.c %.o: %.c
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS) -std=c11
all: $(OBJS) all: $(OBJS)