Skip to content

Commit

Permalink
Gateway discovery fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Jun 3, 2024
1 parent ef1022d commit e6f3c2d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
1 change: 0 additions & 1 deletion client/app/common/UdpSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "UdpSession.h"

#include <cassert>
#include <iostream> // TODO: remove

namespace cc_mqttsn_client_app
{
Expand Down
4 changes: 4 additions & 0 deletions client/app/gw_discover/GwDiscover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ void GwDiscover::gwStatusReportInternal(CC_MqttsnGwStatus status, const CC_Mqtts

std::cout << prefixSuffixInfo.first << ' ' << static_cast<unsigned>(infoTmp.m_gwId) <<
": " << addrToString(infoTmp) << prefixSuffixInfo.second << std::endl;

if (opts().discoverExitOnFirst()) {
doTerminate(0);
}
}

void GwDiscover::searchCompleteInternal(CC_MqttsnAsyncOpStatus status, [[maybe_unused]] const CC_MqttsnGatewayInfo* info)
Expand Down
10 changes: 6 additions & 4 deletions client/lib/src/ClientImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ void ClientImpl::handle(AdvertiseMsg& msg)
monitorGatewayExpiry();
});

// TODO: when advertise arrives before GWINFO and the search is present,
// report search completion

auto iter =
std::find_if(
m_clientState.m_gwInfos.begin(), m_clientState.m_gwInfos.end(),
Expand Down Expand Up @@ -584,14 +587,16 @@ void ClientImpl::handle(GwinfoMsg& msg)

m_clientState.m_gwInfos.resize(m_clientState.m_gwInfos.size() + 1U);
auto& info = m_clientState.m_gwInfos.back();
info.m_expiryTimestamp = m_clientState.m_timestamp + m_configState.m_gwAdvTimeoutMs + m_configState.m_retryPeriod;
info.m_duration = m_configState.m_gwAdvTimeoutMs;

info.m_gwId = msg.field_gwId().value();
info.m_allowedAdvLosses = m_configState.m_allowedAdvLosses;
gwInfo = &info;

auto& addr = msg.field_gwAdd().value();
if (addr.empty()) {
gwStatus = CC_MqttsnGwStatus_Alive;
gwStatus = CC_MqttsnGwStatus_AddedByGateway;
return; // Report gateway status on exit
}

Expand All @@ -601,10 +606,7 @@ void ClientImpl::handle(GwinfoMsg& msg)
return;
}


info.m_addr.assign(addr.begin(), addr.end());
info.m_expiryTimestamp = m_clientState.m_timestamp + m_configState.m_gwAdvTimeoutMs + m_configState.m_retryCount;
info.m_duration = m_configState.m_gwAdvTimeoutMs;
monitorGatewayExpiry();

gwStatus = CC_MqttsnGwStatus_AddedByClient;
Expand Down
2 changes: 0 additions & 2 deletions client/lib/src/op/SearchOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ void SearchOp::handle(GwinfoMsg& msg)
comms::cast_assign(info.m_addrLen) = addr.size();
}

// TODO: store gateway info

completeOpInternal(CC_MqttsnAsyncOpStatus_Complete, &info);
}

Expand Down
2 changes: 1 addition & 1 deletion client/lib/templ/client.cpp.templ
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ CC_MqttsnErrorCode cc_mqttsn_##NAME##client_set_available_gateway_info(CC_Mqttsn
gwInfos.begin(), gwInfos.end(),
[info](auto& storedInfo)
{
return storedInfo.m_gwId = info->m_gwId;
return storedInfo.m_gwId == info->m_gwId;
});

auto updateFunc =
Expand Down
1 change: 1 addition & 0 deletions gateway/app/gateway/GatewayIoClientSocket_Udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ bool GatewayIoClientSocket_Udp::startImpl()
boost::asio::post(io(),
[this]()
{
m_started = true;
reportPendingData();
});

Expand Down

0 comments on commit e6f3c2d

Please sign in to comment.