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

Commit

Permalink
Merge pull request #129 from DLTcollab/develop
Browse files Browse the repository at this point in the history
Pre-release v0.4.0
  • Loading branch information
jserv authored Mar 30, 2019
2 parents ca28a76 + 18dabe8 commit 59c8f48
Show file tree
Hide file tree
Showing 29 changed files with 591 additions and 318 deletions.
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
test --copt='-ggdb3'
coverage -s
coverage --experimental_cc_coverage
coverage --combined_report=lcov
coverage --coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main
coverage --instrumentation_filter="-/tests[/:]"

# Address Sanitizer:--config asan
build:asan --strip=never
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (C) 2018-2019 BiiLabs, Co. Ltd. and Contributors
Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors
All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ all: $(DEPS)

$(DCURL_LIB): $(DCURL_DIR)
git submodule update --init $^
git submodule update --remote $^
$(MAKE) -C $^ config
@echo
$(info Modify $^/build/local.mk for your environments.)
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Tangle-accelerator

[![Build Status](https://badge.buildkite.com/46ec07b122bde13f984c241fe8b38e64698c5c0d816ee6c7e4.svg)](https://buildkite.com/dltcollab/dcurl-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)

`Tangle-accelerator` is a caching proxy server for [IOTA](https://www.iota.org/), which
can cache API requests and rewrite their responses as needed to be routed through full
nodes. Thus, one instance of `Tangle-accelerator` can serve thousands of Tangle requests
Expand Down Expand Up @@ -69,6 +71,20 @@ Before running tangle-accelerator, please edit binding address/port of accelerat
$ make && bazel run //accelerator
```

### Build from docker

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

```
$ make && bazel run //accelerator:ta_image
```

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.

```
$ docker run -d --net=host --name tangle-accelerator wusyong/tangel-accelerator:latest
```

## Developing

The codebase of this repository follows [Google's C++ guidelines](https://google.github.io/styleguide/cppguide.html):
Expand Down
13 changes: 11 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_r

git_repository(
name = "rules_iota",
commit = "b15744b9ea520717752c866d5afc769c3b6b68f3",
commit = "1cb59eea62fd1d071de213a9aa46e61e8273472d",
remote = "https://github.com/iotaledger/rules_iota.git",
)

git_repository(
name = "entangled",
commit = "8d847ffcecd50f8f3760bfee07d7ed33ecc067bf",
commit = "4960865730640d23e75ffbce84d3f74264cfcd28",
remote = "https://github.com/iotaledger/entangled.git",
)

Expand All @@ -18,6 +18,15 @@ git_repository(
remote = "https://github.com/meltwater/served.git",
)

git_repository(
name = "io_bazel_rules_docker",
remote = "https://github.com/bazelbuild/rules_docker.git",
tag = "v0.6.0",
)

load("@rules_iota//:defs.bzl", "iota_deps")
load("@io_bazel_rules_docker//cc:image.bzl", _cc_image_repos = "repositories")

iota_deps()

_cc_image_repos()
19 changes: 15 additions & 4 deletions accelerator/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package(default_visibility = ["//visibility:public"])

load("@io_bazel_rules_docker//cc:image.bzl", "cc_image")

cc_binary(
name = "accelerator",
srcs = ["server.cc"],
Expand All @@ -11,6 +13,11 @@ cc_binary(
],
)

cc_image(
name = "ta_image",
binary = ":accelerator",
)

cc_library(
name = "apis",
srcs = ["apis.c"],
Expand All @@ -36,20 +43,24 @@ cc_library(
":ta_errors",
"//request",
"//response",
"//utils:cache",
"//utils:pow",
"@com_github_uthash//:uthash",
"@entangled//cclient/api",
"@entangled//cclient/types",
"@entangled//common/model:bundle",
"@entangled//utils:time",
],
)

cc_library(
name = "ta_config",
srcs = ["config.c"],
hdrs = ["config.h"],
visibility = ["//visibility:public"],
deps = [
":ta_errors",
"//utils:cache",
"//utils:pow",
"@entangled//cclient/api",
"@entangled//cclient/types",
],
)

cc_library(
Expand Down
71 changes: 47 additions & 24 deletions accelerator/apis.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ status_t api_get_tips(const iota_client_service_t* const service,
return ret;
}

status_t api_get_tips_pair(const iota_client_service_t* const service,
status_t api_get_tips_pair(const iota_config_t* const tangle,
const iota_client_service_t* const service,
char** json_result) {
status_t ret = SC_OK;
ta_get_tips_res_t* res = ta_get_tips_res_new();
Expand All @@ -53,7 +54,7 @@ status_t api_get_tips_pair(const iota_client_service_t* const service,
goto done;
}

ret = cclient_get_txn_to_approve(service, res);
ret = cclient_get_txn_to_approve(service, tangle->depth, res);
if (ret) {
goto done;
}
Expand All @@ -65,7 +66,8 @@ status_t api_get_tips_pair(const iota_client_service_t* const service,
return ret;
}

status_t api_generate_address(const iota_client_service_t* const service,
status_t api_generate_address(const iota_config_t* const tangle,
const iota_client_service_t* const service,
char** json_result) {
status_t ret = SC_OK;
ta_generate_address_res_t* res = ta_generate_address_res_new();
Expand All @@ -74,7 +76,7 @@ status_t api_generate_address(const iota_client_service_t* const service,
goto done;
}

ret = ta_generate_address(service, res);
ret = ta_generate_address(tangle, service, res);
if (ret) {
goto done;
}
Expand Down Expand Up @@ -152,54 +154,75 @@ status_t api_find_transactions_obj_by_tag(
}

status_t api_receive_mam_message(const iota_client_service_t* const service,
const char* const obj, char** json_result) {
status_t ret = SC_OK;
const char* const bundle_hash,
char** json_result) {
mam_api_t mam;

status_t ret = SC_OK;
tryte_t* payload_trytes = NULL;
tryte_t* none_chid_trytes = NULL;
char* payload = NULL;
size_t payload_size = 0;
bundle_transactions_t* bundle = NULL;
bundle_transactions_new(&bundle);
bool is_last_packet;

// Creating MAM API
if (mam_api_init(&mam, (tryte_t*)SEED)) {
ret = SC_MAM_OOM;
if (mam_api_init(&mam, (tryte_t*)SEED) != RC_OK) {
ret = SC_MAM_FAILED_INIT;
goto done;
}

// Get bundle which is find_transactions_by_bundle
ret = ta_get_bundle(service, (tryte_t*)obj, bundle);
if (ret) {
ret = ta_get_bundle(service, (tryte_t*)bundle_hash, bundle);
if (ret != SC_OK) {
goto done;
}

// Read MAM message from bundle
// Set first transaction's address as chid, if no `chid` specified
mam_psk_t_set_add(&mam.psks, &psk);
iota_transaction_t* curr_tx = (iota_transaction_t*)utarray_eltptr(bundle, 0);
none_chid_trytes = (tryte_t*)malloc(sizeof(tryte_t) * NUM_TRYTES_ADDRESS);
flex_trits_to_trytes(none_chid_trytes, NUM_TRYTES_ADDRESS,
transaction_address(curr_tx), NUM_TRITS_ADDRESS,
NUM_TRITS_ADDRESS);
mam_api_add_trusted_channel_pk(&mam, none_chid_trytes);

if (mam_api_bundle_read(&mam, bundle, &payload_trytes, &payload_size,
&is_last_packet) == RC_OK) {
if (payload_trytes == NULL || payload_size == 0) {
ret = SC_MAM_NULL;
ret = SC_MAM_NO_PAYLOAD;
goto done;
} else {
char* payload = calloc(payload_size * 2 + 1, sizeof(char));

payload = calloc(payload_size * 2 + 1, sizeof(char));
if (payload == NULL) {
ret = SC_TA_NULL;
goto done;
}
trytes_to_ascii(payload_trytes, payload_size, payload);
*json_result = payload;

payload = NULL;
free(payload_trytes);
}
} else {
ret = SC_MAM_FAILED_RESPONSE;
ret = SC_MAM_NOT_FOUND;
goto done;
}

ret = receive_mam_message_serialize(json_result, &payload);

done:
mam_api_destroy(&mam);
// Destroying MAM API
if (ret != SC_MAM_FAILED_INIT) {
if (mam_api_destroy(&mam) != RC_OK) {
ret = SC_MAM_FAILED_DESTROYED;
}
}
free(none_chid_trytes);
free(payload_trytes);
free(payload);
bundle_transactions_free(&bundle);

return ret;
}

status_t api_send_transfer(const iota_client_service_t* const service,
status_t api_send_transfer(const iota_config_t* const tangle,
const iota_client_service_t* const service,
const char* const obj, char** json_result) {
status_t ret = SC_OK;
char hash_trytes[NUM_TRYTES_HASH + 1];
Expand All @@ -218,7 +241,7 @@ status_t api_send_transfer(const iota_client_service_t* const service,
goto done;
}

ret = ta_send_transfer(service, req, res);
ret = ta_send_transfer(tangle, service, req, res);
if (ret) {
goto done;
}
Expand Down
18 changes: 13 additions & 5 deletions accelerator/apis.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "common/trinary/trit_tryte.h"
#include "common/trinary/tryte_ascii.h"
#include "mam/api/api.h"
#include "mam/mam/mam_channel_t_set.h"
#include "serializer/serializer.h"

#ifdef __cplusplus
Expand All @@ -28,14 +29,16 @@ extern "C" {
* Generate and return an unused address from the seed. An unused address means
* the address does not have any transaction with it yet.
*
* @param[in] tangle IOTA API parameter configurations
* @param[in] service IRI node end point service
* @param[out] json_result Result containing an unused address in json format
*
* @return
* - SC_OK on success
* - non-zero on error
*/
status_t api_generate_address(const iota_client_service_t* const service,
status_t api_generate_address(const iota_config_t* const tangle,
const iota_client_service_t* const service,
char** json_result);

/**
Expand All @@ -44,14 +47,16 @@ status_t api_generate_address(const iota_client_service_t* const service,
* Get a tips pair as trunk/branch transactions for transaction construction.
* The result is char array in json format:
*
* @param[in] tangle IOTA API parameter configurations
* @param[in] service IRI node end point service
* @param[out] json_result Result containing a tips pair in json format
*
* @return
* - SC_OK on success
* - non-zero on error
*/
status_t api_get_tips_pair(const iota_client_service_t* const service,
status_t api_get_tips_pair(const iota_config_t* const tangle,
const iota_client_service_t* const service,
char** json_result);

/**
Expand All @@ -76,15 +81,16 @@ status_t api_get_tips(const iota_client_service_t* const service,
* Receive a MAM message from given bundle hash.
*
* @param[in] service IRI node end point service
* @param[out] obj bundle hash in trytes
* @param[in] bundle_hash bundle hash decoded in trytes string
* @param[out] json_result Result containing an unused address in json format
*
* @return
* - SC_OK on success
* - non-zero on error
*/
status_t api_receive_mam_message(const iota_client_service_t* const service,
const char* const obj, char** json_result);
const char* const bundle_hash,
char** json_result);

/**
* @brief Send transfer to tangle.
Expand All @@ -93,6 +99,7 @@ status_t api_receive_mam_message(const iota_client_service_t* const service,
* fields include address, value, tag, and message. This API would also try to
* find the transactions after bundle sent.
*
* @param[in] tangle IOTA API parameter configurations
* @param[in] service IRI node end point service
* @param[in] obj Input data in JSON
* @param[out] json_result Result containing transaction objects in json format
Expand All @@ -101,7 +108,8 @@ status_t api_receive_mam_message(const iota_client_service_t* const service,
* - SC_OK on success
* - non-zero on error
*/
status_t api_send_transfer(const iota_client_service_t* const service,
status_t api_send_transfer(const iota_config_t* const tangle,
const iota_client_service_t* const service,
const char* const obj, char** json_result);

/**
Expand Down
Loading

0 comments on commit 59c8f48

Please sign in to comment.