| 488 | static auto broadcast = safe::make_shared<broadcast_ctx_t>(start_broadcast, end_broadcast); |
| 489 | |
| 490 | session_t *control_server_t::get_session(const net::peer_t peer, uint32_t connect_data) { |
| 491 | { |
| 492 | // Fast path - look up existing session by peer |
| 493 | auto lg = _peer_to_session.lock(); |
| 494 | auto it = _peer_to_session->find(peer); |
| 495 | if (it != _peer_to_session->end()) { |
| 496 | return it->second; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | // Slow path - process new session |
| 501 | TUPLE_2D(peer_port, peer_addr, platf::from_sockaddr_ex((sockaddr *) &peer->address.address)); |
| 502 | auto lg = _sessions.lock(); |
| 503 | for (auto pos = std::begin(*_sessions); pos != std::end(*_sessions); ++pos) { |
| 504 | auto session_p = *pos; |
| 505 | |
| 506 | // Skip sessions that are already established |
| 507 | if (session_p->control.peer) { |
| 508 | continue; |
| 509 | } |
| 510 | |
| 511 | // Identify the connection by the unique connect data if the client supports it. |
| 512 | // Only fall back to IP address matching for clients without session ID support. |
| 513 | if (session_p->config.mlFeatureFlags & ML_FF_SESSION_ID_V1) { |
| 514 | if (session_p->control.connect_data != connect_data) { |
| 515 | continue; |
| 516 | } else { |
| 517 | BOOST_LOG(debug) << "Initialized new control stream session by connect data match [v2]"sv; |
| 518 | } |
| 519 | } else { |
| 520 | if (session_p->control.expected_peer_address != peer_addr) { |
| 521 | continue; |
| 522 | } else { |
| 523 | BOOST_LOG(debug) << "Initialized new control stream session by IP address match [v1]"sv; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | // Once the control stream connection is established, RTSP session state can be torn down |
| 528 | rtsp_stream::launch_session_clear(session_p->launch_session_id); |
| 529 | |
| 530 | session_p->control.peer = peer; |
| 531 | |
| 532 | // Use the local address from the control connection as the source address |
| 533 | // for other communications to the client. This is necessary to ensure |
| 534 | // proper routing on multi-homed hosts. |
| 535 | auto local_address = platf::from_sockaddr((sockaddr *) &peer->localAddress.address); |
| 536 | session_p->localAddress = boost::asio::ip::make_address(local_address); |
| 537 | |
| 538 | BOOST_LOG(debug) << "Control local address ["sv << local_address << ']'; |
| 539 | BOOST_LOG(debug) << "Control peer address ["sv << peer_addr << ':' << peer_port << ']'; |
| 540 | |
| 541 | // Insert this into the map for O(1) lookups in the future |
| 542 | auto ptslg = _peer_to_session.lock(); |
| 543 | _peer_to_session->emplace(peer, session_p); |
| 544 | return session_p; |
| 545 | } |
| 546 | |
| 547 | return nullptr; |
nothing calls this directly
no test coverage detected