in src/TcpAdapterProxy.cpp [1105:1168]
bool tcp_adapter_proxy::handle_control_message_data_transfer(tcp_adapter_context &tac, message const &message)
{
using namespace com::amazonaws::iot::securedtunneling;
BOOST_LOG_SEV(log, trace) << "Handling control message...";
std::int32_t stream_id = static_cast<std::int32_t>(message.streamid());
string service_id = message.serviceid();
// v1 message format does not need to validate service id. Set to the one service id stored in memory.
if (tac.adapter_config.is_v1_message_format)
{
service_id = tac.adapter_config.serviceId_to_endpoint_map.cbegin()->first;
}
switch (message.type())
{
case Message_Type_SESSION_RESET:
#ifdef DEBUG
BOOST_LOG_SEV(log, trace) << "Session reset recieved";
#endif
//validation has already been done on stream_id before calling this, so we can just listen
tcp_socket_reset_all(tac, std::bind(&tcp_adapter_proxy::setup_tcp_sockets, this, std::ref(tac)));
return true; //indicates we should stop reading from the web socket after processing this message
case Message_Type_STREAM_RESET:
#ifdef DEBUG
BOOST_LOG_SEV(log, trace) << "Stream reset recieved";
#endif
//validation has already been done on stream_id before calling this, so we can just listen
tcp_socket_reset(tac, service_id, std::bind(&tcp_adapter_proxy::setup_tcp_socket, this, std::ref(tac), service_id));
return true; //indicates we should stop reading from the web socket after processing this message
case Message_Type_STREAM_START: //could verify that this is a destination mode local proxy. Source mode shouldn't receive stream start
if (!stream_id)
{
throw proxy_exception("No stream ID set for stream start message!");
}
if (tac.serviceId_to_streamId_map.find(service_id) == tac.serviceId_to_streamId_map.end())
{
BOOST_LOG_SEV(log, warning) << "Starting new stream for service id: " << service_id;
tac.serviceId_to_streamId_map[service_id] = stream_id;
tac.serviceId_to_tcp_client_map[service_id]->on_receive_stream_start();
}
else if (tac.serviceId_to_streamId_map.at(service_id) != message.streamid())
{
BOOST_LOG_SEV(log, warning) << "Stream start received during data transfer for service id :" << service_id << "with new stream id: " << message.streamid();
BOOST_LOG_SEV(log, warning) << "Reset this stream";
tcp_socket_reset(tac, service_id, std::bind(&tcp_adapter_proxy::setup_tcp_socket, this, std::ref(tac), service_id));
}
return true;
case Message_Type_SERVICE_IDS:
// service ids should be received and validate before any stream can start. Ignore this control message if receive after stream already start.
BOOST_LOG_SEV(log, info) << "Receive service Ids during data transfer. ignore";
return true;
case Message_Type_DATA: //handling the following cases alleviates clang compiler warnings
throw std::logic_error("Data message recieved in control message handler");
case Message_Type_UNKNOWN:
case Message_Type_Message_Type_INT_MIN_SENTINEL_DO_NOT_USE_:
case Message_Type_Message_Type_INT_MAX_SENTINEL_DO_NOT_USE_:
//message-lite in C++ (gcc) generates a far far smaller executable. Likely a gcc issue since msvc generates reasonably sized executable either way
//throw proxy_exception((boost::format("Unexpected message type recieved during control message handling during data transfer: %1%") % External_MessageType_Name(message.messagetype())).str());
throw proxy_exception((boost::format("Unexpected message type recieved during control message handling during data transfer: %1%") % message.type()).str());
default:
if (message.ignorable()) {
return true;
}
throw std::logic_error((boost::format("Unrecognized message type recieved during control message handling during data transfer: %1%") % message.type()).str());
}
}