diff --git a/LICENSE b/LICENSE index b9ed260..3d2d9ab 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,5 @@ Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors. +Copyright (C) 2018 Ievgen Korokyi. Copyright (C) 2017 IOTA AS, IOTA Foundation and Developers. Copyright (C) 2016 Shinya Yagyu. diff --git a/Makefile b/Makefile index 6c4d100..b9f59f1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = 0.4.0 +VERSION = 0.4.1 OUT ?= ./build SRC := src @@ -35,6 +35,9 @@ include mk/cpu-features.mk # Handle git submodule include mk/submodule.mk +# Board specific compiler flags +include mk/board.mk + # Assign the hardware to CPU if no hardware is specified PLATFORMS := $(BUILD_AVX) $(BUILD_SSE) $(BUILD_GENERIC) $(BUILD_GPU) $(BUILD_FPGA_ACCEL) ENABLE_PLATFORMS := $(findstring 1,$(PLATFORMS)) @@ -99,7 +102,7 @@ LIBS := $(addprefix $(OUT)/, $(LIBS)) JARS := dcurljni-$(VERSION).jar JARS := $(addprefix $(OUT)/, $(JARS)) -PREQ := config $(TESTS) $(LIBS) +PREQ := $(SUBS) config $(TESTS) $(LIBS) ifeq ("$(BUILD_JNI)","1") PREQ += $(JARS) endif @@ -152,27 +155,31 @@ OBJS += \ remote_common.o \ remote_interface.o -WORKER_OBJS := $(addprefix $(OUT)/worker-,$(filter-out remote_interface.o, $(OBJS))) +WORKER_EXCLUDE_OBJS := remote_interface.o +ifeq ("$(BUILD_JNI)", "1") +WORKER_EXCLUDE_OBJS += jni/iri-pearldiver-exlib.o +endif +WORKER_OBJS := $(addprefix $(OUT)/worker-,$(filter-out $(WORKER_EXCLUDE_OBJS), $(OBJS))) WORKER_CFLAGS := $(filter-out -DENABLE_REMOTE, $(CFLAGS)) endif OBJS := $(addprefix $(OUT)/, $(OBJS)) -$(OUT)/test-%.o: tests/test-%.c $(LIBTUV_PATH)/include +$(OUT)/test-%.o: tests/test-%.c $(VECHO) " CC\t$@\n" - $(Q)$(CC) -o $@ $(CFLAGS) -I $(SRC) $(LIBTUV_INCLUDE) -c -MMD -MF $@.d $< + $(Q)$(CC) -o $@ $(CFLAGS) -I $(SRC) $(SUB_INCLUDE) -c -MMD -MF $@.d $< -$(OUT)/%.o: $(SRC)/%.c $(LIBTUV_PATH)/include $(LIBRABBITMQ_PATH)/build/include +$(OUT)/%.o: $(SRC)/%.c $(SUB_OBJS) $(VECHO) " CC\t$@\n" - $(Q)$(CC) -o $@ $(CFLAGS) $(LIBTUV_INCLUDE) $(LIBRABBITMQ_INCLUDE) -c -MMD -MF $@.d $< + $(Q)$(CC) -o $@ $(CFLAGS) $(SUB_INCLUDE) -c -MMD -MF $@.d $< -$(OUT)/test-%: $(OUT)/test-%.o $(OBJS) $(LIBTUV_LIBRARY) $(LIBRABBITMQ_LIBRARY) +$(OUT)/test-%: $(OUT)/test-%.o $(OBJS) $(SUB_OBJS) $(VECHO) " LD\t$@\n" - $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBRABBITMQ_LINK) + $(Q)$(CC) -o $@ $^ $(LDFLAGS) -$(OUT)/libdcurl.so: $(OBJS) $(LIBTUV_LIBRARY) $(LIBRABBITMQ_LIBRARY) +$(OUT)/libdcurl.so: $(OBJS) $(SUB_OBJS) $(VECHO) " LD\t$@\n" - $(Q)$(CC) -shared -o $@ $^ $(LDFLAGS) $(LIBRABBITMQ_LINK) + $(Q)$(CC) -shared -o $@ $^ $(LDFLAGS) ifeq ("$(BUILD_REMOTE)", "1") include mk/remote.mk diff --git a/README.md b/README.md index 0857fec..a444256 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,9 @@ In addition, dcurl supports FPGA-accelerated PoW, described in [docs/fpga-accele dcurl can be regarded as the drop-in replacement for [ccurl](https://github.com/iotaledger/ccurl). IOTA Reference Implementation (IRI) adaptation is available to benefit from hardware-accelerated PoW. - ## Build Instructions Check [docs/build-n-test.md](docs/build-n-test.md) for details. - ## Performance After integrating dcurl into IRI, performance of [attachToTangle](https://iota.readme.io/reference#attachtotangle) is measured as following. * Each sampling is measured with 30 transaction trytes and total 200 samples are measured. @@ -25,7 +23,6 @@ After integrating dcurl into IRI, performance of [attachToTangle](https://iota.r * Settings: enable 2 pow tasks in CPU, 1 pow tasks in GPU at the same time ![](https://github.com/raw/DLTcollab/dcurl/develop/docs/benchmark.png) - ## IRI Adaptation [Modified IRI accepting external PoW Library](https://github.com/DLTcollab/iri) Supported IRI version: 1.7.0 @@ -63,6 +60,27 @@ pull requests to dcurl. it faciliates dcurl to perform hardware-accelerated PoW operations on edge devices. +## FAQ +- What is **binary encoded ternary**? + + It is a skill to transform the ternary trit value to two separate bits value.\ + Hence multiple trits can be compressed to two separate data of the same data type and fully utilize the space. + +- Can the project [Batch Binary Encoded Ternary Curl](https://github.com/luca-moser/bct_curl) be applied to dcurl? + + The answer is no.\ + They both use the same skill, **binary encoded ternary**.\ + However, their purpose are totally different. + - **bct_curl**: + + Focus on hashing the multiple data of the same length at the same time.\ + It ends when the hashing is finished. + + - **dcurl**: + + Focus on trying the different values of one transaction at the same time to find the nonce value.\ + The procedure of finding the nonce value also does the hashing.\ + However, it ends when the nonce value is found, which means one of the values is acceptable. ## Licensing `dcurl` is freely redistributable under the MIT License. diff --git a/docs/build-n-test.md b/docs/build-n-test.md index 04982b8..ce2e615 100644 --- a/docs/build-n-test.md +++ b/docs/build-n-test.md @@ -17,9 +17,10 @@ - ``BUILD_SSE``: build the Intel SSE-accelerated Curl backend. - ``BUILD_GPU``: build the OpenCL-based GPU accelerations. - ``BUILD_FPGA_ACCEL``: build the interface interacting with the Cyclone V FPGA based accelerator. Verified on DE10-nano board and Arrow SoCKit board. + - ``BUILD_REMOTE``: build with the remote interface and create the remote worker executable for calculating PoW on remote devices. - ``BUILD_JNI``: build a JAR file including the shared library and the JAVA bytecode for IRI. The build system would generate JNI header file downloading from [latest JAVA source](https://github.com/DLTcollab/iri). - - ``BUILD_COMPAT``: build extra cCurl compatible interface. + - ``BUILD_COMPAT``: build extra cCurl compatible interface. **[deprecated]** - ``BUILD_STAT``: show the statistics of the PoW information. - ``BUILD_DEBUG``: dump verbose messages internally. Build with the corresponding Sanitizer to detect software potential bugs if the value is `address`, `undefined` or `thread`. diff --git a/docs/remote-interface.md b/docs/remote-interface.md index 26d6e22..61b89d2 100644 --- a/docs/remote-interface.md +++ b/docs/remote-interface.md @@ -1,67 +1,76 @@ -# Remote interface -## Introduction - -``` - +-----------------------------------------------+ - | remote interface | - | +----------------------------------------+ | - | +----------------------------------------+| | - | +----------------------------------------+|+ | - | | RabbitMQ-provided RPC |+ | - | +----------------------------------------+ | - | | ^ | - +------------|---------------------|------------+ - +------------|---------------------|------------+ - | | RabbitMQ broker | | - | | | | - | | +------------------+ | - | v +------------------+| | - | +------------------+ +------------------+|| | - | | incoming queue | | private queue ||| | - | | | | ||| | - | | - trytes | | - PoW result ||| | - | | - mwm | | ||+ | - | | | | |+ | - | +------------------+ +------------------+ | - | | ^ | - +------------|---------------------|------------+ - v | - +---------------------------------------------+ - +---------------------------------------------+| - +---------------------------------------------+|+ - | remote worker |+ - +---------------------------------------------+ -``` -To support asynchronous remote procedure call, remote interface in dcurl provides an interface named as `Remote_ImplContext` to implement it. dcurl currently uses RabbitMQ C client to implement asynchronous RPC in remote interface. Remote interface provides thread management to support an asynchronous RPC per thread. - -Here are detailed implementations of the RabbitMQ-provided RPC pattern as follows: -* Asynchronous RPC requests are inserted into the message queue, `incoming_queue`, in RabbitMQ broker -* Asynchronous RPCs with exclusive private queues (callback queues) with TTL = 10s property -* Correlation ID is not used -* An asynchronous RPC uses a connection to RabbitMQ broker -* Remote workers can obtain requests from `incoming_queue` by default exchange of RabbitMQ broker - -## How to test remote interface in localhost -You need to open three terminals - -Terminal 1: Run the RabbitMQ broker You can quickly use docker to run the RabbitMQ broker, rabbitmq -``` -$ sudo docker run -d rabbitmq -``` - -Terminal 2: Run remote workers -``` -$ ./build/remote-worker -``` -How to build remote worker on FPGA board -``` -$ make BUILD_REMOTE=1 BUILD_FPGA_ACCEL=1 BOARD=de10nano -``` - -Terminal 3: Run check -``` -$ make BUILD_REMOTE=1 BUILD_DEBUG=1 check -``` - -## Requirements -Remote interface requires RabbitMQ broker +# Remote interface +## Introduction + +``` + +-----------------------------------------------+ + | remote interface | + | +----------------------------------------+ | + | +----------------------------------------+| | + | +----------------------------------------+|+ | + | | RabbitMQ-provided RPC |+ | + | +----------------------------------------+ | + | | ^ | + +------------|---------------------|------------+ + +------------|---------------------|------------+ + | | RabbitMQ broker | | + | | | | + | | +------------------+ | + | v +------------------+| | + | +------------------+ +------------------+|| | + | | incoming queue | | private queue ||| | + | | | | ||| | + | | - trytes | | - PoW result ||| | + | | - mwm | | ||+ | + | | | | |+ | + | +------------------+ +------------------+ | + | | ^ | + +------------|---------------------|------------+ + v | + +---------------------------------------------+ + +---------------------------------------------+| + +---------------------------------------------+|+ + | remote worker |+ + +---------------------------------------------+ +``` +To support asynchronous remote procedure call, remote interface in dcurl provides an interface named as `Remote_ImplContext` to implement it.\ +dcurl currently uses RabbitMQ C client to implement asynchronous RPC in remote interface.\ +Remote interface provides thread management to support an asynchronous RPC per thread. + +Here are detailed implementations of the RabbitMQ-provided RPC pattern as follows: +* Asynchronous RPC requests are inserted into the message queue, `incoming_queue`, in RabbitMQ broker +* Asynchronous RPCs with exclusive private queues (callback queues) with TTL = 10s property +* Correlation ID is not used +* An asynchronous RPC uses a connection to RabbitMQ broker +* Remote workers can obtain requests from `incoming_queue` by default exchange of RabbitMQ broker + +## How to test remote interface in localhost +You need to open three terminals + +**Terminal 1:**\ +Run the RabbitMQ broker\ +You can quickly use docker to run the RabbitMQ broker, rabbitmq +``` +$ sudo docker run -d -p 5672:5672 rabbitmq +``` + +--- + +**Terminal 2:**\ +Build and run the remote worker +``` +$ cd dcurl +$ make BUILD_REMOTE=1 BUILD_DEBUG=1 +$ ./build/remote-worker +``` + +--- + +**Terminal 3:**\ +Run the tests to send requests to remote worker +``` +$ cd dcurl +$ make BUILD_REMOTE=1 BUILD_DEBUG=1 check +``` + +## Requirements +Remote interface requires RabbitMQ broker diff --git a/jni/iri-pearldiver-exlib.c b/jni/iri-pearldiver-exlib.c index bc1deba..fe0bf3c 100644 --- a/jni/iri-pearldiver-exlib.c +++ b/jni/iri-pearldiver-exlib.c @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #include "iri-pearldiver-exlib.h" #include #include diff --git a/mk/board.mk b/mk/board.mk new file mode 100644 index 0000000..9917188 --- /dev/null +++ b/mk/board.mk @@ -0,0 +1,3 @@ +ifeq ($(BOARD),de10nano) + CFLAGS += -mcpu=cortex-a9 -mtune=cortex-a9 -mfloat-abi=hard -mfpu=neon +endif diff --git a/mk/common.mk b/mk/common.mk index fcb3521..56251fc 100644 --- a/mk/common.mk +++ b/mk/common.mk @@ -26,7 +26,7 @@ NO_COLOR = \e[0m $(OUT)/test-%.done: $(OUT)/test-% $(Q)$(PRINTF) "*** Validating $< ***\n" $(Q)./$< && $(PRINTF) "\t$(PASS_COLOR)[ Verified ]$(NO_COLOR)\n" -check: $(addsuffix .done, $(TESTS)) +check: $(SUBS) $(addsuffix .done, $(TESTS)) config: $(OUT)/config-timestamp diff --git a/mk/remote.mk b/mk/remote.mk index 667f8e7..4c69c90 100644 --- a/mk/remote.mk +++ b/mk/remote.mk @@ -1,8 +1,8 @@ # Build remote-worker -$(OUT)/worker-%.o: $(SRC)/%.c $(LIBTUV_PATH)/include $(LIBRABBITMQ_PATH)/build/include +$(OUT)/worker-%.o: $(SRC)/%.c $(VECHO) " CC\t$@\n" - $(Q)$(CC) -o $@ $(WORKER_CFLAGS) $(LIBTUV_INCLUDE) $(LIBRABBITMQ_INCLUDE) -c -MMD -MF $@.d $< + $(Q)$(CC) -o $@ $(WORKER_CFLAGS) $(SUB_INCLUDE) -c -MMD -MF $@.d $< -$(OUT)/remote-worker: $(OUT)/remote_worker.o $(WORKER_OBJS) $(LIBTUV_LIBRARY) $(LIBRABBITMQ_LIBRARY) +$(OUT)/remote-worker: $(OUT)/remote_worker.o $(WORKER_OBJS) $(SUB_OBJS) $(VECHO) " LD\t$@\n" - $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBRABBITMQ_LINK) + $(Q)$(CC) -o $@ $^ $(LDFLAGS) diff --git a/mk/submodule.mk b/mk/submodule.mk index 12c7164..a027d74 100644 --- a/mk/submodule.mk +++ b/mk/submodule.mk @@ -18,42 +18,54 @@ LIBTUV_PATH = deps/libtuv LIBTUV_INCLUDE := -I $(LIBTUV_PATH)/include LIBTUV_PLATFORM := $(UNAME_M)-$(UNAME_S) LIBTUV_BOARD := $(BOARD) -# PIC (Position-Independent-Code) library -LIBTUV_LIBRARY := $(LIBTUV_PATH)/build/$(LIBTUV_PLATFORM)/release/lib/libtuv.o +# PIC (Position-Independent-Code) object file +LIBTUV_OBJS := $(LIBTUV_PATH)/build/$(LIBTUV_PLATFORM)/release/lib/libtuv.o $(LIBTUV_PATH)/include: git submodule update --init $(LIBTUV_PATH) -$(LIBTUV_LIBRARY): +$(LIBTUV_OBJS): $(MAKE) -C $(LIBTUV_PATH) TUV_BUILD_TYPE=release TUV_CREATE_PIC_LIB=yes TUV_PLATFORM=$(LIBTUV_PLATFORM) TUV_BOARD=$(LIBTUV_BOARD) # librabbitmq related variables LIBRABBITMQ_PATH = deps/rabbitmq-c LIBRABBITMQ_INCLUDE := -I $(LIBRABBITMQ_PATH)/build/include -LIBRABBITMQ_LIB_PATH := $(LIBRABBITMQ_PATH)/build/librabbitmq/ +LIBRABBITMQ_OBJS := $(LIBRABBITMQ_PATH)/build/librabbitmq/CMakeFiles/rabbitmq.dir/*.o ifeq ($(UNAME_S),darwin) - # macOS - LIBRABBITMQ_LINK := -Wl,-rpath,$(LIBRABBITMQ_LIB_PATH) -L$(LIBRABBITMQ_LIB_PATH) -lrabbitmq - LIBRABBITMQ_LIBRARY := $(LIBRABBITMQ_LIB_PATH)/librabbitmq.dylib -else - LIBRABBITMQ_LINK := -Wl,-rpath=$(LIBRABBITMQ_LIB_PATH) -L$(LIBRABBITMQ_LIB_PATH) -lrabbitmq - LIBRABBITMQ_LIBRARY := $(LIBRABBITMQ_LIB_PATH)/librabbitmq.so + OPENSSL_PATH := /usr/local/opt/openssl + LDFLAGS += -L$(OPENSSL_PATH)/lib -lcrypto -lssl endif -$(LIBRABBITMQ_PATH)/build/include: +$(LIBRABBITMQ_PATH)/librabbitmq: git submodule update --init $(LIBRABBITMQ_PATH) - mkdir $(LIBRABBITMQ_PATH)/build + +$(LIBRABBITMQ_OBJS): + mkdir -p $(LIBRABBITMQ_PATH)/build ifeq ($(UNAME_S),darwin) # macOS cd $(LIBRABBITMQ_PATH)/build && \ - cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DCMAKE_INSTALL_PREFIX=. .. && \ + cmake -DOPENSSL_ROOT_DIR=$(OPENSSL_PATH) -DCMAKE_INSTALL_PREFIX=. .. && \ cmake --build . --target install else cd $(LIBRABBITMQ_PATH)/build && \ cmake -DCMAKE_INSTALL_PREFIX=. .. && \ cmake --build . --target install endif - -$(LIBRABBITMQ_LIBRARY): cd $(LIBRABBITMQ_PATH)/build && \ cmake --build . + +# Submodules +SUBS := $(LIBTUV_PATH)/include +ifeq ($(BUILD_REMOTE),1) + SUBS += $(LIBRABBITMQ_PATH)/librabbitmq +endif +# Submodule related objects +SUB_OBJS := $(LIBTUV_OBJS) +ifeq ($(BUILD_REMOTE),1) + SUB_OBJS += $(LIBRABBITMQ_OBJS) +endif +# Submodule C flags for including header files +SUB_INCLUDE := $(LIBTUV_INCLUDE) +ifeq ($(BUILD_REMOTE),1) + SUB_INCLUDE += $(LIBRABBITMQ_INCLUDE) +endif diff --git a/src/clcontext.c b/src/clcontext.c index 438b221..c817740 100644 --- a/src/clcontext.c +++ b/src/clcontext.c @@ -1,8 +1,10 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Copyright (C) 2017 IOTA AS, IOTA Foundation and Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018 BiiLabs Co., Ltd. and Contributors + * Copyright (C) 2017 IOTA AS, IOTA Foundation and Developers + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include "clcontext.h" diff --git a/src/clcontext.h b/src/clcontext.h index 05bdc0d..434bf7c 100644 --- a/src/clcontext.h +++ b/src/clcontext.h @@ -1,7 +1,10 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018 BiiLabs Co., Ltd. and Contributors + * Copyright (C) 2017 IOTA AS, IOTA Foundation and Developers + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #ifndef CLCONTEXT_H_ diff --git a/src/common.c b/src/common.c index 0094fdf..e2e39a1 100644 --- a/src/common.c +++ b/src/common.c @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #include "common.h" double diff_in_second(struct timespec t1, struct timespec t2) diff --git a/src/common.h b/src/common.h index c675118..3595d16 100644 --- a/src/common.h +++ b/src/common.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef COMMON_H_ #define COMMON_H_ @@ -8,16 +16,18 @@ #define __DCURL_MAJOR__ 0 #define __DCURL_MINOR__ 4 -#define __DCURL_PATCH__ 0 +#define __DCURL_PATCH__ 1 double diff_in_second(struct timespec t1, struct timespec t2); -static inline void ddprintf(const char *format, ...) { +static inline void ddprintf(const char *format, ...) +{ #if defined(ENABLE_DEBUG) va_list ap; va_start(ap, format); vprintf(format, ap); va_end(ap); + fflush(stdout); #endif } diff --git a/src/compat-ccurl.c b/src/compat-ccurl.c index 94d559c..423de15 100644 --- a/src/compat-ccurl.c +++ b/src/compat-ccurl.c @@ -1,7 +1,9 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include diff --git a/src/constants.c b/src/constants.c index 38ba2e7..668e12b 100644 --- a/src/constants.c +++ b/src/constants.c @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + char TryteAlphabet[] = "9ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int indices[] = { diff --git a/src/constants.h b/src/constants.h index 04ef2f8..751eb48 100644 --- a/src/constants.h +++ b/src/constants.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef CONSTANTS_H_ #define CONSTANTS_H_ @@ -19,53 +27,56 @@ #define SignatureMessageFragmentTrinaryOffset 0 #define SignatureMessageFragmentTrinarySize 6561 -#define AddressTrinaryOffset \ - SignatureMessageFragmentTrinaryOffset + SignatureMessageFragmentTrinarySize +#define AddressTrinaryOffset \ + (SignatureMessageFragmentTrinaryOffset + \ + SignatureMessageFragmentTrinarySize) #define AddressTrinarySize 243 -#define ValueTrinaryOffset AddressTrinaryOffset + AddressTrinarySize +#define ValueTrinaryOffset (AddressTrinaryOffset + AddressTrinarySize) #define ValueTrinarySize 81 -#define ObsoleteTagTrinaryOffset ValueTrinaryOffset + ValueTrinarySize +#define ObsoleteTagTrinaryOffset (ValueTrinaryOffset + ValueTrinarySize) #define ObsoleteTagTrinarySize 81 -#define TimestampTrinaryOffset ObsoleteTagTrinaryOffset + ObsoleteTagTrinarySize +#define TimestampTrinaryOffset \ + (ObsoleteTagTrinaryOffset + ObsoleteTagTrinarySize) #define TimestampTrinarySize 27 -#define CurrentIndexTrinaryOffset TimestampTrinaryOffset + TimestampTrinarySize +#define CurrentIndexTrinaryOffset \ + (TimestampTrinaryOffset + TimestampTrinarySize) #define CurrentIndexTrinarySize 27 #define LastIndexTrinaryOffset \ - CurrentIndexTrinaryOffset + CurrentIndexTrinarySize + (CurrentIndexTrinaryOffset + CurrentIndexTrinarySize) #define LastIndexTrinarySize 27 -#define BundleTrinaryOffset LastIndexTrinaryOffset + LastIndexTrinarySize +#define BundleTrinaryOffset (LastIndexTrinaryOffset + LastIndexTrinarySize) #define BundleTrinarySize 243 -#define TrunkTransactionTrinaryOffset BundleTrinaryOffset + BundleTrinarySize +#define TrunkTransactionTrinaryOffset (BundleTrinaryOffset + BundleTrinarySize) #define TrunkTransactionTrinarySize 243 #define BranchTransactionTrinaryOffset \ - TrunkTransactionTrinaryOffset + TrunkTransactionTrinarySize + (TrunkTransactionTrinaryOffset + TrunkTransactionTrinarySize) #define BranchTransactionTrinarySize 243 #define TagTrinaryOffset \ - BranchTransactionTrinaryOffset + BranchTransactionTrinarySize + (BranchTransactionTrinaryOffset + BranchTransactionTrinarySize) #define TagTrinarySize 81 -#define AttachmentTimestampTrinaryOffset TagTrinaryOffset + TagTrinarySize +#define AttachmentTimestampTrinaryOffset (TagTrinaryOffset + TagTrinarySize) #define AttachmentTimestampTrinarySize 27 #define AttachmentTimestampLowerBoundTrinaryOffset \ - AttachmentTimestampTrinaryOffset + AttachmentTimestampTrinarySize + (AttachmentTimestampTrinaryOffset + AttachmentTimestampTrinarySize) #define AttachmentTimestampLowerBoundTrinarySize 27 #define AttachmentTimestampUpperBoundTrinaryOffset \ - AttachmentTimestampLowerBoundTrinaryOffset + \ - AttachmentTimestampLowerBoundTrinarySize + (AttachmentTimestampLowerBoundTrinaryOffset + \ + AttachmentTimestampLowerBoundTrinarySize) #define AttachmentTimestampUpperBoundTrinarySize 27 -#define NonceTrinaryOffset \ - AttachmentTimestampUpperBoundTrinaryOffset + \ - AttachmentTimestampUpperBoundTrinarySize +#define NonceTrinaryOffset \ + (AttachmentTimestampUpperBoundTrinaryOffset + \ + AttachmentTimestampUpperBoundTrinarySize) #define NonceTrinarySize 81 -#define transactionTrinarySize \ - SignatureMessageFragmentTrinarySize + AddressTrinarySize + \ - ValueTrinarySize + ObsoleteTagTrinarySize + TimestampTrinarySize + \ - CurrentIndexTrinarySize + LastIndexTrinarySize + BundleTrinarySize + \ - TrunkTransactionTrinarySize + BranchTransactionTrinarySize + \ - TagTrinarySize + AttachmentTimestampTrinarySize + \ - AttachmentTimestampLowerBoundTrinarySize + \ - AttachmentTimestampUpperBoundTrinarySize + NonceTrinarySize +#define transactionTrinarySize \ + (SignatureMessageFragmentTrinarySize + AddressTrinarySize + \ + ValueTrinarySize + ObsoleteTagTrinarySize + TimestampTrinarySize + \ + CurrentIndexTrinarySize + LastIndexTrinarySize + BundleTrinarySize + \ + TrunkTransactionTrinarySize + BranchTransactionTrinarySize + \ + TagTrinarySize + AttachmentTimestampTrinarySize + \ + AttachmentTimestampLowerBoundTrinarySize + \ + AttachmentTimestampUpperBoundTrinarySize + NonceTrinarySize) extern char TryteAlphabet[]; extern const int indices[]; diff --git a/src/cpu-utils.h b/src/cpu-utils.h index 5d06150..52f308c 100644 --- a/src/cpu-utils.h +++ b/src/cpu-utils.h @@ -1,7 +1,9 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include diff --git a/src/curl.c b/src/curl.c index e587340..bc18a59 100644 --- a/src/curl.c +++ b/src/curl.c @@ -1,7 +1,9 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include "curl.h" diff --git a/src/curl.h b/src/curl.h index 94d775c..c431855 100644 --- a/src/curl.h +++ b/src/curl.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef CURL_H_ #define CURL_H_ diff --git a/src/dcurl.c b/src/dcurl.c index 88235da..cb54bec 100644 --- a/src/dcurl.c +++ b/src/dcurl.c @@ -1,7 +1,9 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include "dcurl.h" diff --git a/src/dcurl.h b/src/dcurl.h index fbf36bf..f5b67e5 100644 --- a/src/dcurl.h +++ b/src/dcurl.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef DCURL_H_ #define DCURL_H_ diff --git a/src/implcontext.c b/src/implcontext.c index 711f884..999bac3 100644 --- a/src/implcontext.c +++ b/src/implcontext.c @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #include "implcontext.h" #include @@ -16,7 +24,7 @@ bool initializeImplContext(ImplContext *impl_ctx) bool res = impl_ctx->initialize(impl_ctx); if (res) { ddprintf(MSG_PREFIX "Implementation %s is initialized successfully\n", - impl_ctx->description); + impl_ctx->description); } return res; } diff --git a/src/implcontext.h b/src/implcontext.h index 9a406ce..65495e7 100644 --- a/src/implcontext.h +++ b/src/implcontext.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef IMPL_CTX_H_ #define IMPL_CTX_H_ diff --git a/src/list.h b/src/list.h index dd8f2aa..8630c46 100644 --- a/src/list.h +++ b/src/list.h @@ -1,7 +1,9 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ /* Linux-like double-linked list implementation */ diff --git a/src/pow_avx.c b/src/pow_avx.c index 1feb72b..dbc7325 100644 --- a/src/pow_avx.c +++ b/src/pow_avx.c @@ -1,8 +1,10 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Copyright (C) 2016 Shinya Yagyu. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * Copyright (C) 2016 Shinya Yagyu + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include "pow_avx.h" @@ -29,8 +31,8 @@ static void transform256(__m256i *lmid, __m256i *hmid) alpha = lfrom[t1]; beta = hfrom[t1]; - delta = _mm256_and_si256( alpha, _mm256_xor_si256(lfrom[t2], beta)); - /* alpha & (lfrom[t2] ^ beta) */ + delta = _mm256_and_si256(alpha, _mm256_xor_si256(lfrom[t2], beta)); + /* alpha & (lfrom[t2] ^ beta) */ lto[j] = _mm256_andnot_si256(delta, one); /* ~delta */ hto[j] = _mm256_or_si256(_mm256_xor_si256(alpha, hfrom[t2]), delta); /* (alpha ^ hfrom[t2]) | delta */ @@ -46,8 +48,8 @@ static void transform256(__m256i *lmid, __m256i *hmid) t2 = indices[j + 1]; alpha = lfrom[t1]; beta = hfrom[t1]; - delta = _mm256_and_si256( alpha, _mm256_xor_si256(lfrom[t2], beta)); - /* alpha & (lfrom[t2] ^ beta) */ + delta = _mm256_and_si256(alpha, _mm256_xor_si256(lfrom[t2], beta)); + /* alpha & (lfrom[t2] ^ beta) */ lto[j] = _mm256_andnot_si256(delta, one); /* ~delta */ hto[j] = _mm256_or_si256(_mm256_xor_si256(alpha, hfrom[t2]), delta); /* (alpha ^ hfrom[t2]) | delta */ @@ -226,7 +228,7 @@ static void transform256(__m256d *lmid, __m256d *hmid) alpha = lfrom[t1]; beta = hfrom[t1]; delta = _mm256_and_pd(alpha, _mm256_xor_pd(lfrom[t2], beta)); - /* alpha & (lfrom[t2] ^ beta) */ + /* alpha & (lfrom[t2] ^ beta) */ lto[j] = _mm256_andnot_pd(delta, one); /* ~delta */ hto[j] = _mm256_or_pd(_mm256_xor_pd(alpha, hfrom[t2]), delta); /* (alpha ^ hfrom[t2]) | delta */ @@ -244,7 +246,7 @@ static void transform256(__m256d *lmid, __m256d *hmid) alpha = lfrom[t1]; beta = hfrom[t1]; delta = _mm256_and_pd(alpha, _mm256_xor_pd(lfrom[t2], beta)); - /* alpha & (lfrom[t2] ^ beta) */ + /* alpha & (lfrom[t2] ^ beta) */ lto[j] = _mm256_andnot_pd(delta, one); /* ~delta */ hto[j] = _mm256_or_pd(_mm256_xor_pd(alpha, hfrom[t2]), delta); /* (alpha ^ hfrom[t2]) | delta */ diff --git a/src/pow_c.c b/src/pow_c.c index 640b659..910bcdb 100644 --- a/src/pow_c.c +++ b/src/pow_c.c @@ -1,8 +1,10 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Copyright (C) 2016 Shinya Yagyu. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * Copyright (C) 2016 Shinya Yagyu + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include "pow_c.h" diff --git a/src/pow_c.h b/src/pow_c.h index 546a6db..bab7478 100644 --- a/src/pow_c.h +++ b/src/pow_c.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef POW_C_H_ #define POW_C_H_ diff --git a/src/pow_cl.c b/src/pow_cl.c index 429d94a..2b3ef15 100644 --- a/src/pow_cl.c +++ b/src/pow_cl.c @@ -1,8 +1,10 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Copyright (C) 2017 IOTA AS, IOTA Foundation and Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * Copyright (C) 2017 IOTA AS, IOTA Foundation and Developers + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include "pow_cl.h" @@ -264,7 +266,7 @@ static bool PoWCL_Context_Initialize(ImplContext *impl_ctx) PoW_CL_Context *ctx = (PoW_CL_Context *) malloc(sizeof(PoW_CL_Context) * impl_ctx->num_max_thread); if (!ctx) - return false; + goto fail; for (int i = 0; i < impl_ctx->num_max_thread; i++) { ctx[i].clctx = &_opencl_ctx[i]; diff --git a/src/pow_cl.h b/src/pow_cl.h index 50d5876..34c2cd7 100644 --- a/src/pow_cl.h +++ b/src/pow_cl.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef POW_CL_H_ #define POW_CL_H_ diff --git a/src/pow_fpga_accel.c b/src/pow_fpga_accel.c index eb4a644..1f20499 100644 --- a/src/pow_fpga_accel.c +++ b/src/pow_fpga_accel.c @@ -1,8 +1,10 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Copyright (c) 2018 Ievgen Korokyi. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * Copyright (c) 2018 Ievgen Korokyi + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include "pow_fpga_accel.h" diff --git a/src/pow_fpga_accel.h b/src/pow_fpga_accel.h index bb1eaa0..119018c 100644 --- a/src/pow_fpga_accel.h +++ b/src/pow_fpga_accel.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef POW_FPGA_ACCEL_H_ #define POW_FPGA_ACCEL_H_ diff --git a/src/pow_kernel.cl b/src/pow_kernel.cl index 32b7946..55295b1 100644 --- a/src/pow_kernel.cl +++ b/src/pow_kernel.cl @@ -1,7 +1,9 @@ /* - * Copyright (C) 2017 IOTA AS, IOTA Foundation and Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2017 IOTA AS, IOTA Foundation and Developers + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #define HASH_TRITS_LENGTH 243 diff --git a/src/pow_sse.c b/src/pow_sse.c index cec30d1..a6a0a2a 100644 --- a/src/pow_sse.c +++ b/src/pow_sse.c @@ -1,8 +1,10 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Copyright (C) 2016 Shinya Yagyu. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * Copyright (C) 2016 Shinya Yagyu + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include "pow_sse.h" diff --git a/src/pow_sse.h b/src/pow_sse.h index 73e5af7..4216b59 100644 --- a/src/pow_sse.h +++ b/src/pow_sse.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef POW_SSE_H_ #define POW_SSE_H_ diff --git a/src/remote_common.c b/src/remote_common.c index 9a39669..12c1545 100644 --- a/src/remote_common.c +++ b/src/remote_common.c @@ -1,7 +1,9 @@ /* - * Copyright (C) 2019 dcurl Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include "remote_common.h" @@ -21,8 +23,7 @@ bool die_on_amqp_error(amqp_rpc_reply_t x, char const *context) break; case AMQP_RESPONSE_LIBRARY_EXCEPTION: - ddprintf("%s: %s\n", context, - amqp_error_string2(x.library_error)); + ddprintf("%s: %s\n", context, amqp_error_string2(x.library_error)); break; case AMQP_RESPONSE_SERVER_EXCEPTION: @@ -30,21 +31,21 @@ bool die_on_amqp_error(amqp_rpc_reply_t x, char const *context) case AMQP_CONNECTION_CLOSE_METHOD: { amqp_connection_close_t *m = (amqp_connection_close_t *) x.reply.decoded; - ddprintf("%s: server connection error %uh, message: %.*s\n", - context, m->reply_code, (int) m->reply_text.len, - (char *) m->reply_text.bytes); + ddprintf("%s: server connection error %u, message: %.*s\n", + context, m->reply_code, (int) m->reply_text.len, + (char *) m->reply_text.bytes); break; } case AMQP_CHANNEL_CLOSE_METHOD: { amqp_channel_close_t *m = (amqp_channel_close_t *) x.reply.decoded; - ddprintf("%s: server channel error %uh, message: %.*s\n", - context, m->reply_code, (int) m->reply_text.len, - (char *) m->reply_text.bytes); + ddprintf("%s: server channel error %u, message: %.*s\n", context, + m->reply_code, (int) m->reply_text.len, + (char *) m->reply_text.bytes); break; } default: - ddprintf("%s: unknown server error, method id 0x%08X\n", - context, x.reply.id); + ddprintf("%s: unknown server error, method id 0x%08X\n", context, + x.reply.id); break; } break; @@ -84,8 +85,7 @@ bool connect_broker(amqp_connection_state_t *conn) /* Open the channel in the rabbitmq broker */ amqp_channel_open(*conn, 1); - if (!(die_on_amqp_error(amqp_get_rpc_reply(*conn), - "Opennng the channel"))) + if (!(die_on_amqp_error(amqp_get_rpc_reply(*conn), "Opennng the channel"))) goto channel_close; return true; @@ -196,12 +196,14 @@ bool wait_response_message(amqp_connection_state_t *conn, if (!die_on_amqp_error(amqp_get_rpc_reply(*conn), "Wait method frame")) return false; - ddprintf(MSG_PREFIX "Frame type: %u channel: %u\n", frame.frame_type, frame.channel); + ddprintf(MSG_PREFIX "Frame type: %u channel: %u\n", frame.frame_type, + frame.channel); if (frame.frame_type != AMQP_FRAME_METHOD) continue; - ddprintf(MSG_PREFIX "Method: %s\n", amqp_method_name(frame.payload.method.id)); + ddprintf(MSG_PREFIX "Method: %s\n", + amqp_method_name(frame.payload.method.id)); if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) continue; @@ -209,9 +211,9 @@ bool wait_response_message(amqp_connection_state_t *conn, #if defined(ENABLE_DEBUG) d = (amqp_basic_deliver_t *) frame.payload.method.decoded; ddprintf(MSG_PREFIX "Delivery: %u exchange: %.*s routingkey: %.*s\n", - (unsigned) d->delivery_tag, (int) d->exchange.len, - (char *) d->exchange.bytes, (int) d->routing_key.len, - (char *) d->routing_key.bytes); + (unsigned) d->delivery_tag, (int) d->exchange.len, + (char *) d->exchange.bytes, (int) d->routing_key.len, + (char *) d->routing_key.bytes); #endif amqp_maybe_release_buffers(*conn); @@ -224,15 +226,15 @@ bool wait_response_message(amqp_connection_state_t *conn, return false; if (frame.frame_type != AMQP_FRAME_HEADER) { - ddprintf("Unexpected header!"); + ddprintf("Unexpected header!\n"); return false; } #if defined(ENABLE_DEBUG) p = (amqp_basic_properties_t *) frame.payload.properties.decoded; if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { - ddprintf(MSG_PREFIX "Content-type: %.*s\n", (int) p->content_type.len, - (char *) p->content_type.bytes); + ddprintf(MSG_PREFIX "Content-type: %.*s\n", + (int) p->content_type.len, (char *) p->content_type.bytes); } #endif ddprintf("---\n"); @@ -241,7 +243,7 @@ bool wait_response_message(amqp_connection_state_t *conn, body_received = 0; while (body_received < body_target) { if (!die_on_error(amqp_simple_wait_frame_noblock(*conn, &frame, &t), - "RPC timeout")) + "RPC timeout")) return false; if (!die_on_amqp_error(amqp_get_rpc_reply(*conn), @@ -249,22 +251,24 @@ bool wait_response_message(amqp_connection_state_t *conn, return false; if (frame.frame_type != AMQP_FRAME_BODY) { - ddprintf("Unexpected body"); + ddprintf("Unexpected body\n"); return false; } body_received += frame.payload.body_fragment.len; } if (body_received != body_target) { - ddprintf("Received body is small than body target"); + ddprintf("Received body is small than body target\n"); return false; } memcpy(frame_body, (char *) frame.payload.body_fragment.bytes, body_len); - ddprintf(MSG_PREFIX "PoW result: %.*s", (int) frame.payload.body_fragment.len, - (char *) frame.payload.body_fragment.bytes); + ddprintf(MSG_PREFIX "PoW result: %.*s\n", + (int) frame.payload.body_fragment.len, + (char *) frame.payload.body_fragment.bytes); + ddprintf("---\n"); /* everything was fine, we can quit now because we received the reply */ return true; diff --git a/src/remote_common.h b/src/remote_common.h index a063601..cb1805e 100644 --- a/src/remote_common.h +++ b/src/remote_common.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef REMOTE_COMMON_H_ #define REMOTE_COMMON_H_ diff --git a/src/remote_interface.c b/src/remote_interface.c index 76f0c6f..da326c4 100644 --- a/src/remote_interface.c +++ b/src/remote_interface.c @@ -1,7 +1,9 @@ /* - * Copyright (C) 2019 dcurl Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include "remote_interface.h" @@ -13,7 +15,7 @@ bool initializeRemoteContext(RemoteImplContext *remote_ctx) bool res = remote_ctx->initialize(remote_ctx); if (res) { ddprintf(MSG_PREFIX "Implementation %s is initialized successfully\n", - remote_ctx->description); + remote_ctx->description); } return res; } @@ -109,16 +111,17 @@ static bool Remote_doPoW(RemoteImplContext *remote_ctx, void *pow_ctx) sprintf(buf, "%d", ctx->mwm); memcpy(messagebody + TRANSACTION_TRYTES_LENGTH, buf, 4); - if (!declare_callback_queue(&remote_ctx->conn[ctx->indexOfContext], 1, &reply_to_queue)) + if (!declare_callback_queue(&remote_ctx->conn[ctx->indexOfContext], 1, + &reply_to_queue)) goto fail; - if (!publish_message_with_reply_to(&remote_ctx->conn[ctx->indexOfContext], 1, - "incoming_queue", reply_to_queue, + if (!publish_message_with_reply_to(&remote_ctx->conn[ctx->indexOfContext], + 1, "incoming_queue", reply_to_queue, messagebody)) goto fail; - if (!wait_response_message(&remote_ctx->conn[ctx->indexOfContext], 1, reply_to_queue, - (char *) (ctx->output_trytes), + if (!wait_response_message(&remote_ctx->conn[ctx->indexOfContext], 1, + reply_to_queue, (char *) (ctx->output_trytes), TRANSACTION_TRYTES_LENGTH)) goto fail; @@ -142,8 +145,7 @@ static bool Remote_init(RemoteImplContext *remote_ctx) memset(remote_ctx->slots, 0, remote_ctx->num_max_thread * sizeof(bool)); - for(int i = 0 ; i < CONN_MAX; i++) - { + for (int i = 0; i < CONN_MAX; i++) { if (!connect_broker(&remote_ctx->conn[i])) goto fail_to_init; } @@ -164,7 +166,7 @@ static void Remote_destroy(RemoteImplContext *remote_ctx) { PoW_Remote_Context *ctx = (PoW_Remote_Context *) remote_ctx->context; - for(int i = 0; i < CONN_MAX; i++) + for (int i = 0; i < CONN_MAX; i++) disconnect_broker(&remote_ctx->conn[i]); free(ctx); diff --git a/src/remote_interface.h b/src/remote_interface.h index 0851984..07c5411 100644 --- a/src/remote_interface.h +++ b/src/remote_interface.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef REMOTE_INTERFACE_H_ #define REMOTE_INTERFACE_H_ diff --git a/src/remote_worker.c b/src/remote_worker.c index 12c9136..f8df527 100644 --- a/src/remote_worker.c +++ b/src/remote_worker.c @@ -1,13 +1,15 @@ /* - * Copyright (C) 2019 dcurl Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ +#include "common.h" #include "constants.h" #include "dcurl.h" #include "remote_common.h" -#include "common.h" int main(int argc, char const *const *argv) { @@ -30,7 +32,9 @@ int main(int argc, char const *const *argv) if (!consume_message(&conn, 1, &envelope)) goto fail; - ddprintf(MSG_PREFIX "Delivery %u, exchange %.*s, routingkey %.*s, callback queue: %s " + ddprintf( + MSG_PREFIX + "Delivery %u, exchange %.*s, routingkey %.*s, callback queue: %s " "\n", (unsigned) envelope.delivery_tag, (int) envelope.exchange.len, (char *) envelope.exchange.bytes, (int) envelope.routing_key.len, @@ -38,8 +42,8 @@ int main(int argc, char const *const *argv) (char *) envelope.message.properties.reply_to.bytes); if (envelope.message.properties._flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { ddprintf(MSG_PREFIX "Content-type: %.*s\n", - (int) envelope.message.properties.content_type.len, - (char *) envelope.message.properties.content_type.bytes); + (int) envelope.message.properties.content_type.len, + (char *) envelope.message.properties.content_type.bytes); } /* Message body format: transacton | mwm */ @@ -59,14 +63,14 @@ int main(int argc, char const *const *argv) /* Publish a message of remote PoW result */ if (!publish_message( - &conn, 1, - (char *) envelope.message.properties.reply_to.bytes, + &conn, 1, (char *) envelope.message.properties.reply_to.bytes, (char *) ret_trytes)) goto fail; free(ret_trytes); amqp_destroy_envelope(&envelope); - ddprintf(MSG_PREFIX "Publishing PoW result to callback queue is done\n"); + ddprintf(MSG_PREFIX + "Publishing PoW result to callback queue is done\n"); ddprintf(MSG_PREFIX "---\n"); } diff --git a/src/trinary.c b/src/trinary.c index ac12e87..ad75e85 100644 --- a/src/trinary.c +++ b/src/trinary.c @@ -1,7 +1,9 @@ /* - * Copyright (C) 2018 dcurl Developers. - * Use of this source code is governed by MIT license that can be - * found in the LICENSE file. + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. */ #include "trinary.h" diff --git a/src/trinary.h b/src/trinary.h index 44dacc9..f01cffc 100644 --- a/src/trinary.h +++ b/src/trinary.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef TRINARY_H_ #define TRINARY_H_ diff --git a/src/trinary_sse42.h b/src/trinary_sse42.h index 33f3c3e..9f4684f 100644 --- a/src/trinary_sse42.h +++ b/src/trinary_sse42.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef TRINARY_SSE42_H_ #define TRINARY_SSE42_H_ diff --git a/tests/common.h b/tests/common.h index 2543ec0..62f3ad0 100644 --- a/tests/common.h +++ b/tests/common.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #ifndef TEST_COMMON_H #define TEST_COMMON_H diff --git a/tests/test-curl.c b/tests/test-curl.c index 81f1315..dca9a96 100644 --- a/tests/test-curl.c +++ b/tests/test-curl.c @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #include "common.h" int main() diff --git a/tests/test-dcurl.c b/tests/test-dcurl.c index fcee3bd..3fb5a10 100644 --- a/tests/test-dcurl.c +++ b/tests/test-dcurl.c @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + /* Test program for dcurl */ #include "common.h" #include "dcurl.h" diff --git a/tests/test-multi-pow.c b/tests/test-multi-pow.c index ac9a876..df77c72 100644 --- a/tests/test-multi-pow.c +++ b/tests/test-multi-pow.c @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + /* Test program for thread-safe dcurl */ #include #include "common.h" @@ -16,8 +24,7 @@ void *dcurl_entry_cb(void *arg) { dcurl_item *item = (dcurl_item *) arg; /* test dcurl Implementation with mwm = 14 */ - int8_t *ret_trytes = - dcurl_entry(item->input_trytes, item->mwm, 8); + int8_t *ret_trytes = dcurl_entry(item->input_trytes, item->mwm, 8); assert(ret_trytes && "dcurl_entry() failed"); memcpy(item->output_trytes, ret_trytes, TRANSACTION_TRYTES_LENGTH); free(ret_trytes); @@ -77,8 +84,7 @@ int main() for (int i = 0; i < THREAD_MAX; i++) { memcpy(items[i].input_trytes, trytes, TRANSACTION_TRYTES_LENGTH); items[i].mwm = mwm; - pthread_create(&threads[i], NULL, dcurl_entry_cb, - (void *) &items[i]); + pthread_create(&threads[i], NULL, dcurl_entry_cb, (void *) &items[i]); } for (int i = 0; i < THREAD_MAX; i++) diff --git a/tests/test-pow.c b/tests/test-pow.c index 522a169..9666914 100644 --- a/tests/test-pow.c +++ b/tests/test-pow.c @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + /* Test program for pow_*.c */ #include "common.h" #include "implcontext.h" diff --git a/tests/test-trinary.c b/tests/test-trinary.c index d5cfbc2..b69079a 100644 --- a/tests/test-trinary.c +++ b/tests/test-trinary.c @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + #include "common.h" int main()