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

Commit 9e8b43d

Browse files
authored
Merge pull request #404 from DLTcollab/develop
Pre-release v0.8.0
2 parents 6c43471 + 33ef7cd commit 9e8b43d

File tree

125 files changed

+11440
-7971
lines changed

Some content is hidden

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

125 files changed

+11440
-7971
lines changed

.bazelrc

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,53 @@
1-
test --copt='-ggdb3'
1+
build --copt -W
2+
build --copt -Wall
3+
build --copt -Wextra
4+
build --output_filter='^//((?!external:).)*$'
5+
26
coverage -s
37
coverage --experimental_cc_coverage
48
coverage --combined_report=lcov
59
coverage --coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main
610
coverage --instrumentation_filter="-/tests[/:]"
711

8-
# Address Sanitizer:--config asan
12+
13+
test --copt='-ggdb3'
14+
15+
# enforce using python2
16+
# see also: https://github.com/bazelbuild/rules_docker#known-issues
17+
build --host_force_python=PY2
18+
test --host_force_python=PY2
19+
run --host_force_python=PY2
20+
21+
# --config asan: Address sanitizer
922
build:asan --strip=never
23+
build:asan --copt -DADDRESS_SANITIZER
1024
build:asan --copt -fsanitize=address
1125
build:asan --copt -fno-omit-frame-pointer
1226
build:asan --linkopt -fsanitize=address
1327

14-
# Thread Sanitizer: --config tsan
28+
# --config tsan: ThreadSanitizer
1529
build:tsan --strip=never
30+
build:tsan --copt -DTHREAD_SANITIZER
31+
build:tsan --copt -DDYNAMIC_ANNOTATIONS_ENABLED=1
32+
build:tsan --copt -DDYNAMIC_ANNOTATIONS_EXTERNAL_IMPL=1
1633
build:tsan --copt -fsanitize=thread
1734
build:tsan --copt -fno-omit-frame-pointer
1835
build:tsan --linkopt -fsanitize=thread
36+
build:tsan --linkopt -ltsan
37+
38+
# --config msan: Memory sanitizer
39+
build:msan --strip=never
40+
build:msan --copt -DADDRESS_SANITIZER
41+
build:msan --copt -fsanitize=memory
42+
build:msan --copt -fno-omit-frame-pointer
43+
build:msan --linkopt -fsanitize=memory
1944

20-
# Undefined Behavior Sanitizer: --config ubsan
45+
# --config ubsan: Undefined Behavior Sanitizer
2146
build:ubsan --strip=never
2247
build:ubsan --copt -fsanitize=undefined
2348
build:ubsan --copt -fno-omit-frame-pointer
2449
build:ubsan --linkopt -fsanitize=undefined
50+
build:ubsan --linkopt -lubsan
2551

52+
import %workspace%/hooks/toolchains.rc
2653
try-import %workspace%/user.bazelrc

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ BreakConstructorInitializersBeforeComma: false
4343
BreakConstructorInitializers: BeforeColon
4444
BreakAfterJavaFieldAnnotations: false
4545
BreakStringLiterals: true
46-
ColumnLimit: 80
46+
ColumnLimit: 120
4747
CommentPragmas: '^ IWYU pragma:'
4848
CompactNamespaces: false
4949
ConstructorInitializerAllOnOneLineOrOnePerLine: true

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "third_party/hiredis"]
55
path = third_party/hiredis
66
url = https://github.com/redis/hiredis.git
7+
[submodule "third_party/mosquitto"]
8+
path = third_party/mosquitto
9+
url = https://github.com/eclipse/mosquitto.git

Doxyfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ INPUT = . \
88
request \
99
response \
1010
serializer \
11-
utils
11+
utils \
12+
connectivity/mqtt
1213
FILE_PATTERNS = *.h \
1314
*.md
1415
EXAMPLE_PATH = tests

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors
3+
Copyright (C) 2018-2020 BiiLabs Co., Ltd. and Contributors
44
All Rights Reserved.
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy

MQTT_server.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Introduction
2+
The structure of this information deisseminating network is based on MQTT protocol which consists of three components. `Connectivity Endpoint`, `tangle-accelerator` and `Parser`
3+
4+
### 1. Connectivity Endpoint
5+
This is a client implemented with any possible lightweight computing node (such as Raspberry Pi) and a communication module (i.e. NB-IoT module). There are some modems allowing users to send MQTT message with AT-command-like command, so for these kinds of modems, they don't need to run a `mosquitto`-dependent programs on the lightweight computing node.
6+
For the `Connectivity Endpoint` which uses a modem provides AT-command-like commands, few things they need to do are choosing the right topic (we use different topics to simulate RESTful methodology) and serializing the data/message into the demanded format which contains `Device ID` for TA requests. After the message is serialized into the demanded format, we can send this message with modem provided command as simple as we send a http request with Python.
7+
8+
### 2. tangle-accelerator
9+
TA (tangle-accelerator) plays a role of server which receives requests from communication module and processes the requests. However, under the structure of this MQTT information deisseminating network, both `tangle-accelerator` and `Connectivity Endpoint` are MQTT client. We must take care that `tangle-accelerator` is not a broker under this topology of MQTT information disseminating network.
10+
`tangle-accelerator` runs as a MQTT subscriber and publisher at the same time which listen to the requests on several different topics and respond the requests according to respective request result. We treat each topic as different URL path of http protocol does.
11+
12+
### 3. Parser
13+
The `Parser` plays a role of both subscriber and publisher simultaneously; thus, we will implement this `Parser`, which is a duplex client by modifying `mosquitto`'s client source code.
14+
Sometimes, it might necessitate parsing MQTT messages, since the messages which are sent from multifarious modems may vary from one to another. In order to support a wide range of modems from different manufactures, we can use a duplex client to revise the messages which are sent from modems into the regulated format, then send the message in regulated format to a specific topic which contains only requests follow TA's request format.
15+
16+
## Communication structure
17+
`<root>` is the host operator defined root path. It can be used if we want to choose a certain host of a cluster.
18+
19+
#### 1. Communication Endpoint sends message
20+
Communication endpoint would send message on topic `<root>/<API>/raw/<parser type ID>`
21+
On this topic, the messages are in raw types whose formats depend on the modems users chose.
22+
And the sub-topic, `<parser type ID>`, aims to pass the message to a appropriate parser (the work that parser should
23+
do is corresponding to multifarious manufacturers or even different modems).
24+
25+
The message should contain the `Device ID` of the `Communication Endpoint`, since the `Device ID` will be used in returning data for `tangle-accelerator`. Once the message is published, Communication Endpoint will start to listen the topic, `<root>/<API>/<Device ID>`. The resonse will be published into this topic
26+
#### 2. Parser parses raw message
27+
Parser parses messages came from topic `<root>/<API>/raw/<parser type ID>` into regulted format of TA.
28+
#### 3. Parser sends neat messages
29+
Parser sends parsed, neat, regulated format messages to topic `<root>/<API>`, and the messages contain `Device ID` of source devices as well.
30+
#### 3. TA receives the message
31+
TA receive the message from topic `<root>/<API>`, and then it starts to process the requests.
32+
The responses will be sent onto topic `<root>/<API>/<Device ID>`.

Makefile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
DCURL_DIR := third_party/dcurl
22
DCURL_LIB := $(DCURL_DIR)/build/libdcurl.so
3-
HIREDIS_DIR := third_party/hiredis
4-
HIREDIS_LIB := $(HIREDIS_DIR)/build/libdhiredis.a
5-
DEPS += $(DCURL_LIB) $(HIREDIS_LIB)
3+
MOSQITTO_DIR := third_party/mosquitto
4+
MOSQITTO_LIB := $(MOSQITTO_DIR)/lib/libmosquitto.so.1
5+
DEPS += $(DCURL_LIB)
66

77
all: $(DEPS)
88

9-
.PHONY: $(DCURL_LIB)
9+
.PHONY: $(DCURL_LIB) $(MOSQITTO_LIB)
1010

1111
$(DCURL_LIB): $(DCURL_DIR)
1212
git submodule update --init $^
@@ -15,14 +15,16 @@ $(DCURL_LIB): $(DCURL_DIR)
1515
$(info Modify $^/build/local.mk for your environments.)
1616
$(MAKE) -C $^ all
1717

18-
$(HIREDIS_LIB): $(HIREDIS_DIR)
18+
MQTT: $(DCURL_LIB) $(MOSQITTO_LIB)
19+
$(MOSQITTO_LIB): $(MOSQITTO_DIR)
1920
git submodule update --init $^
20-
$(MAKE) -C $^ static
21+
@echo
22+
$(MAKE) -C $^ WITH_DOCS=no
2123

2224
clean:
2325
$(MAKE) -C $(DCURL_DIR) clean
24-
$(MAKE) -C $(HIREDIS_DIR) clean
26+
$(MAKE) -C $(MOSQITTO_LIB) clean
2527

2628
distclean: clean
27-
$(RM) -r $(DCURL_DIR) $(HIREDIS_DIR)
28-
git checkout $(DCURL_DIR) $(HIREDIS_DIR)
29+
$(RM) -r $(DCURL_DIR)
30+
git checkout $(DCURL_DIR)

README.md

Lines changed: 121 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# Tangle-accelerator
22

3-
[![Build Status](https://badge.buildkite.com/0deb4c46f2f69363e4d326014843b92853733f243f379c70b5.svg)](https://buildkite.com/dltcollab/tangle-accelerator-test) [![Gitter](https://img.shields.io/gitter/room/DLTcollab/tangle-accelerator.svg)](https://gitter.im/DLTcollab/tangle-accelerator) [![GitHub release](https://img.shields.io/github/release-pre/DLTcollab/tangle-accelerator.svg)](https://github.com/DLTcollab/tangle-accelerator/releases)
3+
[![Build Status](https://badge.buildkite.com/0deb4c46f2f69363e4d326014843b92853733f243f379c70b5.svg)](https://buildkite.com/dltcollab/tangle-accelerator-test) [![GitHub release](https://img.shields.io/github/release-pre/DLTcollab/tangle-accelerator.svg)](https://github.com/DLTcollab/tangle-accelerator/releases)
44

55
`Tangle-accelerator` is a caching proxy server for [IOTA](https://www.iota.org/), which
66
can cache API requests and rewrite their responses as needed to be routed through full
7-
nodes. Thus, one instance of `Tangle-accelerator` can serve thousands of Tangle requests
8-
at once without accessing remote full nodes frequently.
7+
nodes. In other words, one instance of `Tangle-accelerator` can serve thousands of IOTA
8+
requests at once without accessing remote full nodes frequently, that improves the
9+
scalability and usability of [Tangle network](https://www.iota.org/research/meet-the-tangle).
10+
11+
Being at the edge as a key-value store, an edge-caching node powered by `Tangle-accelerator`
12+
does not have to communicate to typical [IOTA](https://www.iota.org/) full nodes for every API
13+
calls. Instead, the cached transaction data being sought is available as needed.
914

1015
As an intermediate server accelerateing interactions with the Tangle, it faciliates
1116
[dcurl](https://github.com/DLTcollab/dcurl) to perform hardware-accelerated PoW operations
1217
on edge devices. In the meanwhile, `Tangle-accelerator` provides shortcuts for certain
13-
use scenarios such as MAM and [TangleID](https://github.com/TangleID).
18+
use scenarios such as MAM and [TangleID](https://tangleid.github.io/).
1419

1520
At the moment, it is not feasible to host fully-functioned full nodes on Raspberry Pi class
1621
Arm devices, but Raspberry Pi 3 is known to be capable to execute `Tangle-accelerator`
@@ -43,6 +48,28 @@ both footprint and startup time are behaved pretty well.
4348
4449
```
4550

51+
### Transaction reattachment
52+
53+
`Tangle-accelerator` helps to reattach pending transactions were attached from `Tangle-accelerator`.
54+
Reattachment increases chances of confirmation and prevents messages being pruned when full nodes perform snapshot.
55+
Clients should provide a uniqle ID as the identifier to each message and it's corresponding transaction hash since a new transaction hash will be generated after reattachement.
56+
57+
`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.
58+
59+
Clients can find the transaction alone with wanted message by using the ID to query.
60+
61+
## Connectivity
62+
63+
`Tangle-accelerator`, at this moment, supports the following TCP/IP derived protocols:
64+
* `HTTP`
65+
* `MQTT`
66+
67+
### HTTP
68+
`HTTP` can be used in the normal internet service. User can use RESTful APIs to interact with `tangle-accelerator`.
69+
70+
### MQTT
71+
`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.
72+
4673
## Documentation
4774

4875
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:
@@ -71,7 +98,7 @@ Before running tangle-accelerator, please edit binding address/port of accelerat
7198
$ make && bazel run //accelerator
7299
```
73100

74-
### Build from docker
101+
### Optional: Build Docker Images
75102

76103
If you prefer building a docker image, tangle-accelerator also provides build rules for it. Note that you still have to edit configurations in `accelerator/config.h`.
77104

@@ -82,7 +109,73 @@ $ make && bazel run //accelerator:ta_image
82109
There's also an easier option to pull image from docker hub then simply run with default configs. Please do remember a redis-server is still required in this way.
83110

84111
```
85-
$ docker run -d --net=host --name tangle-accelerator wusyong/tangel-accelerator:latest
112+
$ docker run -d --net=host --name tangle-accelerator dltcollab/tangle-accelerator
113+
```
114+
115+
### Optional: Build and Push Docker Image to Docker Hub
116+
117+
Before pushing the docker image to Docker Hub, you need to log in the docker registry:
118+
119+
```
120+
$ docker login
121+
```
122+
123+
Then you could push the docker image with the following command:
124+
125+
```
126+
$ make && bazel run //accelerator:push_docker
127+
```
128+
129+
If you get the following error message:
130+
131+
```
132+
SyntaxError: invalid syntax
133+
----------------
134+
Note: The failure of target @containerregistry//:digester (with exit code 1) may have been caused by the fact that it is running under Python 3 instead of Python 2. Examine the error to determine if that appears to be the problem. Since this target is built in the host configuration, the only way to change its version is to set --host_force_python=PY2, which affects the entire build.
135+
136+
If this error started occurring in Bazel 0.27 and later, it may be because the Python toolchain now enforces that targets analyzed as PY2 and PY3 run under a Python 2 and Python 3 interpreter, respectively. See https://github.com/bazelbuild/bazel/issues/7899 for more information.
137+
------------
138+
```
139+
140+
Use the `--host_force_python=PY2` parameter to force the Bazel to use the Python2 in entire build.
141+
142+
```
143+
$ make && bazel run //accelerator:push_docker --host_force_python=PY2
144+
```
145+
146+
### Optional: Enable MQTT connectivity
147+
MQTT connectivity is an optional feature allowing IoT endpoint devices to collaborate with `Tangle-Accelerator`.
148+
149+
```
150+
make MQTT && bazel run //accelerator:accelerator_mqtt
151+
```
152+
153+
Note you may need to set up the `MQTT_HOST` and `TOPIC_ROOT` in `config.h` to connect to a MQTT broker.
154+
For more information for MQTT connectivity of `tangle-accelerator`, you could read `connectivity/mqtt/usage.md`.
155+
156+
### Optional: Enable external database for transaction reattachment
157+
Transaction reattachment is an optional feature.
158+
159+
You can enable it in the build time by adding option : `--define db=enable`
160+
161+
Transaction reattachment relies on ScyllDB, you need to install the dependency by following commands.
162+
163+
For Ubuntu Linux 16.04/x86_64:
164+
165+
```
166+
wget https://downloads.datastax.com/cpp-driver/ubuntu/16.04/cassandra/v2.14.1/cassandra-cpp-driver_2.14.1-1_amd64.deb
167+
wget https://downloads.datastax.com/cpp-driver/ubuntu/16.04/cassandra/v2.14.1/cassandra-cpp-driver-dev_2.14.1-1_amd64.deb
168+
sudo dpkg -i cassandra-cpp-driver_2.14.1-1_amd64.deb
169+
sudo dpkg -i cassandra-cpp-driver-dev_2.14.1-1_amd64.deb
170+
```
171+
172+
For Ubuntu Linux 18.04/x86_64:
173+
174+
```
175+
wget https://downloads.datastax.com/cpp-driver/ubuntu/18.04/cassandra/v2.14.1/cassandra-cpp-driver_2.14.1-1_amd64.deb
176+
wget https://downloads.datastax.com/cpp-driver/ubuntu/18.04/cassandra/v2.14.1/cassandra-cpp-driver-dev_2.14.1-1_amd64.deb
177+
sudo dpkg -i cassandra-cpp-driver_2.14.1-1_amd64.deb
178+
sudo dpkg -i cassandra-cpp-driver-dev_2.14.1-1_amd64.deb
86179
```
87180

88181
## Developing
@@ -111,14 +204,35 @@ Buildifier can be installed with `bazel` or `go`
111204
2. change directory to `buildtools`
112205
3. build it with bazel command, `$ bazel build //buildifier`
113206
The executable file will be located under `path/to/buildtools/bazel-bin`
114-
4. make a soft link
207+
4. make a soft link or move the executable file under `/usr/bin`
115208

116209
### clang-format
117210
clang-format can be installed by command:
118211
- Debian/Ubuntu based systems: `$ sudo apt-get install clang-format`
119212
- macOS: `$ brew install clang-format`
120213

121214

215+
## Usage
216+
`Tangle-accelerator` currently supports two categories of APIs
217+
* direct API: check [wiki page](https://github.com/DLTcollab/tangle-accelerator/wiki) for details.
218+
* Proxy API to IRI core functionalities
219+
220+
### IRI Porxy API
221+
`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.
222+
We support two way to forward Proxy APIs to IRI:
223+
1. Bypass Proxy APIs directly to IRI.
224+
2. Process the Proxy APIs, then transmit them to IRI.
225+
226+
The user can choose which way they want with CLI argument `--proxy_passthrough`.
227+
All the Proxy APIs are supported with the first way.
228+
However, the second way currently only supports the followings Proxy APIs:
229+
* checkConsistency
230+
* findTransactions
231+
* getBalances
232+
* getInclusionStates
233+
* getNodeInfo
234+
* getTrytes
235+
122236
## Licensing
123237
`Tangle-accelerator` is freely redistributable under the MIT License. Use of this source
124238
code is governed by a MIT-style license that can be found in the `LICENSE` file.

WORKSPACE

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
2+
load("//third_party:third_party.bzl", "third_party_deps")
23

34
git_repository(
45
name = "rules_iota",
5-
commit = "1cb59eea62fd1d071de213a9aa46e61e8273472d",
6+
commit = "73f598ad1ce3ba79ff22d747f723d6d5cbf351e1",
67
remote = "https://github.com/iotaledger/rules_iota.git",
78
)
89

10+
git_repository(
11+
name = "iota_toolchains",
12+
commit = "0f93f76fdff9f091dd3a99aa3f19b5d3f4f7f7fc",
13+
remote = "https://github.com/iotaledger/toolchains.git",
14+
)
15+
916
git_repository(
1017
name = "entangled",
11-
commit = "4960865730640d23e75ffbce84d3f74264cfcd28",
1218
remote = "https://github.com/iotaledger/entangled.git",
19+
tag = "cclient-v1.0.0-beta",
1320
)
1421

1522
git_repository(
@@ -21,12 +28,26 @@ git_repository(
2128
git_repository(
2229
name = "io_bazel_rules_docker",
2330
remote = "https://github.com/bazelbuild/rules_docker.git",
24-
tag = "v0.6.0",
31+
tag = "v0.7.0",
2532
)
2633

2734
load("@rules_iota//:defs.bzl", "iota_deps")
35+
load("@io_bazel_rules_docker//repositories:repositories.bzl", container_repositories = "repositories")
36+
37+
container_repositories()
38+
2839
load("@io_bazel_rules_docker//cc:image.bzl", _cc_image_repos = "repositories")
2940

3041
iota_deps()
3142

43+
third_party_deps()
44+
3245
_cc_image_repos()
46+
47+
load("@iota_toolchains//:toolchains.bzl", "setup_initial_deps")
48+
49+
setup_initial_deps()
50+
51+
load("@iota_toolchains//:defs.bzl", "setup_toolchains_repositories")
52+
53+
setup_toolchains_repositories()

0 commit comments

Comments
 (0)