| 855 | } |
| 856 | |
| 857 | void endpoint_manager_impl::on_connect(std::shared_ptr<boardnet_endpoint> _endpoint) { |
| 858 | // Is called when endpoint->connect succeeded! |
| 859 | |
| 860 | // Set to state CONNECTED as connection is not yet fully established in remote side POV |
| 861 | // but endpoint is ready to send / receive. Set to ESTABLISHED after timer expires |
| 862 | // to prevent inserting subscriptions twice or send out subscription before remote side |
| 863 | // is finished with TCP 3 way handshake |
| 864 | _endpoint->set_connected(true); |
| 865 | |
| 866 | std::vector<serviceinfo> services_to_report_; |
| 867 | { |
| 868 | const bool endpoint_is_reliable = _endpoint->is_reliable(); |
| 869 | std::scoped_lock its_lock(endpoint_mutex_); |
| 870 | for (auto& [its_si, its_reliability_map] : remote_services_) { |
| 871 | if (auto found_endpoint = its_reliability_map.find(endpoint_is_reliable); found_endpoint != its_reliability_map.end()) { |
| 872 | if (found_endpoint->second == _endpoint) { |
| 873 | std::shared_ptr<serviceinfo> its_info(router_->find_service(its_si.service(), its_si.instance())); |
| 874 | if (!its_info) { |
| 875 | _endpoint->set_established(true); |
| 876 | return; |
| 877 | } |
| 878 | // only report services offered via TCP+UDP when both |
| 879 | // endpoints are connected |
| 880 | const auto its_other_endpoint = its_info->get_endpoint(!endpoint_is_reliable); |
| 881 | |
| 882 | if (!its_other_endpoint || (its_other_endpoint && its_other_endpoint->is_established_or_connected())) { |
| 883 | services_to_report_.push_back({its_si.service(), its_si.instance(), its_info->get_major(), its_info->get_minor(), 0, |
| 884 | true}); // the last 2 parameters will not be used |
| 885 | services_to_report_.back().set_endpoint(_endpoint, |
| 886 | true); // In this case, we don't care if the endpoint is reliable or not |
| 887 | } |
| 888 | } |
| 889 | } |
| 890 | } |
| 891 | } |
| 892 | for (const auto& s : services_to_report_) { |
| 893 | router_->service_endpoint_connected(s.get_service(), s.get_instance(), s.get_major(), s.get_minor(), s.get_endpoint(true)); |
| 894 | } |
| 895 | if (services_to_report_.empty()) { |
| 896 | _endpoint->set_established(true); |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | void endpoint_manager_impl::on_disconnect(std::shared_ptr<boardnet_endpoint> _endpoint) { |
| 901 | // Is called when endpoint->connect fails! |
no test coverage detected