Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 9f31659

Browse files
committed
Merge branch 'develop'
2 parents f21b69c + 3c5352c commit 9f31659

File tree

197 files changed

+12035
-4233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+12035
-4233
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ docs/html/
9292

9393
# Python
9494
__pycache__/
95+
96+
# Certificate for build system
97+
pem/*.inc
98+
99+
# Legato app related files
100+
resolv.conf
101+
output_base/
102+
_build_endpoint/
103+
endpoint.*.update
104+
.repo
105+
legato/

CONTRIBUTING.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
# Contributing to Tangle-accelerator
22

33
When contributing to this repository, please first discuss the change you wish to make via issue,
4-
email, or any other method with the owners of this repository before making a change.
4+
email, or any other method with the owners of this repository before making a change.
55

66
Please note we have a code of conduct, please follow it in all your interactions with the project.
77

88
## Pull Request Process
99

10-
1. Ensure any install or build dependencies are removed before the end of the layer when doing a
11-
build.
10+
1. Ensure any install or build dependencies are removed before the end of the layer when doing a build.
1211
2. Create a new branch for fixing or developing the changes.
1312
3. Run test with `bazel test //tests/...`, after finishing the changes.
14-
4. Update the README.md with details of changes to the interface, which includes new environment
15-
variables, exposed ports, useful file locations and container parameters.
13+
4. Update the README.md with details of changes to the interface, which includes new environment variables, exposed ports, useful file locations and container parameters.
1614
5. Run `hooks/formatter` before committing the changes.
1715
6. Rebase to the latest `develop` branch.
1816

1917
## Git Commit Message Guidelines
18+
2019
Read this [blog article](https://chris.beams.io/posts/git-commit/) and [this article](https://www.conventionalcommits.org/en/v1.0.0-beta.2/) and follow the instructions in these articles.
2120
The subject line of git commit message should follow this pattern
2221
`<type>[optional scope]: <description>`
@@ -28,6 +27,21 @@ The `type` includes the following 5 words depending on the content of the commit
2827
* test
2928
* doc
3029

30+
## Doxygen-friendly Representation
31+
32+
Function parameters should be in the following style or [doxygen official example](https://www.doxygen.nl/manual/commands.html#cmdparam) which allows the generating doxygen documentation.
33+
34+
```c
35+
/**
36+
* Copies bytes from a source memory area to a destination memory area,
37+
* where both areas may not overlap.
38+
* @param[out] dest The memory area to copy to.
39+
* @param[in] src The memory area to copy from.
40+
* @param[in] n The number of bytes to copy
41+
*/
42+
void memcpy(void *dest, const void *src, size_t n);
43+
```
44+
3145
## Code of Conduct
3246
3347
### Our Pledge

Doxyfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
DOXYFILE_ENCODING = UTF-8
22
PROJECT_NAME = "tangle-accelerator"
3-
PROJECT_NUMBER = 0.1.0
3+
PROJECT_NUMBER = 0.9.2
44
OUTPUT_DIRECTORY = docs/
55
OPTIMIZE_OUTPUT_FOR_C = YES
66
INPUT = . \
@@ -9,13 +9,19 @@ INPUT = . \
99
accelerator/core/request \
1010
accelerator/core/response \
1111
accelerator/core/serializer \
12+
endpoint \
13+
endpoint/endpointComp \
14+
endpoint/hal \
15+
endpoint \
1216
utils \
17+
utils/cache \
1318
common \
1419
storage \
1520
connectivity/mqtt \
1621
connectivity/http
1722
FILE_PATTERNS = *.h \
18-
*.md
23+
*.md \
24+
*.c
1925
EXAMPLE_PATH = tests
2026
EXAMPLE_PATTERNS = test_*
2127
USE_MDFILE_AS_MAINPAGE = README.md

Makefile

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,59 @@ DCURL_DIR := third_party/dcurl
22
DCURL_LIB := $(DCURL_DIR)/build/libdcurl.so
33
MOSQUITTO_DIR := third_party/mosquitto
44
MOSQUITTO_LIB := $(MOSQUITTO_DIR)/lib/libmosquitto.so.1
5+
PEM_DIR = pem
6+
# Default pem file. See pem/README.md for more information
7+
PEM := $(PEM_DIR)/cert.pem
8+
OUTPUT_BASE_DIR := output_base
9+
# Endpoint build target. The default intends to the platform of your development system.
10+
EP_TARGET := simulator
11+
# Build test suite
12+
TESTS := false
13+
# Enable endpoint HTTPS connection to tangle-accelerator.
14+
# The endpoint uses HTTP connection to transmit encrypted data by default.
15+
# See "HTTPS Connection Support" in docs/endpoint.md for more information.
16+
ENFORCE_EP_HTTPS := false
17+
# The flags that will be preprocessed by mkapp program, part of Legato Application Framework.
18+
# Eventually, the processed flags are passed as compiler-time options.
19+
LEGATO_FLAGS :=
520
DEPS += $(DCURL_LIB)
621

7-
all: $(DEPS)
22+
# Determine to enable HTTPS connection
23+
ifeq ($(ENFORCE_EP_HTTPS), true)
24+
LEGATO_FLAGS += -DENDPOINT_HTTPS
25+
endif
826

9-
.PHONY: $(DCURL_LIB) $(MOSQUITTO_LIB)
27+
# Determine to build test suite
28+
ifeq ($(TESTS), true)
29+
LEGATO_FLAGS += -DENABLE_ENDPOINT_TEST
30+
endif
31+
32+
# The tangle-acclerator host for endpoint to connect
33+
ifdef EP_TA_HOST
34+
LEGATO_FLAGS += -DEP_TA_HOST=${EP_TA_HOST}
35+
endif
36+
# The tangle-acclerator port for endpoint to connect
37+
ifdef EP_TA_PORT
38+
LEGATO_FLAGS += -DEP_TA_PORT=${EP_TA_PORT}
39+
endif
40+
# The ssl seed for endpoint (optional)
41+
ifdef EP_SSL_SEED
42+
LEGATO_FLAGS += -DEP_SSL_SEED=${EP_SSL_SEED}
43+
endif
44+
45+
# Pass target into endpoint build process
46+
LEGATO_FLAGS += -DEP_TARGET=$(EP_TARGET)
47+
48+
# Prepend the "-C" flag at the beginging for passing cflags into mkapp
49+
LEGATO_FLAGS := $(foreach flags, $(LEGATO_FLAGS), -C $(flags))
50+
51+
# Include the build command from the specific target
52+
include endpoint/platform/$(EP_TARGET)/build.mk
53+
export EP_TARGET
54+
55+
all: $(DEPS) cert
56+
57+
.PHONY: $(DCURL_LIB) $(MOSQUITTO_LIB) legato cert check_pem
1058

1159
$(DCURL_LIB): $(DCURL_DIR)
1260
git submodule update --init $^
@@ -15,12 +63,36 @@ $(DCURL_LIB): $(DCURL_DIR)
1563
$(info Modify $^/build/local.mk for your environments.)
1664
$(MAKE) -C $^ all
1765

18-
MQTT: $(DCURL_LIB) $(MOSQUITTO_LIB)
66+
MQTT: $(DCURL_LIB) $(MOSQUITTO_LIB) cert
1967
$(MOSQUITTO_LIB): $(MOSQUITTO_DIR)
2068
git submodule update --init $^
2169
@echo
2270
$(MAKE) -C $^ WITH_DOCS=no
2371

72+
# Build endpoint Legato app
73+
legato: cert
74+
# Fetch the required external source code
75+
# FIXME: Use 'fetch' instead of 'build' to avoid extra building actions.
76+
# The 'build' option is for getting the header file like 'mam/mam/mam_endpoint_t_set.h',
77+
# which can not be downloaded when the 'fetch' option is used.
78+
bazel --output_base=$(OUTPUT_BASE_DIR) build //endpoint:libendpoint.so
79+
# Generate endpoint Legato app
80+
$(call platform-build-command)
81+
82+
cert: check_pem
83+
@xxd -i $(PEM) > $(PEM_DIR)/ca_crt.inc
84+
@sed -E \
85+
-e 's/(unsigned char)(.*)(\[\])(.*)/echo "\1 ca_crt_pem\3\4"/ge' \
86+
-e 's/(unsigned int)(.*)(=)(.*)/echo "\1 ca_crt_pem_len \3\4"/ge' \
87+
-e 's/^unsigned/static &/' \
88+
-e 's/(.*)(pem_len = )([0-9]+)(.*)/echo "\1\2$$((\3+1))\4"/ge' \
89+
-e 's/(0[xX][[[:xdigit:]]+)$$/\1, 0x0/g' \
90+
-i $(PEM_DIR)/ca_crt.inc
91+
check_pem:
92+
ifndef PEM
93+
$(error PEM is not set)
94+
endif
95+
2496
clean:
2597
$(MAKE) -C $(DCURL_DIR) clean
2698
$(MAKE) -C $(MOSQUITTO_DIR) clean

README.md

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use scenarios such as MAM and [TangleID](https://tangleid.github.io/).
1919

2020
At the moment, it is not feasible to host fully-functioned full nodes on Raspberry Pi class
2121
Arm devices, but Raspberry Pi 3 is known to be capable to execute `Tangle-accelerator`
22-
without problems. Since it is written in C/C++ with [entangled](https://github.com/iotaledger/entangled),
22+
without problems. Since it is written in C/C++ with [iota.c](https://github.com/iotaledger/iota.c),
2323
both footprint and startup time are behaved pretty well.
2424

2525
## Architecture
@@ -28,7 +28,7 @@ both footprint and startup time are behaved pretty well.
2828

2929
```
3030
+-------------------------------------------+
31-
+----------+ | +-----------------+ +-----------+ |
31+
+----------+ | +-----------------+ +-----------+ |
3232
| | | | Service | | Cache | |
3333
| Client <-----> | | <---> | | |
3434
| | | | -Explorer | | -Trytes | |
@@ -37,7 +37,7 @@ both footprint and startup time are behaved pretty well.
3737
| | -Proxy | | | |
3838
| +-----------------+ +-----------+ |
3939
| ^ |
40-
+---------|---------------------------------+
40+
+---------|---------------------------------+
4141
v
4242
+-------------------------------------------+
4343
| Full Node |
@@ -52,7 +52,7 @@ both footprint and startup time are behaved pretty well.
5252

5353
`Tangle-accelerator` helps to reattach pending transactions were attached from `Tangle-accelerator`.
5454
Reattachment increases chances of confirmation and prevents messages being pruned when full nodes perform snapshot.
55-
Clients should provide a unique ID as the identifier to each message and it's corresponding transaction hash since a new transaction hash will be generated after reattachment.
55+
Clients should provide a unique ID as the identifier to each message and it's corresponding transaction hash since a new transaction hash will be generated after reattachment.
5656

5757
`Tangle-accelerator` uses ScyllaDB to store each transaction's ID, hash and status(Pending or confirmed). `Tangle-accelerator` will periodically check the status of pending transactions and reattach transactions which have been pended too long. Confirmed transactions will be stored into permanodes.
5858

@@ -61,20 +61,23 @@ Clients can find the transaction alone with wanted message by using the ID to qu
6161
## Connectivity
6262

6363
`Tangle-accelerator`, at this moment, supports the following TCP/IP derived protocols:
64+
6465
* `HTTP`
65-
* `MQTT`
66+
* `MQTT`
6667

6768
### HTTP
69+
6870
`HTTP` can be used in the normal internet service. User can use RESTful APIs to interact with `tangle-accelerator`.
6971

7072
### MQTT
73+
7174
`MQTT` is a lightweight communication protocol which can be used in the IoT scenarios. `Tangle-accelerator`'s support to `MQTT` allows embedded devices to write data on IOTA internet with relative low quality hardware devices. We hope this will speed up DLT into our daily life.
7275

7376
## Documentation
7477

7578
This page contains basic instructions for setting up tangle-accelerator, You can generate full documentation and API reference via Doxygen. The documentation is under `docs/` after generated:
7679

77-
```
80+
```bash
7881
$ doxygen Doxyfile
7982
```
8083

@@ -90,74 +93,112 @@ Tangle-accelerator is built and launched through Bazel, it also requires Redis t
9093

9194
## Build from Source
9295

93-
Before running tangle-accelerator, please edit binding address/port of accelerator instance, IRI, and redis server in `accelerator/config.h` unless they are all localhost and/or you don't want to provide external connection. With dependency of [entangled](https://github.com/iotaledger/entangled), IRI address doesn't support https at the moment. Here are some configurations and command you might need to change and use:
96+
Before running tangle-accelerator, please edit binding address/port of accelerator instance, IOTA full node, and redis server in `accelerator/config.h` unless they are all localhost and/or you don't want to provide external connection. With dependency of [iota.c](https://github.com/iotaledger/iota.c), IOTA full node address doesn't support https at the moment. Here are some configurations and command you might need to change and use:
9497

95-
* `TA_HOST`: binding address of accelerator instance
96-
* `TA_PORT`: port of accelerator instance
97-
* `IRI_HOST`: binding address of IRI
98-
* `IRI_PORT`: port of IRI
99-
* `quiet`: Turn off logging message
98+
* `ta_host`: Binding address of accelerator instance.
99+
* `ta_port`: Port of accelerator instance.
100+
* `node_host`: Binding address of IOTA full node which includes IRI and Hornet or other community implementation.
101+
* `node_port`: Port of IOTA full node.
102+
* `http_threads`: Determine thread pool size to process HTTP connections.
103+
* `quiet`: Turn off logging message.
100104

101-
```
105+
```bash
102106
$ make && bazel run //accelerator
103107
```
108+
104109
### Building Options
110+
105111
Tangle-accelerator supports several different build time options.
106112

107113
* Docker images
108114
* MQTT connectivity
109115
* External database
116+
* Debug Mode
117+
118+
Debug mode enables tangle-accelerator to display extra `debug` logs.
119+
120+
```bash
121+
$ bazel run --define build_type=debug //accelerator
122+
```
123+
124+
* Profiling Mode
125+
126+
Profiling mode adds `-pg` flag when compiling tangle-accelerator. This allows tangle-accelerator to write profile information for the analysis program gprof.
127+
128+
```bash
129+
$ bazel run --define build_type=profile //accelerator
130+
```
110131

111132
See [docs/build.md](docs/build.md) for more information.
112133

113134
## Developing
114135

115136
The codebase of this repository follows [Google's C++ guidelines](https://google.github.io/styleguide/cppguide.html):
116-
- Please run `hooks/autohook.sh install` after initial checkout.
117-
- Pass `-c dbg` for building with debug symbols.
137+
138+
* Please run `hooks/autohook.sh install` after initial checkout.
139+
* Pass `-c dbg` for building with debug symbols.
118140

119141
### Tools required for running git commit hook
120-
- buildifier
121-
- clang-format
142+
143+
* buildifier
144+
* clang-format
145+
* [shfmt](https://github.com/mvdan/sh)
122146

123147
### Buildifier
148+
124149
Buildifier can be installed with `bazel` or `go`
125150

126151
#### Install with go
152+
127153
1. change directory to `$GOPATH`
128154
2. run `$ go get github.com/bazelbuild/buildtools/buildifier`
129155
The executable file will be located under `$GOPATH/bin`
130156
3. make a soft link for global usage, run
131157
`$ sudo ln -s $HOME/go/bin/buildifier /usr/bin/buildifier`
132158

133159
#### Install with bazel
160+
134161
1. clone `bazelbuild/buildtools` repository
135162
`$ git clone https://github.com/bazelbuild/buildtools.git`
136163
2. change directory to `buildtools`
137164
3. build it with bazel command, `$ bazel build //buildifier`
138165
The executable file will be located under `path/to/buildtools/bazel-bin`
139-
4. make a soft link or move the executable file under `/usr/bin`
166+
4. make a soft link or move the executable file under `/usr/bin`
140167

141168
### clang-format
169+
142170
clang-format can be installed by command:
143-
- Debian/Ubuntu based systems: `$ sudo apt-get install clang-format`
144-
- macOS: `$ brew install clang-format`
145171

172+
* Debian/Ubuntu based systems: `$ sudo apt-get install clang-format`
173+
* macOS: `$ brew install clang-format`
174+
175+
### shfmt
176+
177+
It requires Go 1.13 or above, and install it with following command.
178+
179+
```shell
180+
GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt
181+
```
146182

147183
## Usage
184+
148185
`Tangle-accelerator` currently supports two categories of APIs
186+
149187
* Direct API: check [wiki page](https://github.com/DLTcollab/tangle-accelerator/wiki) for details.
150-
* Proxy API to IRI core functionalities
188+
* Proxy API to IOTA core functionalities
189+
190+
### Full Node Proxy API
151191

152-
### IRI Proxy API
153-
`tangle-accelerator` allows the use of IRI core APIs. The calling process does not have to be aware of the destination machine running IRI. With the exactly same format of IRI API, `tangle-accelerator` would help users forward the request to IRI and forward the response back to users.
154-
We support two way to forward Proxy APIs to IRI:
155-
1. Bypass Proxy APIs directly to IRI.
156-
2. Process the Proxy APIs, then transmit them to IRI.
192+
`tangle-accelerator` allows the use of IOTA core APIs. The calling process does not have to be aware of the destination machine running IOTA full node. With the exactly same format of IOTA core APIs, `tangle-accelerator` would help users forward the request to IOTA full node and forward the response back to users.
193+
We support two way to forward Proxy APIs to IOTA full node:
194+
195+
1. Bypass Proxy APIs directly to IOTA full node.
196+
2. Process the Proxy APIs, then transmit them to IOTA full node.
157197

158198
The user can choose which way they want with CLI argument `--proxy_passthrough`.
159199
All the Proxy APIs are supported with the first way.
160200
However, the second way currently only supports the followings Proxy APIs:
201+
161202
* checkConsistency
162203
* findTransactions
163204
* getBalances
@@ -166,5 +207,6 @@ However, the second way currently only supports the followings Proxy APIs:
166207
* getTrytes
167208

168209
## Licensing
210+
169211
`Tangle-accelerator` is freely redistributable under the MIT License. Use of this source
170212
code is governed by a MIT-style license that can be found in the `LICENSE` file.

0 commit comments

Comments
 (0)