diff --git a/.gitignore b/.gitignore index b33fc65..4f91830 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -* - !.gitignore !Makefile !**/ @@ -7,4 +5,8 @@ *.o .settings/language.settings.xml *.a +*.so +*.so.* test/testit_libp2p +cscope.files +cscope.out diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..28f7568 --- /dev/null +++ b/.gitmodules @@ -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 diff --git a/Makefile b/Makefile index 272a600..d05f154 100644 --- a/Makefile +++ b/Makefile @@ -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 +export DEBUG = true +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 = \ - conn/*.o \ - crypto/*.o \ - 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 +ifdef DEBUG +CFLAGS += -g3 +endif -link: - ar rcs libp2p.a $(OBJS) $(LINKER_FLAGS) + +OBJS = $(shell (find $(COMPONENTS) -name *.o)) + +all: test + +link: compile + $(AR) rcs libp2p.a $(OBJS) $(LINKER_FLAGS) +#ifdef SHARED + gcc -shared -o libp2p.so $(OBJS) $(LINKER_FLAGS) +#endif compile: - 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 - -clean: - cd conn; make clean; - cd crypto; make clean; - cd db; make clean; - cd hashmap; make clean; - 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 + $(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 diff --git a/c-multiaddr b/c-multiaddr new file mode 160000 index 0000000..b1f7d60 --- /dev/null +++ b/c-multiaddr @@ -0,0 +1 @@ +Subproject commit b1f7d607eef3928d7153e87c2b551e0c713588df diff --git a/c-multihash b/c-multihash new file mode 160000 index 0000000..3a7a71c --- /dev/null +++ b/c-multihash @@ -0,0 +1 @@ +Subproject commit 3a7a71c7fdbbea60498d25a27d9fd63d57f507c0 diff --git a/c-protobuf b/c-protobuf new file mode 160000 index 0000000..1472282 --- /dev/null +++ b/c-protobuf @@ -0,0 +1 @@ +Subproject commit 1472282e313d65afd2a3884bcab9df7c39928c05 diff --git a/conn/Makefile b/conn/Makefile index 1e7d7aa..a2048f6 100644 --- a/conn/Makefile +++ b/conn/Makefile @@ -1,13 +1,9 @@ -CC = gcc -CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3 -LFLAGS = DEPS = OBJS = dialer.o transport_dialer.o connection.o tcp_transport_dialer.o session.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) - all: $(OBJS) clean: diff --git a/conn/dialer.c b/conn/dialer.c index 758edca..34aa8e0 100644 --- a/conn/dialer.c +++ b/conn/dialer.c @@ -26,7 +26,6 @@ struct TransportDialer* libp2p_conn_tcp_transport_dialer_new(); * @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) { - int success = 0; struct Dialer* dialer = (struct Dialer*)malloc(sizeof(struct Dialer)); if (dialer != NULL) { dialer->peerstore = peerstore; @@ -166,7 +165,7 @@ int libp2p_conn_dialer_join_swarm(const struct Dialer* dialer, struct Libp2pPeer return 0; } // 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 { libp2p_logger_error("dialer", "Expected a yamux context, but got a context of type %d.\n", peer->sessionContext->default_stream->stream_type); diff --git a/crypto/Makefile b/crypto/Makefile index 18867a3..b4be33a 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -1,13 +1,9 @@ -CC = gcc -CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -g3 -LFLAGS = DEPS = OBJS = rsa.o sha256.o sha512.o sha1.o key.o peerutils.o ephemeral.o aes.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) - all: $(OBJS) cd encoding; make all; diff --git a/crypto/encoding/Makefile b/crypto/encoding/Makefile index 7eda9dd..8e91776 100644 --- a/crypto/encoding/Makefile +++ b/crypto/encoding/Makefile @@ -1,5 +1,3 @@ -CC = gcc -CFLAGS = -O0 -I../../include -g3 -std=c99 LFLAGS = 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 \ @@ -7,9 +5,8 @@ DEPS = ../../include/libp2p/crypto/encoding/base58.h ../../include/libp2p/crypto OBJS = base58.o base64.o x509.o base16.o base32.o %.o: %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(CFLAGS) -std=c99 - all: $(OBJS) clean: diff --git a/db/Makefile b/db/Makefile index ab7f456..b69194a 100644 --- a/db/Makefile +++ b/db/Makefile @@ -1,13 +1,9 @@ -CC = gcc -CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3 -std=c99 -LFLAGS = DEPS = OBJS = datastore.o filestore.o %.o: %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(CFLAGS) -std=c99 - all: $(OBJS) clean: diff --git a/hashmap/Makefile b/hashmap/Makefile index 96e40f3..aa803f7 100644 --- a/hashmap/Makefile +++ b/hashmap/Makefile @@ -1,13 +1,9 @@ -CC = gcc -CFLAGS = -O0 -I../include -g3 -LFLAGS = DEPS = OBJS = hashmap.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) - all: $(OBJS) clean: diff --git a/identify/Makefile b/identify/Makefile index e15ce81..9aa0fc5 100644 --- a/identify/Makefile +++ b/identify/Makefile @@ -1,16 +1,8 @@ -CC = gcc -CFLAGS = -O0 -Wall -Werror -I../include -I../../c-protobuf -std=c11 - -ifdef DEBUG -CFLAGS += -g3 -endif - -LFLAGS = DEPS = OBJS = identify.o %.o: %.c - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(CFLAGS) -std=c11 all: $(OBJS) diff --git a/include/libp2p/crypto/rsa.h b/include/libp2p/crypto/rsa.h index 878ce9c..e88e604 100644 --- a/include/libp2p/crypto/rsa.h +++ b/include/libp2p/crypto/rsa.h @@ -4,7 +4,7 @@ #include struct RsaPublicKey { - char* der; + unsigned char* der; size_t der_length; }; @@ -20,7 +20,7 @@ struct RsaPrivateKey { unsigned long long N; // the keys in DER format // private - char* der; + unsigned char* der; size_t der_length; // public char* public_key_der; diff --git a/net/Makefile b/net/Makefile index 59d703b..9c2cbd3 100644 --- a/net/Makefile +++ b/net/Makefile @@ -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 = OBJS = sctp.o socket.o tcp.o udp.o multistream.o protocol.o connectionstream.o stream.o server.o diff --git a/nodeio/Makefile b/nodeio/Makefile index b3e63f4..d279292 100644 --- a/nodeio/Makefile +++ b/nodeio/Makefile @@ -1,11 +1,3 @@ -CC = gcc -CFLAGS = -O0 -Wall -I../include -I../../c-protobuf - -ifdef DEBUG -CFLAGS += -g3 -endif - -LFLAGS = DEPS = OBJS = nodeio.o diff --git a/os/Makefile b/os/Makefile index 6e1faaf..1f46bef 100644 --- a/os/Makefile +++ b/os/Makefile @@ -1,13 +1,9 @@ -CC = gcc -CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3 -LFLAGS = DEPS = OBJS = utils.o memstream.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) - all: $(OBJS) clean: diff --git a/peer/Makefile b/peer/Makefile index c41dcbb..8a395ce 100644 --- a/peer/Makefile +++ b/peer/Makefile @@ -1,13 +1,9 @@ -CC = gcc -CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3 -std=c11 -LFLAGS = DEPS = OBJS = peer.o peerstore.o providerstore.o %.o: %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(CFLAGS) -std=c11 - all: $(OBJS) clean: diff --git a/peer/peer.c b/peer/peer.c index 82052f6..0f779c4 100644 --- a/peer/peer.c +++ b/peer/peer.c @@ -256,9 +256,7 @@ int libp2p_peer_protobuf_decode(unsigned char* in, size_t in_size, struct Libp2p int retVal = 0; char* buffer = NULL; size_t buffer_size = 0; - struct Libp2pLinkedList* current = NULL; struct Libp2pLinkedList* last = NULL; - struct MultiAddress* ma = NULL; *out = libp2p_peer_new(); if ( *out == NULL) diff --git a/record/Makefile b/record/Makefile index 280325b..56e58f6 100644 --- a/record/Makefile +++ b/record/Makefile @@ -1,13 +1,9 @@ -CC = gcc -CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3 -LFLAGS = DEPS = OBJS = record.o message.o message_handler.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) - all: $(OBJS) clean: diff --git a/routing/Makefile b/routing/Makefile index f71a960..57cc06b 100644 --- a/routing/Makefile +++ b/routing/Makefile @@ -1,12 +1,9 @@ DHT_DIR = dht -CC = gcc -CFLAGS = -O0 -I../include -I../../c-multiaddr/include -I$(DHT_DIR) -g3 -LFLAGS = DEPS = # $(DHT_DIR)/dht.h OBJS = kademlia.o dht.o dht_protocol.o %.o: %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(CFLAGS) -I$(DHT_DIR) all: $(OBJS) @@ -21,5 +18,5 @@ kademlia_test: $(OBJS) clean: rm -f kademlia_test $(OBJS) - #dht.c - #rm -rf $(DHT_DIR) +#dht.c +#rm -rf $(DHT_DIR) diff --git a/routing/dht.c b/routing/dht.c index 0e210b6..2527b38 100644 --- a/routing/dht.c +++ b/routing/dht.c @@ -302,11 +302,6 @@ static int parse_message(const unsigned char *buf, int buflen, int *want_return); 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] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 }; diff --git a/routing/dht_protocol.c b/routing/dht_protocol.c index e34383b..cb77c1c 100644 --- a/routing/dht_protocol.c +++ b/routing/dht_protocol.c @@ -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, unsigned char** result_buffer, size_t *result_buffer_size) { - struct Datastore* datastore = dht_context->datastore; struct Filestore* filestore = dht_context->filestore; size_t data_size = 0; unsigned char* data = NULL; diff --git a/secio/Makefile b/secio/Makefile index 8542bbd..696275b 100644 --- a/secio/Makefile +++ b/secio/Makefile @@ -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 = OBJS = exchange.o propose.o secio.o %.o: %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(CFLAGS) -std=c99 all: $(OBJS) diff --git a/secio/secio.c b/secio/secio.c index 865c37b..d9e799e 100644 --- a/secio/secio.c +++ b/secio/secio.c @@ -314,7 +314,7 @@ int libp2p_secio_verify_signature(struct PublicKey* public_key, const unsigned c if (public_key->type == KEYTYPE_RSA) { 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; 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) { 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; int retVal = libp2p_crypto_rsa_sign(&rsa_key, in, in_length, signature, signature_size); // debugging diff --git a/swarm/Makefile b/swarm/Makefile index cd43de1..88bb67f 100644 --- a/swarm/Makefile +++ b/swarm/Makefile @@ -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 = OBJS = swarm.o %.o: %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(CFLAGS) -std=c99 all: $(OBJS) diff --git a/test/Makefile b/test/Makefile index c53b6d0..05e9d51 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,20 +1,20 @@ CC = gcc -CFLAGS = -O0 -I../include -I. -I../../c-multihash/include -I../../c-multiaddr/include -std=c11 +CFLAGS = $(INCLUDE) -O0 -std=c11 ifdef DEBUG CFLAGS += -g3 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 -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) $(CC) -c -o $@ $< $(CFLAGS) testit_libp2p: $(OBJS) $(DEPS) $(CC) -o $@ $(OBJS) $(LFLAGS) -lp2p -lm -lmultihash -lmultiaddr -lpthread - + all_others: cd ../crypto; make all; cd ../thirdparty; make all; diff --git a/utils/Makefile b/utils/Makefile index 653f98c..a726924 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -1,16 +1,8 @@ -CC = gcc -CFLAGS = -O0 -Wall -I../include -I../../c-multiaddr/include -std=c99 - -ifdef DEBUG -CFLAGS += -g3 -endif - -LFLAGS = DEPS = OBJS = string_list.o vector.o linked_list.o logger.o urlencode.o thread_pool.o threadsafe_buffer.o %.o: %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(CFLAGS) -std=c99 all: $(OBJS) diff --git a/yamux/Makefile b/yamux/Makefile index ff0165b..b151cfa 100644 --- a/yamux/Makefile +++ b/yamux/Makefile @@ -1,16 +1,8 @@ -CC = gcc -CFLAGS = -O0 -Wall -Werror -I../include -I../../c-protobuf -std=c11 - -ifdef DEBUG -CFLAGS += -g3 -endif - -LFLAGS = DEPS = OBJS = frame.o session.o stream.o yamux.o ../os/timespec.o %.o: %.c - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(CFLAGS) -std=c11 all: $(OBJS) @@ -19,4 +11,4 @@ clean: rm -f test test: all test.o - $(CC) -o test test.o $(OBJS) $(CFLAGS) \ No newline at end of file + $(CC) -o test test.o $(OBJS) $(CFLAGS)