Skip to content

Commit

Permalink
Adding iso mux support (#28)
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Lukas <[email protected]>
  • Loading branch information
SebaLukas authored Aug 7, 2024
1 parent 8555895 commit baef73c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/iso15118/tbd_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct TbdConfig {
config::SSLConfig ssl{config::CertificateBackend::EVEREST_LAYOUT, ""};
std::string interface_name;
config::TlsNegotiationStrategy tls_negotiation_strategy{config::TlsNegotiationStrategy::ACCEPT_CLIENT_OFFER};
bool enable_sdp_server{true};
};

class TbdController {
Expand All @@ -36,7 +37,7 @@ class TbdController {

private:
io::PollManager poll_manager;
io::SdpServer sdp_server;
std::unique_ptr<io::SdpServer> sdp_server;

d20::SessionConfig session_config;

Expand Down
4 changes: 3 additions & 1 deletion src/iso15118/io/socket_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ bool get_first_sockaddr_in6_for_interface(const std::string& interface_name, soc

// NOTE (aw): because we did the check for AF_INET6, we can assume that ifa_addr is indeed an sockaddr_in6
const auto current_addr = reinterpret_cast<const sockaddr_in6*>(current_if->ifa_addr);
if (not IN6_IS_ADDR_LINKLOCAL(&(current_addr->sin6_addr))) {

// NOTE (sl): If using loopback device, accept any address. Loopback usually does not have a link local address
if (interface_name.compare("lo") != 0 and not IN6_IS_ADDR_LINKLOCAL(&(current_addr->sin6_addr))) {
continue;
}

Expand Down
14 changes: 11 additions & 3 deletions src/iso15118/tbd_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ namespace iso15118 {

TbdController::TbdController(TbdConfig config_, session::feedback::Callbacks callbacks_) :
config(std::move(config_)), callbacks(std::move(callbacks_)) {
poll_manager.register_fd(sdp_server.get_fd(), [this]() { handle_sdp_server_input(); });
if (config.enable_sdp_server) {
sdp_server = std::make_unique<io::SdpServer>();
poll_manager.register_fd(sdp_server->get_fd(), [this]() { handle_sdp_server_input(); });
}
session_config = d20::SessionConfig();
}

void TbdController::loop() {
static constexpr auto POLL_MANAGER_TIMEOUT_MS = 50;

if (not config.enable_sdp_server) {
auto connection = std::make_unique<io::ConnectionPlain>(poll_manager, config.interface_name);
const auto& new_session = sessions.emplace_back(std::move(connection), session_config, callbacks);
}

auto next_event = get_current_time_point();

while (true) {
Expand Down Expand Up @@ -73,7 +81,7 @@ void TbdController::setup_session(const std::vector<message_20::Authorization>&
}

void TbdController::handle_sdp_server_input() {
auto request = sdp_server.get_peer_request();
auto request = sdp_server->get_peer_request();

if (not request) {
return;
Expand Down Expand Up @@ -104,7 +112,7 @@ void TbdController::handle_sdp_server_input() {
// Todo(sl): Check if session_config is empty
const auto& new_session = sessions.emplace_back(std::move(connection), session_config, callbacks);

sdp_server.send_response(request, ipv6_endpoint);
sdp_server->send_response(request, ipv6_endpoint);
}

} // namespace iso15118

0 comments on commit baef73c

Please sign in to comment.