Skip to content

Commit

Permalink
Release v2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Sep 3, 2024
2 parents b8dab41 + e949c3e commit ba80c07
Show file tree
Hide file tree
Showing 16 changed files with 368 additions and 57 deletions.
122 changes: 121 additions & 1 deletion .github/workflows/actions_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Github Actions Build
on: [push]

env:
COMMS_TAG: v5.2.5
COMMS_TAG: v5.2.6
CC_MQTTSN_TAG: v2.8.1
CC_MQTT311_TAG: v2.8

Expand Down Expand Up @@ -67,6 +67,66 @@ jobs:
working-directory: ${{runner.workspace}}/build
shell: bash
run: ctest -V

build_gcc_ubuntu_24_04:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
type: [Debug, Release, MinSizeRel]
cc_ver: [13, 14]
cpp: [17, 20]

steps:
- uses: actions/checkout@v4

- name: Prepare Install
run: sudo apt-get update --fix-missing

- name: Install Packages
run: sudo apt install qtbase5-dev libboost-all-dev gcc-${{matrix.cc_ver}} g++-${{matrix.cc_ver}}

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Prepare externals
shell: bash
run: $GITHUB_WORKSPACE/script/prepare_externals.sh
env:
BUILD_DIR: ${{runner.workspace}}/build
CC: gcc-${{matrix.cc_ver}}
CXX: g++-${{matrix.cc_ver}}
EXTERNALS_DIR: ${{runner.workspace}}/externals
COMMON_INSTALL_DIR: ${{runner.workspace}}/build/install
COMMON_BUILD_TYPE: ${{matrix.type}}
COMMON_CXX_STANDARD: ${{matrix.cpp}}
COMMS_TAG: ${{env.COMMS_TAG}}
CC_MQTTSN_TAG: ${{env.CC_MQTTSN_TAG}}
CC_MQTT311_TAG: ${{env.CC_MQTT311_TAG}}

- name: Configure CMake
shell: bash
working-directory: ${{runner.workspace}}/build
run: |
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{matrix.type}} -DCMAKE_CXX_STANDARD=${{matrix.cpp}} \
-DCMAKE_INSTALL_PREFIX=install -DCMAKE_PREFIX_PATH=${{runner.workspace}}/build/install \
-DCC_MQTTSN_BUILD_UNIT_TESTS=ON -DCC_MQTTSN_WITH_SANITIZERS=ON \
-DCC_MQTTSN_CUSTOM_CLIENT_CONFIG_FILES="$GITHUB_WORKSPACE/client/lib/script/BareMetalTestConfig.cmake;$GITHUB_WORKSPACE/client/lib/script/NoGwDiscoverConfig.cmake;$GITHUB_WORKSPACE/client/lib/script/Qos1Config.cmake;$GITHUB_WORKSPACE/client/lib/script/Qos0Config.cmake"
env:
CC: gcc-${{matrix.cc_ver}}
CXX: g++-${{matrix.cc_ver}}

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --config ${{matrix.type}} --target install
env:
VERBOSE: 1

- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
run: ctest -V

build_clang_ubuntu_22_04:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -137,6 +197,66 @@ jobs:
working-directory: ${{runner.workspace}}/build
shell: bash
run: ctest -V

build_clang_ubuntu_24_04:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
type: [Debug, Release, MinSizeRel]
cc_ver: [16, 17, 18]
cpp: [17, 20]

steps:
- uses: actions/checkout@v4

- name: Prepare Install
run: sudo apt-get update --fix-missing

- name: Install Packages
run: sudo apt install qtbase5-dev libboost-all-dev clang-${{matrix.cc_ver}}

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Prepare externals
shell: bash
run: $GITHUB_WORKSPACE/script/prepare_externals.sh
env:
BUILD_DIR: ${{runner.workspace}}/build
CC: clang-${{matrix.cc_ver}}
CXX: clang++-${{matrix.cc_ver}}
EXTERNALS_DIR: ${{runner.workspace}}/externals
COMMON_INSTALL_DIR: ${{runner.workspace}}/build/install
COMMON_BUILD_TYPE: ${{matrix.type}}
COMMON_CXX_STANDARD: ${{matrix.cpp}}
COMMS_TAG: ${{env.COMMS_TAG}}
CC_MQTTSN_TAG: ${{env.CC_MQTTSN_TAG}}
CC_MQTT311_TAG: ${{env.CC_MQTT311_TAG}}

- name: Configure CMake
shell: bash
working-directory: ${{runner.workspace}}/build
run: |
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{matrix.type}} -DCMAKE_CXX_STANDARD=${{matrix.cpp}} \
-DCMAKE_INSTALL_PREFIX=install -DCMAKE_PREFIX_PATH=${{runner.workspace}}/build/install \
-DCC_MQTTSN_BUILD_UNIT_TESTS=ON -DCC_MQTTSN_WITH_SANITIZERS=ON \
-DCC_MQTTSN_CUSTOM_CLIENT_CONFIG_FILES="$GITHUB_WORKSPACE/client/lib/script/BareMetalTestConfig.cmake;$GITHUB_WORKSPACE/client/lib/script/NoGwDiscoverConfig.cmake;$GITHUB_WORKSPACE/client/lib/script/Qos1Config.cmake;$GITHUB_WORKSPACE/client/lib/script/Qos0Config.cmake"
env:
CC: clang-${{matrix.cc_ver}}
CXX: clang++-${{matrix.cc_ver}}

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --config ${{matrix.type}} --target install
env:
VERBOSE: 1

- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
run: ctest -V

build_msvc_2019:
runs-on: windows-2019
Expand Down
56 changes: 54 additions & 2 deletions client/app/common/AppClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ namespace cc_mqttsn_client_app
namespace
{

const std::uint8_t FwdEncMsgType = 0xfe;

enum FwdEncOffset : unsigned
{
FwdEncOffset_Length = 0,
FwdEncOffset_MsgType = 1U,
FwdEncOffset_Ctrl = 2U,
FwdEncOffset_NodeId = 3U,
};

AppClient* asThis(void* data)
{
return reinterpret_cast<AppClient*>(data);
Expand Down Expand Up @@ -92,6 +102,16 @@ bool AppClient::start(int argc, const char* argv[])
return true;
}

auto fwdEncNodeId = parseBinaryData(m_opts.fwdEncNodeId());
if (!fwdEncNodeId.empty()) {
auto prefixLen = FwdEncOffset_NodeId + fwdEncNodeId.size();
m_fwdEncPrefix.resize(prefixLen);
m_fwdEncPrefix[FwdEncOffset_Length] = static_cast<std::uint8_t>(prefixLen);
m_fwdEncPrefix[FwdEncOffset_MsgType] = FwdEncMsgType;
m_fwdEncPrefix[FwdEncOffset_Ctrl] = 0U;
std::copy(fwdEncNodeId.begin(), fwdEncNodeId.end(), &m_fwdEncPrefix[FwdEncOffset_NodeId]);
}

if (!createSession()) {
return false;
}
Expand Down Expand Up @@ -445,7 +465,16 @@ unsigned AppClient::cancelNextTickWaitInternal()
void AppClient::sendDataInternal(const unsigned char* buf, unsigned bufLen, unsigned broadcastRadius)
{
assert(m_session);
m_session->sendData(buf, bufLen, broadcastRadius);
if (m_fwdEncPrefix.empty()) {
m_session->sendData(buf, bufLen, broadcastRadius);
return;
}

std::vector<std::uint8_t> encData;
encData.reserve(m_fwdEncPrefix.size() + bufLen);
encData.insert(encData.end(), m_fwdEncPrefix.begin(), m_fwdEncPrefix.end());
encData.insert(encData.end(), buf, buf + bufLen);
m_session->sendData(encData.data(), encData.size(), broadcastRadius);
}

bool AppClient::createSession()
Expand All @@ -461,7 +490,30 @@ bool AppClient::createSession()
{
assert(m_client);
m_lastAddr = addr;
::cc_mqttsn_client_process_data(m_client.get(), buf, static_cast<unsigned>(bufLen), origin);

if (m_fwdEncPrefix.empty()) {
::cc_mqttsn_client_process_data(m_client.get(), buf, static_cast<unsigned>(bufLen), origin);
return;
}

do {
if (bufLen <= m_fwdEncPrefix.size()) {
break;
}

if (!std::equal(m_fwdEncPrefix.begin(), m_fwdEncPrefix.begin() + FwdEncOffset_Ctrl, buf)) {
break;
}

if (!std::equal(m_fwdEncPrefix.begin() + FwdEncOffset_NodeId, m_fwdEncPrefix.end(), &buf[FwdEncOffset_NodeId])) {
break;
}

::cc_mqttsn_client_process_data(m_client.get(), buf + m_fwdEncPrefix.size(), static_cast<unsigned>(bufLen - m_fwdEncPrefix.size()), origin);
return;
} while (false);

logError() << "Recieved data doesn't have appropriate forwarding encapsulation prefix, ignoring..." << std::endl;
});

m_session->setNetworkErrorReportCb(
Expand Down
1 change: 1 addition & 0 deletions client/app/common/AppClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class AppClient
ProgramOptions m_opts;
ClientPtr m_client;
SessionPtr m_session;
std::vector<std::uint8_t> m_fwdEncPrefix;
Addr m_lastAddr;
};

Expand Down
15 changes: 15 additions & 0 deletions client/app/common/ProgramOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ void ProgramOptions::addWill()
m_desc.add(opts);
}

void ProgramOptions::addEncapsulate()
{
po::options_description opts("Forwarder Encapsulation");
opts.add_options()
("fwd-enc-node-id", po::value<std::string>()->default_value(std::string()), "Emulate forwarder encapsulation with specified node ID (passed as binary data). Use \"\\x\" prefix before hex value of each byte")
;

m_desc.add(opts);
}

void ProgramOptions::addPublish()
{
po::options_description opts("Publish Options");
Expand Down Expand Up @@ -202,6 +212,11 @@ unsigned ProgramOptions::willQos() const
return m_vm["will-qos"].as<unsigned>();
}

std::string ProgramOptions::fwdEncNodeId() const
{
return m_vm["fwd-enc-node-id"].as<std::string>();
}

std::string ProgramOptions::pubTopic() const
{
return m_vm["pub-topic"].as<std::string>();
Expand Down
6 changes: 5 additions & 1 deletion client/app/common/ProgramOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ProgramOptions
void addDiscover();
void addConnect();
void addWill();
void addEncapsulate();
void addPublish();
void addSubscribe();

Expand Down Expand Up @@ -62,7 +63,10 @@ class ProgramOptions
// Will Options
std::string willTopic() const;
std::string willMessage() const;
unsigned willQos() const;
unsigned willQos() const;

// Forwarder Encapsulation options
std::string fwdEncNodeId() const;

// Publish Options
std::string pubTopic() const;
Expand Down
1 change: 1 addition & 0 deletions client/app/pub/Pub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Pub::Pub(boost::asio::io_context& io, int& result) :
opts().addNetwork();
opts().addConnect();
opts().addWill();
opts().addEncapsulate();
opts().addPublish();
}

Expand Down
1 change: 1 addition & 0 deletions client/app/sub/Sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Sub::Sub(boost::asio::io_context& io, int& result) :
opts().addNetwork();
opts().addConnect();
opts().addWill();
opts().addEncapsulate();
opts().addSubscribe();
}

Expand Down
2 changes: 1 addition & 1 deletion client/lib/include/cc_mqttsn_client/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" {

/// @brief Patch level of the library
/// @ingroup global
#define CC_MQTTSN_CLIENT_PATCH_VERSION 1U
#define CC_MQTTSN_CLIENT_PATCH_VERSION 2U

/// @brief Macro to create numeric version as single unsigned number
#define CC_MQTTSN_CLIENT_MAKE_VERSION(major_, minor_, patch_) \
Expand Down
4 changes: 4 additions & 0 deletions gateway/app/gateway/GatewayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ bool GatewayApp::start(int argc, const char* argv[])
session->setClientIdReportCb(
[this, sessionPtr = session.get()](const std::string& clientId)
{
if (clientId.empty()) {
return;
}

auto iter =
std::find_if(
m_sessions.begin(), m_sessions.end(),
Expand Down
Loading

0 comments on commit ba80c07

Please sign in to comment.