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

Commit fcad2e1

Browse files
author
HYChang
committed
feat(endpoint): Improve endpoint build instructions
This commit adds the build instructions for generating endpoint test or app with different target. For compatibility with legato framework, we use the GNU Make build system to build endpoint. Use "make legato" to generate endpoint app. The macro TARGET intends to the target platform. The default TARGET is the platform on your development host. Set the TARGET like TARGET=wp77xx to generate specific platform endpoint app. The macro ENABLE_ENDPOINT_TEST is for generating the endpoint app in test mode. Set ENABLE_ENDPOINT_TEST=true to enable generating test mode endpoint app. The endpoint uses the sierra framework as based runtime system. Developers need to set up the sierra development environment to build endpoint as specific target. See docs/endpoint.md for more information. Close #591
1 parent 3cf2d2a commit fcad2e1

File tree

8 files changed

+194
-15
lines changed

8 files changed

+194
-15
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ pem/*.inc
100100
resolv.conf
101101
output_base/
102102
_build_endpoint/
103-
endpoint.wp77xx.update
103+
endpoint.*.update

Makefile

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,35 @@ DCURL_LIB := $(DCURL_DIR)/build/libdcurl.so
33
MOSQUITTO_DIR := third_party/mosquitto
44
MOSQUITTO_LIB := $(MOSQUITTO_DIR)/lib/libmosquitto.so.1
55
PEM_DIR = pem
6+
# Default pem file. See pem/README.md for more information
67
PEM := $(PEM_DIR)/cert.pem
78
NAMESERVER := 8.8.8.8
89
RESOLV_CONF_DIR := endpoint/endpointComp
910
OUTPUT_BASE_DIR := output_base
11+
# Endpoint build target. The default intends to the platform of your development system.
12+
TARGET := simulator
13+
# Build test suite
14+
TESTS := false
15+
# Enable endpoint HTTPS connection to tangle-accelerator.
16+
# The endpoint uses HTTP connection to transmit encrypted data by default.
17+
# See "HTTPS Connection Support" in docs/endpoint.md for more information.
18+
ENFORCE_EP_HTTPS := false
19+
# The CFLAGS to pass during endpoint app build
20+
ENDPOINT_CFLAGS :=
1021
DEPS += $(DCURL_LIB)
1122

23+
# Determine to enable HTTPS connection
24+
ifeq ($(ENFORCE_EP_HTTPS), true)
25+
ENDPOINT_CFLAGS += -C -DENDPOINT_HTTPS
26+
endif
27+
28+
# Determine to build test suite
29+
ifeq ($(TESTS), true)
30+
ENDPOINT_CFLAGS += -C -DENABLE_ENDPOINT_TEST
31+
endif
32+
33+
include endpoint/platform/$(TARGET)/build.mk
34+
1235
all: $(DEPS) cert
1336

1437
.PHONY: $(DCURL_LIB) $(MOSQUITTO_LIB) legato cert check_pem
@@ -36,7 +59,7 @@ legato: cert
3659
# which can not be downloaded when the 'fetch' option is used.
3760
bazel --output_base=$(OUTPUT_BASE_DIR) build //endpoint:libendpoint.so
3861
# Generate endpoint Legato app
39-
(cd endpoint && leaf shell -c "mkapp -v -t wp77xx endpoint.adef")
62+
$(call platform-build-command)
4063

4164
cert: check_pem
4265
@xxd -i $(PEM) > $(PEM_DIR)/ca_crt.inc

docs/endpoint.md

Lines changed: 137 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,149 @@
11
# Endpoint
2+
23
The endpoint is one of the components provided by Tangle-accelerator, running on a resource-constrained network connectivity module. The embedded devices can send messages to blockchain network (Tangle) with a connectivity module loaded endpoint. The message would be transmitted to connectivity module through UART. Message would be encrypted and send to tangle.
34

45
# Streaming Message Channel Implementation
6+
57
The encrypted message would be sent to Tangle with a streaming message channel API. The streaming message channel API would ensure the order of messages in the channel. The user who wants to fetch/send message to Tangle needs to provide `data_id`, `key` and `protocol` to identify a specific message.
68
A message sent by endpoint needs to be encrypted locally, which avoids message being peeked and modified.
79

8-
# How to use
10+
# How to build endpoint
11+
12+
## Setup Legato application framework development environment
13+
14+
The endpoint uses the Legato application framework as based runtime system. Developers need to set up the Sierra development environment to build endpoint as specific target.
15+
16+
### How to build endpoint application for wp77xx
17+
18+
[Leaf](https://docs.legato.io/latest/toolsLeaf.html) is a workspace manager that will download, install and configure the required software packages for a Legato development environment.
19+
20+
#### prerequisite packages required by leaf
21+
22+
```shell
23+
$ sudo apt install \
24+
python3-argcomplete \
25+
python3-colorama \
26+
python3-gnupg \
27+
python3-jsonschema \
28+
python3-requests \
29+
gnupg \
30+
bash-completion \
31+
xz-utils
932
```
10-
$ bazel build //endpoint:wp7702
11-
$ bazel build //endpoint:sim
33+
34+
Install leaf
35+
36+
```shell
37+
$ curl -sLO https://downloads.sierrawireless.com/tools/leaf/leaf_latest.deb && sudo dpkg -i leaf_latest.deb
1238
```
1339

14-
## HTTPS Connection Support
15-
The endpoint uses http connection as default. The message which sent to tangle-accelerator has been encrypted. So the HTTP connection would not be unsafe. To build with https connection support, add `--define https=enable` option.
40+
Create a workspace
41+
42+
```shell
43+
$ mkdir -p workspace
44+
$ cd workspace
45+
```
46+
47+
Setup the wp77xx target profile
48+
49+
```shell
50+
$ leaf setup legato-stable -p swi-wp77_3.0.0
51+
```
52+
53+
Finally, make the wp77xx endpoint target. Be careful with the directory of tangle-accelerator. It should be located within the workspace directory.
54+
55+
```shell
56+
$ git clone https://github.com/DLTcollab/tangle-accelerator.git
57+
$ cd tangle-accelerator
58+
$ make TARGET=wp77xx legato # build endpoint as wp77xx target
59+
$ make TESTS=true TARGET=wp77xx legato # build endpoint as wp77xx target in test mode
60+
```
61+
62+
### How to build endpoint application for native target
63+
64+
Install required packages:
65+
66+
```shell
67+
$ sudo apt-get install -y \
68+
autoconf \
69+
automake \
70+
bash \
71+
bc \
72+
bison \
73+
bsdiff \
74+
build-essential \
75+
chrpath \
76+
cmake \
77+
cpio \
78+
diffstat \
79+
flex \
80+
gawk \
81+
gcovr \
82+
git \
83+
gperf \
84+
iputils-ping \
85+
libbz2-dev \
86+
libcurl4-gnutls-dev \
87+
libncurses5-dev \
88+
libncursesw5-dev \
89+
libsdl-dev \
90+
libssl-dev \
91+
libtool \
92+
libxml2-utils \
93+
ninja-build \
94+
python \
95+
python-git \
96+
python-jinja2 \
97+
python-pkg-resources \
98+
python3 \
99+
texinfo \
100+
unzip \
101+
wget \
102+
zlib1g-dev
16103
```
17-
$ bazel build --define https=enable //endpoint:wp7702
104+
105+
Create a workspace
106+
107+
```shell
108+
$ mkdir -p workspace
109+
$ cd workspace
110+
```
111+
112+
Clone a specific version of `legato`. The `19.07.0` is the preferred stable version.
113+
114+
```shell
115+
$ repo init -u git://github.com/legatoproject/manifest -m legato/releases/19.07.0.xml # specific legato 19.07.0 version
116+
$ repo sync
117+
```
118+
119+
Build legato as native target
120+
121+
```shell
122+
$ cd legato
123+
$ make localhost
124+
```
125+
126+
Checkout the shell to legato shell
127+
128+
```shell
129+
$ source framework/tools/scripts/configlegatoenv
130+
```
131+
132+
Finally, use GNU Make to build endpoint application at the root directory of tangle-accelerator.
133+
134+
```shell
135+
$ cd tangle-accelerator
136+
$ make legato # build endpoint as native target
137+
```
138+
139+
The endpoint will be built at `endpoint/_build_endpoint/localhost/app/endpoint/staging/read-only/bin/endpoint`
140+
141+
## HTTPS Connection Support
142+
143+
The endpoint uses HTTP connection as default. The message sent to tangle-accelerator has been encrypted, so the HTTP connection would not be unsafe. To build with HTTPS connection support, add `ENFORCE_EP_HTTPS=true` option.
144+
145+
For HTTPS connection support, the PEM file should also be set. The default pem file is located at `pem/cert.pem`. If the `PEM` is not set, the build system will use the default pem. The endpoint will verify the connection server with the trusted certificate from the pem file. The default pem is only for the build system. The user should provide the certificate from the server you want to connect. See pem/README.md for more information.
146+
147+
```shell
148+
$ make ENFORCE_EP_HTTPS=true PEM=/path/to/pem legato
18149
```

endpoint/BUILD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ cc_binary(
2525
"endpoint_core.h",
2626
],
2727
defines = [
28-
"TA_HOST=\"localhost\"",
29-
"TA_PORT=\"443\"",
30-
"TA_SSL_SEED=\"nonce\"",
28+
"ENDPOINT_HOST=\"localhost\"",
29+
"ENDPOINT_PORT=\"443\"",
30+
"ENDPOINT_SSL_SEED=\"nonce\"",
3131
],
3232
linkshared = True,
3333
deps = [

endpoint/endpointComp/endpoint.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
#include "endpoint.h"
1010

11-
#include "legato.h"
12-
11+
#include "common/ta_errors.h"
1312
#include "endpoint/endpoint_core.h"
13+
#include "le_test.h"
14+
#include "legato.h"
1415
#include "utils/cipher.h"
1516

1617
#define TEST_VALUE 0
@@ -102,8 +103,16 @@ COMPONENT_INIT {
102103
memcpy(iv, test_iv, AES_IV_SIZE);
103104
srand(time(NULL));
104105

106+
#ifdef ENABLE_ENDPOINT_TEST
107+
LE_TEST_INIT;
108+
LE_TEST_INFO("=== ENDPOINT TEST BEGIN ===");
109+
LE_TEST(SC_OK == send_transaction_information(value, message, message_fmt, tag, address, next_address, private_key,
110+
device_id, iv));
111+
LE_TEST_EXIT;
112+
#else
105113
while (true) {
106114
send_transaction_information(value, message, message_fmt, tag, address, next_address, private_key, device_id, iv);
107115
sleep(10);
108116
}
117+
#endif
109118
}

endpoint/platform/simulator/build.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (C) 2019-2020 BiiLabs Co., Ltd. and Contributors
2+
# All Rights Reserved.
3+
# This is free software; you can redistribute it and/or modify it under the
4+
# terms of the MIT license. A copy of the license can be found in the file
5+
# "LICENSE" at the root of this distribution.
6+
7+
platform-build-command = \
8+
cd endpoint && mkapp -v -t localhost -C -DENABLE_ENDPOINT_TEST $(ENDPOINT_CFLAGS) endpoint.adef;

endpoint/platform/wp77xx/build.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (C) 2019-2020 BiiLabs Co., Ltd. and Contributors
2+
# All Rights Reserved.
3+
# This is free software; you can redistribute it and/or modify it under the
4+
# terms of the MIT license. A copy of the license can be found in the file
5+
# "LICENSE" at the root of this distribution.
6+
7+
platform-build-command = \
8+
cd endpoint && leaf shell -c "mkapp -v -t wp77xx $(ENDPOINT_CFLAGS) endpoint.adef"

hooks/formatter

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/bash
22

3-
for file in $(find $(git rev-parse --show-toplevel) | grep -E "\.(c|cc|cpp|h|hh|hpp|m|mm)\$" | grep -Ev "/third_party/")
3+
for file in $(find $(git rev-parse --show-toplevel) | egrep "\.(c|cc|cpp|h|hh|hpp|m|mm)\$" | egrep -v "third_party|output_base");
44
do
55
clang-format -style=file -fallback-style=none -i $file
66
done
77

8-
for file in $(find $(git rev-parse --show-toplevel) | grep -E "\BUILD\$" | grep -Ev "/third_party/")
8+
for file in $(find $(git rev-parse --show-toplevel) | egrep "\BUILD\$" | egrep -v "third_party|output_base" )
99
do
1010
buildifier $file
1111
done

0 commit comments

Comments
 (0)