@@ -616,15 +616,15 @@ namespace ccf
616
616
disp, ::tcp::tcp_inbound, [this ](const uint8_t * data, size_t size) {
617
617
auto id = serialized::peek<ccf::tls::ConnID>(data, size);
618
618
619
- auto search = sessions. find (id);
620
- if (search == sessions. end () )
619
+ auto session = find_session (id);
620
+ if (session == nullptr )
621
621
{
622
622
LOG_DEBUG_FMT (
623
623
" Ignoring tls_inbound for unknown or refused session: {}" , id);
624
624
return ;
625
625
}
626
626
627
- search-> second . second ->handle_incoming_data ({data, size});
627
+ session ->handle_incoming_data ({data, size});
628
628
});
629
629
630
630
DISPATCHER_SET_MESSAGE_HANDLER (
@@ -644,58 +644,66 @@ namespace ccf
644
644
disp, udp::udp_inbound, [this ](const uint8_t * data, size_t size) {
645
645
auto id = serialized::peek<int64_t >(data, size);
646
646
647
- auto search = sessions.find (id);
648
- if (search == sessions.end ())
647
+ std::shared_ptr<Session> session;
649
648
{
650
- LOG_DEBUG_FMT (
651
- " Ignoring udp::udp_inbound for unknown or refused session: {}" ,
652
- id);
653
- return ;
654
- }
655
- else if (!search->second .second && custom_protocol_subsystem)
656
- {
657
- LOG_DEBUG_FMT (" Creating custom UDP session {}" , id);
649
+ std::lock_guard<ccf::pal::Mutex> guard (lock);
658
650
659
- try
651
+ auto search = sessions.find (id);
652
+ if (search == sessions.end ())
660
653
{
661
- const auto & conn_id = search->first ;
662
- const auto & interface_id = search->second .first ;
654
+ LOG_DEBUG_FMT (
655
+ " Ignoring udp::udp_inbound for unknown or refused session: {}" ,
656
+ id);
657
+ return ;
658
+ }
659
+ else if (!search->second .second && custom_protocol_subsystem)
660
+ {
661
+ LOG_DEBUG_FMT (" Creating custom UDP session {}" , id);
663
662
664
- auto iit = listening_interfaces.find (interface_id);
665
- if (iit == listening_interfaces.end ())
663
+ try
666
664
{
667
- LOG_DEBUG_FMT (
668
- " Failure to create custom protocol session because of "
669
- " unknown interface '{}', ignoring udp::udp_inbound for "
670
- " session: "
671
- " {}" ,
672
- interface_id,
673
- id);
665
+ const auto & conn_id = search->first ;
666
+ const auto & interface_id = search->second .first ;
667
+
668
+ auto iit = listening_interfaces.find (interface_id);
669
+ if (iit == listening_interfaces.end ())
670
+ {
671
+ LOG_DEBUG_FMT (
672
+ " Failure to create custom protocol session because of "
673
+ " unknown interface '{}', ignoring udp::udp_inbound for "
674
+ " session: "
675
+ " {}" ,
676
+ interface_id,
677
+ id);
678
+ }
679
+
680
+ const auto & interface = iit->second ;
681
+
682
+ search->second .second =
683
+ custom_protocol_subsystem->create_session (
684
+ interface.app_protocol , conn_id, nullptr );
685
+
686
+ if (!search->second .second )
687
+ {
688
+ LOG_DEBUG_FMT (
689
+ " Failure to create custom protocol session, ignoring "
690
+ " udp::udp_inbound for session: {}" ,
691
+ id);
692
+ return ;
693
+ }
674
694
}
675
-
676
- const auto & interface = iit->second ;
677
-
678
- search->second .second = custom_protocol_subsystem->create_session (
679
- interface.app_protocol , conn_id, nullptr );
680
-
681
- if (!search->second .second )
695
+ catch (const std::exception & ex)
682
696
{
683
697
LOG_DEBUG_FMT (
684
- " Failure to create custom protocol session, ignoring "
685
- " udp::udp_inbound for session: {}" ,
686
- id);
698
+ " Failure to create custom protocol session: {}" , ex.what ());
687
699
return ;
688
700
}
689
701
}
690
- catch (const std::exception & ex)
691
- {
692
- LOG_DEBUG_FMT (
693
- " Failure to create custom protocol session: {}" , ex.what ());
694
- return ;
695
- }
702
+
703
+ session = search->second .second ;
696
704
}
697
705
698
- search-> second . second ->handle_incoming_data ({data, size});
706
+ session ->handle_incoming_data ({data, size});
699
707
});
700
708
}
701
709
};
0 commit comments