From e93e212d70897db03c6b13aaf17aaaf6318931e7 Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Wed, 28 Nov 2018 10:43:33 -0500 Subject: [PATCH 01/16] Makefile: link should depend on compile This fixes make all - previously it was doing first link then compile with make 4.1 --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 272a600..ec9a46e 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ OBJS = \ swarm/*.o \ yamux/*.o -link: +link: compile ar rcs libp2p.a $(OBJS) $(LINKER_FLAGS) compile: @@ -41,14 +41,14 @@ compile: 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; From ccabb8c0acf10707f78f63d7bd4565ad5d47fae7 Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Thu, 29 Nov 2018 05:34:18 -0500 Subject: [PATCH 02/16] gitignore: don't ignore everything --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index b33fc65..710471f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -* - !.gitignore !Makefile !**/ From d3858ffc26aba7530d05b44f87fcce1b94f3f5b6 Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Thu, 29 Nov 2018 07:15:27 -0500 Subject: [PATCH 03/16] Makefile: refactor include files Now major include files are comming from main Makefile, module need to add just their specific include path. To work make the include path absolute. --- Makefile | 3 ++- conn/Makefile | 3 +-- crypto/Makefile | 3 +-- crypto/encoding/Makefile | 4 +--- db/Makefile | 3 +-- hashmap/Makefile | 3 +-- identify/Makefile | 2 +- net/Makefile | 2 +- nodeio/Makefile | 2 +- os/Makefile | 3 +-- peer/Makefile | 3 +-- record/Makefile | 3 +-- routing/Makefile | 6 +++--- secio/Makefile | 2 +- swarm/Makefile | 2 +- test/Makefile | 4 ++-- utils/Makefile | 2 +- yamux/Makefile | 4 ++-- 18 files changed, 23 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index ec9a46e..1017faf 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,8 @@ DEBUG = true export DEBUG -LINKER_FLAGS= +ROOT= $(shell pwd) +export INCLUDE = -I$(ROOT)/include -I$(ROOT)/../c-protobuf -I$(ROOT)/../c-multihash/include -I$(ROOT)/../c-multiaddr/include OBJS = \ conn/*.o \ diff --git a/conn/Makefile b/conn/Makefile index 1e7d7aa..2e05e2c 100644 --- a/conn/Makefile +++ b/conn/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3 +CFLAGS = $(INCLUDE) -O0 -g3 LFLAGS = DEPS = OBJS = dialer.o transport_dialer.o connection.o tcp_transport_dialer.o session.o @@ -7,7 +7,6 @@ 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/crypto/Makefile b/crypto/Makefile index 18867a3..8b511e5 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -g3 +export CFLAGS = $(INCLUDE) -O0 -g3 LFLAGS = DEPS = OBJS = rsa.o sha256.o sha512.o sha1.o key.o peerutils.o ephemeral.o aes.o @@ -7,7 +7,6 @@ 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..3719318 100644 --- a/crypto/encoding/Makefile +++ b/crypto/encoding/Makefile @@ -1,5 +1,4 @@ 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 +6,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..8a24d0f 100644 --- a/db/Makefile +++ b/db/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3 -std=c99 +CFLAGS = $(INCLUDE) -O0 -g3 -std=c99 LFLAGS = DEPS = OBJS = datastore.o filestore.o @@ -7,7 +7,6 @@ OBJS = datastore.o filestore.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) - all: $(OBJS) clean: diff --git a/hashmap/Makefile b/hashmap/Makefile index 96e40f3..0acbb2c 100644 --- a/hashmap/Makefile +++ b/hashmap/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -I../include -g3 +CFLAGS = $(INCLUDE) -O0 -g3 LFLAGS = DEPS = OBJS = hashmap.o @@ -7,7 +7,6 @@ OBJS = hashmap.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) - all: $(OBJS) clean: diff --git a/identify/Makefile b/identify/Makefile index e15ce81..22677db 100644 --- a/identify/Makefile +++ b/identify/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -Wall -Werror -I../include -I../../c-protobuf -std=c11 +CFLAGS = $(INCLUDE) -O0 -Wall -Werror -std=c11 ifdef DEBUG CFLAGS += -g3 diff --git a/net/Makefile b/net/Makefile index 59d703b..65c150f 100644 --- a/net/Makefile +++ b/net/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -Wall -I../include -I../../c-protobuf -I../../c-multiaddr/include +CFLAGS = $(INCLUDE) -O0 -Wall ifdef DEBUG CFLAGS += -g3 diff --git a/nodeio/Makefile b/nodeio/Makefile index b3e63f4..876a573 100644 --- a/nodeio/Makefile +++ b/nodeio/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -Wall -I../include -I../../c-protobuf +CFLAGS = $(INCLUDE) -O0 -Wall ifdef DEBUG CFLAGS += -g3 diff --git a/os/Makefile b/os/Makefile index 6e1faaf..1bf8853 100644 --- a/os/Makefile +++ b/os/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3 +CFLAGS = $(INCLUDE) -O0 -g3 LFLAGS = DEPS = OBJS = utils.o memstream.o @@ -7,7 +7,6 @@ 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..af36362 100644 --- a/peer/Makefile +++ b/peer/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3 -std=c11 +CFLAGS = $(INCLUDE) -O0 -g3 -std=c11 LFLAGS = DEPS = OBJS = peer.o peerstore.o providerstore.o @@ -7,7 +7,6 @@ OBJS = peer.o peerstore.o providerstore.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) - all: $(OBJS) clean: diff --git a/record/Makefile b/record/Makefile index 280325b..bca5d02 100644 --- a/record/Makefile +++ b/record/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -I../include -I../../c-protobuf -I../../c-multihash/include -I../../c-multiaddr/include -g3 +CFLAGS = $(INCLUDE) -O0 -g3 LFLAGS = DEPS = OBJS = record.o message.o message_handler.o @@ -7,7 +7,6 @@ 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..18bfa0f 100644 --- a/routing/Makefile +++ b/routing/Makefile @@ -1,6 +1,6 @@ DHT_DIR = dht CC = gcc -CFLAGS = -O0 -I../include -I../../c-multiaddr/include -I$(DHT_DIR) -g3 +CFLAGS = $(INCLUDE) -I$(DHT_DIR) -O0 -g3 LFLAGS = DEPS = # $(DHT_DIR)/dht.h OBJS = kademlia.o dht.o dht_protocol.o @@ -21,5 +21,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/secio/Makefile b/secio/Makefile index 8542bbd..59a0167 100644 --- a/secio/Makefile +++ b/secio/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -Wall -I../include -I../../c-protobuf -I../../c-multiaddr/include -std=c99 +CFLAGS = $(INCLUDE) -O0 -Wall -std=c99 ifdef DEBUG CFLAGS += -g3 diff --git a/swarm/Makefile b/swarm/Makefile index cd43de1..c5bf8d0 100644 --- a/swarm/Makefile +++ b/swarm/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -Wall -I../include -I../../c-protobuf -I../../c-multiaddr/include -std=c99 +CFLAGS = $(INCLUDE) -O0 -Wall -std=c99 ifdef DEBUG CFLAGS += -g3 diff --git a/test/Makefile b/test/Makefile index c53b6d0..24b8431 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,5 +1,5 @@ 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 @@ -14,7 +14,7 @@ OBJS = testit.o ../../c-protobuf/protobuf.o ../../c-protobuf/varint.o ../libp2p. 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..5e9d048 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -Wall -I../include -I../../c-multiaddr/include -std=c99 +CFLAGS = $(INCLUDE) -O0 -Wall -std=c99 ifdef DEBUG CFLAGS += -g3 diff --git a/yamux/Makefile b/yamux/Makefile index ff0165b..942a128 100644 --- a/yamux/Makefile +++ b/yamux/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -O0 -Wall -Werror -I../include -I../../c-protobuf -std=c11 +CFLAGS = $(INCLUDE) -O0 -Wall -Werror -std=c11 ifdef DEBUG CFLAGS += -g3 @@ -19,4 +19,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) From d74885170428629d2308bb4afb1055eb51a5f9db Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Thu, 29 Nov 2018 07:43:16 -0500 Subject: [PATCH 04/16] dependencies: add c-multiaddr, c-multihash and c-protobuf as submodules --- .gitmodules | 9 +++++++++ c-multiaddr | 1 + c-multihash | 1 + c-protobuf | 1 + 4 files changed, 12 insertions(+) create mode 100644 .gitmodules create mode 160000 c-multiaddr create mode 160000 c-multihash create mode 160000 c-protobuf diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6a6b6e4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "c-multiaddr"] + path = c-multiaddr + url = https://github.com/raduiliescu83/c-multiaddr.git +[submodule "c-multihash"] + path = c-multihash + url = https://github.com/raduiliescu83/c-multihash.git +[submodule "c-protobuf"] + path = c-protobuf + url = https://github.com/raduiliescu83/c-protobuf.git diff --git a/c-multiaddr b/c-multiaddr new file mode 160000 index 0000000..a271e08 --- /dev/null +++ b/c-multiaddr @@ -0,0 +1 @@ +Subproject commit a271e08996337eaadede798d785d18ec9515fd42 diff --git a/c-multihash b/c-multihash new file mode 160000 index 0000000..bc6c083 --- /dev/null +++ b/c-multihash @@ -0,0 +1 @@ +Subproject commit bc6c0830136d39c87b9f59a335d096db882418f6 diff --git a/c-protobuf b/c-protobuf new file mode 160000 index 0000000..dceaa02 --- /dev/null +++ b/c-protobuf @@ -0,0 +1 @@ +Subproject commit dceaa020823be04c9ed54fec8fb8b2537f440d26 From 5bc911bba34a7aa30e1753a24570f11ab8b304b2 Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Thu, 29 Nov 2018 08:12:39 -0500 Subject: [PATCH 05/16] Makefile: update include path to c-* submodules --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1017faf..4631119 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ DEBUG = true export DEBUG ROOT= $(shell pwd) -export INCLUDE = -I$(ROOT)/include -I$(ROOT)/../c-protobuf -I$(ROOT)/../c-multihash/include -I$(ROOT)/../c-multiaddr/include +export INCLUDE = -I$(ROOT)/include -I$(ROOT)/c-protobuf -I$(ROOT)/c-multihash/include -I$(ROOT)/c-multiaddr/include OBJS = \ conn/*.o \ From bd6400c370b21b5a65818e375da56be56afadee8 Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Thu, 29 Nov 2018 10:17:20 -0500 Subject: [PATCH 06/16] Makefile: create list of components and use it for compile and clean --- Makefile | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 4631119..c627ca9 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +COMPONENTS = conn crypto db thirdparty hashmap identify net os peer record routing secio swarm utils yamux DEBUG = true export DEBUG @@ -5,6 +6,7 @@ export DEBUG ROOT= $(shell pwd) export INCLUDE = -I$(ROOT)/include -I$(ROOT)/c-protobuf -I$(ROOT)/c-multihash/include -I$(ROOT)/c-multiaddr/include + OBJS = \ conn/*.o \ crypto/*.o \ @@ -27,21 +29,7 @@ link: compile ar rcs libp2p.a $(OBJS) $(LINKER_FLAGS) 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; + $(foreach dir,$(COMPONENTS), $(MAKE) -C $(dir) all ;) test: compile link cd test; make all; @@ -51,21 +39,4 @@ 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,$(COMPONENTS), $(MAKE) -C $(dir) clean ;) From 826774586341499d0df2719b1d28d9e70faf116b Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Thu, 29 Nov 2018 11:03:48 -0500 Subject: [PATCH 07/16] Makefile: use COMPONENTS list to generate the linker objects --- Makefile | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index c627ca9..064ce21 100644 --- a/Makefile +++ b/Makefile @@ -6,27 +6,10 @@ export DEBUG ROOT= $(shell pwd) export INCLUDE = -I$(ROOT)/include -I$(ROOT)/c-protobuf -I$(ROOT)/c-multihash/include -I$(ROOT)/c-multiaddr/include - -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 +OBJS = $(shell (find $(COMPONENTS) -name *.o)) link: compile - ar rcs libp2p.a $(OBJS) $(LINKER_FLAGS) + $(AR) rcs libp2p.a $(OBJS) $(LINKER_FLAGS) compile: $(foreach dir,$(COMPONENTS), $(MAKE) -C $(dir) all ;) From 209e7c432eb4cfca1d7fa8c9131a6957556598b6 Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Mon, 3 Dec 2018 06:04:51 -0500 Subject: [PATCH 08/16] Makefile: fix test build was broken after moving c-multiaddress and c-multihash as subprojects --- test/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Makefile b/test/Makefile index 24b8431..05e9d51 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,9 +5,9 @@ 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) From 8d3957f3b888adcd45cd5e3bd3e850fc885c93a6 Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Mon, 3 Dec 2018 07:22:33 -0500 Subject: [PATCH 09/16] Makefile: refactor CFLAGS to come from main Makefile Also remove CC and link flags since linking is done in main Makefile --- Makefile | 10 ++++++++-- conn/Makefile | 3 --- crypto/Makefile | 3 --- crypto/encoding/Makefile | 1 - db/Makefile | 5 +---- hashmap/Makefile | 3 --- identify/Makefile | 10 +--------- net/Makefile | 8 -------- nodeio/Makefile | 8 -------- os/Makefile | 3 --- peer/Makefile | 5 +---- record/Makefile | 3 --- routing/Makefile | 5 +---- secio/Makefile | 10 +--------- swarm/Makefile | 10 +--------- utils/Makefile | 10 +--------- yamux/Makefile | 10 +--------- 17 files changed, 16 insertions(+), 91 deletions(-) diff --git a/Makefile b/Makefile index 064ce21..4f2e097 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,15 @@ COMPONENTS = conn crypto db thirdparty hashmap identify net os peer record routing secio swarm utils yamux -DEBUG = true -export DEBUG +export DEBUG = true 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 + +ifdef DEBUG +CFLAGS += -g3 +endif + OBJS = $(shell (find $(COMPONENTS) -name *.o)) @@ -23,3 +28,4 @@ all: test clean: $(foreach dir,$(COMPONENTS), $(MAKE) -C $(dir) clean ;) + make -C test clean diff --git a/conn/Makefile b/conn/Makefile index 2e05e2c..a2048f6 100644 --- a/conn/Makefile +++ b/conn/Makefile @@ -1,6 +1,3 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -g3 -LFLAGS = DEPS = OBJS = dialer.o transport_dialer.o connection.o tcp_transport_dialer.o session.o diff --git a/crypto/Makefile b/crypto/Makefile index 8b511e5..b4be33a 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -1,6 +1,3 @@ -CC = gcc -export CFLAGS = $(INCLUDE) -O0 -g3 -LFLAGS = DEPS = OBJS = rsa.o sha256.o sha512.o sha1.o key.o peerutils.o ephemeral.o aes.o diff --git a/crypto/encoding/Makefile b/crypto/encoding/Makefile index 3719318..8e91776 100644 --- a/crypto/encoding/Makefile +++ b/crypto/encoding/Makefile @@ -1,4 +1,3 @@ -CC = gcc 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 \ diff --git a/db/Makefile b/db/Makefile index 8a24d0f..b69194a 100644 --- a/db/Makefile +++ b/db/Makefile @@ -1,11 +1,8 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -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) diff --git a/hashmap/Makefile b/hashmap/Makefile index 0acbb2c..aa803f7 100644 --- a/hashmap/Makefile +++ b/hashmap/Makefile @@ -1,6 +1,3 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -g3 -LFLAGS = DEPS = OBJS = hashmap.o diff --git a/identify/Makefile b/identify/Makefile index 22677db..9aa0fc5 100644 --- a/identify/Makefile +++ b/identify/Makefile @@ -1,16 +1,8 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -Wall -Werror -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/net/Makefile b/net/Makefile index 65c150f..9c2cbd3 100644 --- a/net/Makefile +++ b/net/Makefile @@ -1,11 +1,3 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -Wall - -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 876a573..d279292 100644 --- a/nodeio/Makefile +++ b/nodeio/Makefile @@ -1,11 +1,3 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -Wall - -ifdef DEBUG -CFLAGS += -g3 -endif - -LFLAGS = DEPS = OBJS = nodeio.o diff --git a/os/Makefile b/os/Makefile index 1bf8853..1f46bef 100644 --- a/os/Makefile +++ b/os/Makefile @@ -1,6 +1,3 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -g3 -LFLAGS = DEPS = OBJS = utils.o memstream.o diff --git a/peer/Makefile b/peer/Makefile index af36362..8a395ce 100644 --- a/peer/Makefile +++ b/peer/Makefile @@ -1,11 +1,8 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -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) diff --git a/record/Makefile b/record/Makefile index bca5d02..56e58f6 100644 --- a/record/Makefile +++ b/record/Makefile @@ -1,6 +1,3 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -g3 -LFLAGS = DEPS = OBJS = record.o message.o message_handler.o diff --git a/routing/Makefile b/routing/Makefile index 18bfa0f..57cc06b 100644 --- a/routing/Makefile +++ b/routing/Makefile @@ -1,12 +1,9 @@ DHT_DIR = dht -CC = gcc -CFLAGS = $(INCLUDE) -I$(DHT_DIR) -O0 -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) diff --git a/secio/Makefile b/secio/Makefile index 59a0167..696275b 100644 --- a/secio/Makefile +++ b/secio/Makefile @@ -1,16 +1,8 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -Wall -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/swarm/Makefile b/swarm/Makefile index c5bf8d0..88bb67f 100644 --- a/swarm/Makefile +++ b/swarm/Makefile @@ -1,16 +1,8 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -Wall -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/utils/Makefile b/utils/Makefile index 5e9d048..a726924 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -1,16 +1,8 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -Wall -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 942a128..b151cfa 100644 --- a/yamux/Makefile +++ b/yamux/Makefile @@ -1,16 +1,8 @@ -CC = gcc -CFLAGS = $(INCLUDE) -O0 -Wall -Werror -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) From 83c97bab78e870fdce4534b7365a446c6ab4a6e0 Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Mon, 3 Dec 2018 07:24:15 -0500 Subject: [PATCH 10/16] Makefile: make first build targe all Otherwise when you give make command it will do just link --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4f2e097..1eab075 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,8 @@ endif OBJS = $(shell (find $(COMPONENTS) -name *.o)) +all: test + link: compile $(AR) rcs libp2p.a $(OBJS) $(LINKER_FLAGS) @@ -24,8 +26,6 @@ test: compile link rebuild: clean all -all: test - clean: $(foreach dir,$(COMPONENTS), $(MAKE) -C $(dir) clean ;) make -C test clean From f60d6560b122a7ab6fbf0ba5d6cf98d0fb832c8f Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Mon, 3 Dec 2018 07:31:01 -0500 Subject: [PATCH 11/16] Makefile: change the test build target - no more cd --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1eab075..f44fb2a 100644 --- a/Makefile +++ b/Makefile @@ -21,8 +21,8 @@ link: compile compile: $(foreach dir,$(COMPONENTS), $(MAKE) -C $(dir) all ;) -test: compile link - cd test; make all; +test: link + make -C test all; rebuild: clean all From 29d7a412fe243f6185118b0156c4b9c25e9e5b0b Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Mon, 3 Dec 2018 08:20:00 -0500 Subject: [PATCH 12/16] gitignore: add cscope files in gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 710471f..0f4957b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ .settings/language.settings.xml *.a test/testit_libp2p +cscope.files +cscope.out From d386a4b496ead52f78d91372a1e063d5ecb61233 Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Mon, 3 Dec 2018 08:20:51 -0500 Subject: [PATCH 13/16] build: fix all build warnings --- conn/dialer.c | 3 +-- include/libp2p/crypto/rsa.h | 4 ++-- peer/peer.c | 2 -- routing/dht.c | 5 ----- routing/dht_protocol.c | 1 - secio/secio.c | 4 ++-- 6 files changed, 5 insertions(+), 14 deletions(-) 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/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/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/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/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 From 2949b2468fc5e0682095ec2878fec017efdd78e8 Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Mon, 3 Dec 2018 09:24:50 -0500 Subject: [PATCH 14/16] Makefile: build libp2p as shared library --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f44fb2a..2d7f3aa 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,11 @@ COMPONENTS = conn crypto db thirdparty hashmap identify net os peer record routing secio swarm utils yamux export DEBUG = true +export SHARED = true 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 +export CFLAGS = $(INCLUDE) -Wall -O0 -fPIC ifdef DEBUG CFLAGS += -g3 @@ -17,6 +18,9 @@ all: test link: compile $(AR) rcs libp2p.a $(OBJS) $(LINKER_FLAGS) +#ifdef SHARED + gcc -shared -o libp2p.so $(OBJS) $(LINKER_FLAGS) +#endif compile: $(foreach dir,$(COMPONENTS), $(MAKE) -C $(dir) all ;) From 797e4462d62c1251fce2da8a5a41b3f42ee4da8d Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Mon, 3 Dec 2018 09:25:35 -0500 Subject: [PATCH 15/16] gitignore: ignore .so.* files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 0f4957b..4f91830 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ *.o .settings/language.settings.xml *.a +*.so +*.so.* test/testit_libp2p cscope.files cscope.out From 3e35485820f9cfa80f3d5cdac34e04b930d21df7 Mon Sep 17 00:00:00 2001 From: Radu Iliescu Date: Wed, 5 Dec 2018 08:52:11 -0500 Subject: [PATCH 16/16] Update multihash subproject --- c-multihash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c-multihash b/c-multihash index bc6c083..e9847bb 160000 --- a/c-multihash +++ b/c-multihash @@ -1 +1 @@ -Subproject commit bc6c0830136d39c87b9f59a335d096db882418f6 +Subproject commit e9847bb8520ae554a7ddfaa47b17577b30d0d56f