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

Commit

Permalink
feat(endpoint): Improve endpoint build instructions
Browse files Browse the repository at this point in the history
This commit adds the build instructions for generate 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 intend to the target to generate. The default TARGET
is the platform on your development host. Set the TARGET like
TARGET=wp77xx to generate specific platform endpoint app.

The macro ENDPOINT_TEST_ENABLE is for generate the endpoint app in test mode.
Set ENDPOINT_TEST_ENABLE=true to enable to generate test mode app
in the endpoint.

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.

The default port has been modified to passed the test on buildkite.

Close #591
  • Loading branch information
splasky committed Jun 15, 2020
1 parent 7790ea2 commit 6af9628
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 16 deletions.
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ PEM := $(PEM_DIR)/cert.pem
NAMESERVER := 8.8.8.8
RESOLV_CONF_DIR := endpoint/endpointComp
OUTPUT_BASE_DIR := output_base
# Endpoint build target, the localhost is the platform intended to your development system.
# It is the default setting defined in the legato application framework.
TARGET := localhost
ENDPOINT_TEST_ENABLE := false
HTTPS := false
DEPS += $(DCURL_LIB)

all: $(DEPS) cert
Expand Down Expand Up @@ -34,9 +39,21 @@ legato: cert
# FIXME: Use 'fetch' instead of 'build' to avoid extra building actions.
# The 'build' option is for getting the header file like 'mam/mam/mam_endpoint_t_set.h',
# which can not be downloaded when the 'fetch' option is used.
ifeq ($(HTTPS), true)
bazel --output_base=$(OUTPUT_BASE_DIR) --define https=enable build //endpoint:libendpoint.so
else
bazel --output_base=$(OUTPUT_BASE_DIR) build //endpoint:libendpoint.so
endif
# Generate endpoint Legato app
(cd endpoint && leaf shell -c "mkapp -v -t wp77xx endpoint.adef")
ifeq ($(TARGET), localhost)
(cd endpoint && mkapp -v -t localhost -C -DENDPOINT_TEST_ENABLE endpoint.adef)
else
ifeq ($(ENDPOINT_TEST_ENABLE), true)
(cd endpoint && leaf shell -c "mkapp -v -t $(TARGET) -C -DENDPOINT_TEST_ENABLE endpoint.adef")
else
(cd endpoint && leaf shell -c "mkapp -v -t $(TARGET) endpoint.adef")
endif
endif

cert: check_pem
@xxd -i $(PEM) > $(PEM_DIR)/ca_crt.inc
Expand Down
117 changes: 111 additions & 6 deletions docs/endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,119 @@ The endpoint is one of the components provided by Tangle-accelerator, running on
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.
A message sent by endpoint needs to be encrypted locally, which avoids message being peeked and modified.

# How to use
# How to build endpoint

## Setup Sierra development environment
The endpoint uses the sierra framework as based runtime system. Developers need to set up the sierra dev environment to build endpoint as specific target.

### How to build wp77xx

[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.

```
$ bazel build //endpoint:wp7702
$ bazel build //endpoint:sim
$ wget https://downloads.sierrawireless.com/tools/leaf/leaf_latest.deb -O /tmp/leaf_latest.deb && sudo apt install /tmp/leaf_latest.deb
```

## HTTPS Connection Support
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.
Create a workspace
```
mkdir -p workspace
$ cd workspace
```

Setup the wp77xx target profile
```
leaf setup legato-latest -p swi-wp77_3.3.0
```

Finally, make the wp77xx endpoint target. Be careful the tangle-accelerator directory should be located at the sub level of the workspace directory created by `leaf setup legato-latest -p swi-wp77_3.3.0`
```
$ git clone https://github.com/DLTcollab/tangle-accelerator.git
$ cd tangle-accelerator
$ make TARGET=wp77xx legato // build endpoint as wp77xx target
$ make ENDPOINT_TEST_ENABLE=true TARGET=wp77xx legato // build endpoint as wp77xx target in test mode
```

### How to build endpoint as x86 test target

Install required packages:
```
$ sudo apt-get install -y \
autoconf \
automake \
bash \
bc \
bison \
bsdiff \
build-essential \
chrpath \
cmake \
cpio \
diffstat \
flex \
gawk \
gcovr \
git \
gperf \
iputils-ping \
libbz2-dev \
libcurl4-gnutls-dev \
libncurses5-dev \
libncursesw5-dev \
libsdl-dev \
libssl-dev \
libtool \
libxml2-utils \
ninja-build \
python \
python-git \
python-jinja2 \
python-pkg-resources \
python3 \
texinfo \
unzip \
wget \
zlib1g-dev
```

Create a workspace
```
$ bazel build --define https=enable //endpoint:wp7702
mkdir -p workspace
$ cd workspace
```

Download legato by git-repo
```
$ repo init -u git://github.com/legatoproject/manifest
$ repo sync
```

You can also clone for specific version
```
$ repo init -u git://github.com/legatoproject/manifest -m legato/releases/19.07.0.xml
$ repo sync
```

Build legato as localhost target
```
$ cd legato
$ make localhost
```

Checkout the shell to legato shell
```
source ./framework/tools/scripts/configlegatoenv
```

Finally, go back to the TA project. Use GNU Make to make the endpoint project at the TA's root directory.
```
$ make legato // build endpoint as x86 target
```

The endpoint will be built at `endpoint/_build_endpoint/localhost/app/endpoint/staging/read-only/bin/endpoint`

## HTTPS Connection Support
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 `HTTPS=true` option.
```
$ make HTTPS=true legato
```
8 changes: 4 additions & 4 deletions endpoint/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cc_library(
hdrs = ["endpoint_core.h"],
defines = [
"ENDPOINT_HOST=\"localhost\"",
"ENDPOINT_PORT=\"443\"",
"ENDPOINT_PORT=\"8000\"",
"ENDPOINT_SSL_SEED=\"nonce\"",
],
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -38,9 +38,9 @@ cc_binary(
"endpoint_core.h",
],
defines = [
"TA_HOST=\"localhost\"",
"TA_PORT=\"443\"",
"TA_SSL_SEED=\"nonce\"",
"ENDPOINT_HOST=\"localhost\"",
"ENDPOINT_PORT=\"8000\"",
"ENDPOINT_SSL_SEED=\"nonce\"",
],
linkshared = True,
deps = [
Expand Down
14 changes: 11 additions & 3 deletions endpoint/endpointComp/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

#include "endpoint.h"

#include "legato.h"

#include "common/ta_errors.h"
#include "endpoint/endpoint_core.h"
#include "le_test.h"
#include "legato.h"
#include "utils/cipher.h"

#define TEST_VALUE 0
Expand Down Expand Up @@ -53,15 +54,22 @@ COMPONENT_INIT {
// The initialization of hardware and the input from hardware are not implemented yet.
le_arg_SetFlagCallback(print_help, "h", "help");
le_arg_Scan();

uint8_t iv[AES_IV_SIZE] = {0};

memcpy(iv, test_iv, AES_IV_SIZE);
srand(time(NULL));

#ifdef ENDPOINT_TEST_ENABLE
LE_TEST_INIT;
LE_TEST_INFO("=== ENDPOINT TEST BEGIN ===");
LE_TEST(SC_OK == send_transaction_information(TEST_VALUE, TEST_MESSAGE, TEST_MESSAGE_FMT, TEST_TAG, TEST_ADDRESS,
TEST_NEXT_ADDRESS, test_key, TEST_DEVICE_ID, iv));
LE_TEST_EXIT;
#else
while (true) {
send_transaction_information(TEST_VALUE, TEST_MESSAGE, TEST_MESSAGE_FMT, TEST_TAG, TEST_ADDRESS, TEST_NEXT_ADDRESS,
test_key, TEST_DEVICE_ID, iv);
sleep(10);
}
#endif
}
4 changes: 2 additions & 2 deletions hooks/formatter
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

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

for file in $(find $(git rev-parse --show-toplevel) | grep -E "\BUILD\$" | grep -Ev "/third_party/")
for file in $(find $(git rev-parse --show-toplevel) | grep -E "\BUILD\$" | grep -Ev "/third_party/" | grep -E "/output_base")
do
buildifier $file
done
Expand Down

0 comments on commit 6af9628

Please sign in to comment.