@@ -253,8 +253,12 @@ namespace aws { namespace iot { namespace securedtunneling {
253
253
{
254
254
if (tac.serviceId_to_tcp_server_map .find (service_id) == tac.serviceId_to_tcp_server_map .end ())
255
255
{
256
- BOOST_LOG_SEV (log , debug) << " No serviceId_to_tcp_server mapping for service_id: " << service_id;
257
- return connection_ptr;
256
+ if (tac.serviceId_to_tcp_server_map .find (tac.adapter_config .serviceId_to_endpoint_map .cbegin ()->first ) == tac.serviceId_to_tcp_server_map .end ())
257
+ {
258
+ BOOST_LOG_SEV (log , debug) << " No serviceId_to_tcp_server mapping for service_id: " << service_id;
259
+ return connection_ptr;
260
+ }
261
+ service_id = tac.adapter_config .serviceId_to_endpoint_map .cbegin ()->first ;;
258
262
}
259
263
tcp_server::pointer server = tac.serviceId_to_tcp_server_map [service_id];
260
264
BOOST_LOG_SEV (log , trace) << " num active connections for service id " << service_id << " : " << server->connectionId_to_tcp_connection_map .size ();
@@ -376,6 +380,7 @@ namespace aws { namespace iot { namespace securedtunneling {
376
380
BOOST_LOG_SEV (this ->log , trace) << " Post-reset TCP drain complete. Closing TCP socket for service id " << service_id << " connection id " << connection_id;
377
381
BOOST_LOG_SEV (this ->log , info) << " Disconnected from: " << connection_to_reset->socket ().remote_endpoint ();
378
382
connection_to_reset->socket_ .close ();
383
+ delete_tcp_socket (tac, service_id, connection_id);
379
384
*tcp_write_buffer_drain_complete = true ;
380
385
if (*web_socket_write_buffer_drain_complete)
381
386
{
@@ -515,8 +520,9 @@ namespace aws { namespace iot { namespace securedtunneling {
515
520
tcp_connection::pointer socket_connection = get_tcp_connection (tac, service_id, connection_id);
516
521
517
522
// if simultaneous connections are not enabled, then send a stream reset
518
- if (tac.adapter_config .is_v2_message_format )
523
+ if (tac.adapter_config .is_v2_message_format || tac. adapter_config . is_v1_message_format )
519
524
{
525
+ BOOST_LOG_SEV (log , info) << " simultaneous connections are not enabled, sending stream reset" ;
520
526
socket_connection->after_send_message = std::bind (&tcp_adapter_proxy::setup_tcp_socket, this , std::ref (tac), service_id);
521
527
tac.serviceId_to_control_message_handler_map [service_id] = std::bind (&tcp_adapter_proxy::ignore_message_and_stop, this , std::ref (tac), std::placeholders::_1);
522
528
async_send_stream_reset (tac, service_id, connection_id);
@@ -600,8 +606,16 @@ namespace aws { namespace iot { namespace securedtunneling {
600
606
601
607
BOOST_LOG_SEV (log , debug) << " Sending stream start, setting new stream ID to: " << new_stream_id << " , service id: " << service_id;
602
608
609
+ if (tac.adapter_config .is_v1_message_format )
610
+ {
611
+ outgoing_message.set_serviceid (" " );
612
+ }
613
+ else
614
+ {
615
+ outgoing_message.set_serviceid (service_id);
616
+ }
617
+
603
618
outgoing_message.set_type (Message_Type_STREAM_START);
604
- outgoing_message.set_serviceid (service_id);
605
619
outgoing_message.set_streamid (new_stream_id);
606
620
outgoing_message.set_connectionid (connection_id);
607
621
outgoing_message.set_ignorable (false );
@@ -638,8 +652,16 @@ namespace aws { namespace iot { namespace securedtunneling {
638
652
}
639
653
std::int32_t stream_id = tac.serviceId_to_streamId_map [service_id];
640
654
655
+ if (tac.adapter_config .is_v1_message_format )
656
+ {
657
+ outgoing_message.set_serviceid (" " );
658
+ }
659
+ else
660
+ {
661
+ outgoing_message.set_serviceid (service_id);
662
+ }
663
+
641
664
outgoing_message.set_type (Message_Type_CONNECTION_START);
642
- outgoing_message.set_serviceid (service_id);
643
665
outgoing_message.set_streamid (stream_id);
644
666
outgoing_message.set_connectionid (connection_id);
645
667
outgoing_message.set_ignorable (false );
@@ -657,12 +679,20 @@ namespace aws { namespace iot { namespace securedtunneling {
657
679
return ;
658
680
}
659
681
682
+ if (tac.adapter_config .is_v1_message_format )
683
+ {
684
+ outgoing_message.set_serviceid (" " );
685
+ }
686
+ else
687
+ {
688
+ outgoing_message.set_serviceid (service_id);
689
+ }
690
+
660
691
// NOTE: serviceIds -> streamId mapping will be updated when send/receive stream start, no action needed now.
661
692
std::int32_t stream_id = tac.serviceId_to_streamId_map [service_id];
662
693
outgoing_message.set_type (Message_Type_STREAM_RESET);
663
- outgoing_message.set_serviceid (service_id);
664
694
outgoing_message.set_streamid (stream_id);
665
- outgoing_message.set_connectionid (0 );
695
+ outgoing_message.set_connectionid (connection_id );
666
696
outgoing_message.set_ignorable (false );
667
697
outgoing_message.clear_payload ();
668
698
async_send_message (tac, outgoing_message, service_id, connection_id);
@@ -677,10 +707,19 @@ namespace aws { namespace iot { namespace securedtunneling {
677
707
BOOST_LOG_SEV (log , warning) << " No stream id mapping found for service id " << service_id << " . Skip connection reset." ;
678
708
return ;
679
709
}
710
+
711
+ if (tac.adapter_config .is_v1_message_format )
712
+ {
713
+ outgoing_message.set_serviceid (" " );
714
+ }
715
+ else
716
+ {
717
+ outgoing_message.set_serviceid (service_id);
718
+ }
719
+
680
720
// NOTE: serviceIds -> streamId mapping will be updated when send/receive stream start, no action needed now.
681
721
std::int32_t stream_id = tac.serviceId_to_streamId_map [service_id];
682
722
outgoing_message.set_type (Message_Type_CONNECTION_RESET);
683
- outgoing_message.set_serviceid (service_id);
684
723
outgoing_message.set_streamid (stream_id);
685
724
outgoing_message.set_connectionid (connection_id);
686
725
outgoing_message.set_ignorable (false );
@@ -1073,7 +1112,7 @@ namespace aws { namespace iot { namespace securedtunneling {
1073
1112
// backward compatibility: set connection id to 1 if first received a message with no connection id (id value will be 0)
1074
1113
if (!connection_id)
1075
1114
{
1076
- connection_id = 1 ;
1115
+ BOOST_LOG_SEV ( log , info) << " reverting to v2 message format " ;
1077
1116
tac.adapter_config .is_v2_message_format = true ;
1078
1117
}
1079
1118
string service_id = message.serviceid ();
@@ -1305,6 +1344,7 @@ namespace aws { namespace iot { namespace securedtunneling {
1305
1344
// Remove empty string map and put new mapping
1306
1345
tac.adapter_config .serviceId_to_endpoint_map .erase (" " );
1307
1346
tac.adapter_config .serviceId_to_endpoint_map [service_id] = endpoint;
1347
+
1308
1348
BOOST_LOG_SEV (log , info) << " Updated port mapping for v1 format: " ;
1309
1349
for (auto m : tac.adapter_config .serviceId_to_endpoint_map )
1310
1350
{
@@ -1328,7 +1368,7 @@ namespace aws { namespace iot { namespace securedtunneling {
1328
1368
// backward compatibility: set connection id to 1 if first received a message with no connection id (id value will be 0)
1329
1369
if (!connection_id)
1330
1370
{
1331
- connection_id = 1 ;
1371
+ BOOST_LOG_SEV ( log , info) << " reverting to v2 message format " ;
1332
1372
tac.adapter_config .is_v2_message_format = true ;
1333
1373
}
1334
1374
string service_id = message.serviceid ();
@@ -1431,7 +1471,7 @@ namespace aws { namespace iot { namespace securedtunneling {
1431
1471
// backward compatibility: set connection id to 1 if first received a message with no connection id (id value will be 0)
1432
1472
if (!connection_id)
1433
1473
{
1434
- connection_id = 1 ;
1474
+ BOOST_LOG_SEV ( log , info) << " reverting to v2 message format " ;
1435
1475
tac.adapter_config .is_v2_message_format = true ;
1436
1476
}
1437
1477
/* *
@@ -1562,7 +1602,7 @@ namespace aws { namespace iot { namespace securedtunneling {
1562
1602
// backward compatibility: set connection id to 1 if first received a message with no connection id (id value will be 0)
1563
1603
if (!connection_id)
1564
1604
{
1565
- connection_id = 1 ;
1605
+ BOOST_LOG_SEV ( log , info) << " reverting to v2 message format " ;
1566
1606
tac.adapter_config .is_v2_message_format = true ;
1567
1607
}
1568
1608
tcp_connection::pointer connection = get_tcp_connection (tac, service_id, connection_id);
@@ -1762,8 +1802,17 @@ namespace aws { namespace iot { namespace securedtunneling {
1762
1802
throw proxy_exception ((boost::format (" No streamId exists for the service Id %1%" ) % service_id).str ());
1763
1803
}
1764
1804
BOOST_LOG_SEV (log , debug) << " Prepare to send data message: service id: " << service_id << " stream id: " << tac.serviceId_to_streamId_map [service_id] << " connection id: " << connection_id;
1805
+
1806
+ if (tac.adapter_config .is_v1_message_format )
1807
+ {
1808
+ outgoing_message.set_serviceid (" " );
1809
+ }
1810
+ else
1811
+ {
1812
+ outgoing_message.set_serviceid (service_id);
1813
+ }
1814
+
1765
1815
// Construct outgoing message
1766
- outgoing_message.set_serviceid (service_id);
1767
1816
outgoing_message.set_streamid (tac.serviceId_to_streamId_map [service_id]);
1768
1817
outgoing_message.set_connectionid (connection_id);
1769
1818
size_t const send_size = std::min<std::size_t >(GET_SETTING (settings, MESSAGE_MAX_PAYLOAD_SIZE),
@@ -1988,9 +2037,10 @@ namespace aws { namespace iot { namespace securedtunneling {
1988
2037
uint32_t new_connection_id = ++server->highest_connection_id ;
1989
2038
1990
2039
// backward compatibility: set connection id to 1 if simultaneous connections is not enabled
1991
- if (tac.adapter_config .is_v2_message_format )
2040
+ if (tac.adapter_config .is_v2_message_format || tac. adapter_config . is_v1_message_format )
1992
2041
{
1993
- new_connection_id = 1 ;
2042
+ BOOST_LOG_SEV (log , info) << " Falling back to older protocol, setting new connection id to 0" ;
2043
+ new_connection_id = 0 ;
1994
2044
}
1995
2045
BOOST_LOG_SEV (log , info) << " creating tcp connection id " << new_connection_id;
1996
2046
@@ -2009,7 +2059,7 @@ namespace aws { namespace iot { namespace securedtunneling {
2009
2059
server->connectionId_to_tcp_connection_map [new_connection_id]->socket () = std::move (new_socket);
2010
2060
BOOST_LOG_SEV (log , info) << " Accepted tcp connection on port " << server->connectionId_to_tcp_connection_map [new_connection_id]->socket ().local_endpoint ().port () << " from " << server->connectionId_to_tcp_connection_map [new_connection_id]->socket ().remote_endpoint ();
2011
2061
2012
- if (is_first_connection)
2062
+ if (is_first_connection || tac. adapter_config . is_v1_message_format || tac. adapter_config . is_v2_message_format )
2013
2063
{
2014
2064
async_send_stream_start (tac, service_id, new_connection_id);
2015
2065
}
0 commit comments