Add support for authentication and encryption

This commit is contained in:
Guillaume Meunier
2024-11-26 23:59:35 +01:00
committed by Patrick Nicolas
parent 447b77c35c
commit c6e773fd22
45 changed files with 1516 additions and 455 deletions
+20 -8
View File
@@ -27,21 +27,24 @@
#include <optional>
#include <poll.h>
#include <stdexcept>
#include <stop_token>
#include <system_error>
namespace wivrn
{
class wivrn_connection
{
typed_socket<TCP, from_headset::packets, to_headset::packets> control;
typed_socket<UDP, from_headset::packets, to_headset::packets> stream;
std::atomic<bool> active = false;
std::string pin;
void init();
wivrn::from_headset::headset_info_packet info_packet;
void init(std::stop_token stop_token, std::function<void()> tick = []() {});
public:
wivrn_connection(TCP && tcp);
wivrn_connection(std::stop_token stop_token, const std::string & pin, TCP && tcp);
wivrn_connection(const wivrn_connection &) = delete;
wivrn_connection & operator=(const wivrn_connection &) = delete;
@@ -49,7 +52,7 @@ public:
{
return active;
}
void reset(TCP && tcp);
void reset(TCP && tcp, std::function<void()> tick = []() {});
void shutdown();
template <typename T>
@@ -66,15 +69,19 @@ public:
throw;
}
}
template <typename T>
void send_stream(T && packet)
{
try
{
if (active and stream)
stream.send(std::forward<T>(packet));
else
control.send(std::forward<T>(packet));
if (active)
{
if (stream)
stream.send(std::forward<T>(packet));
else
control.send(std::forward<T>(packet));
}
}
catch (...)
{
@@ -85,6 +92,11 @@ public:
std::optional<from_headset::packets> poll_control(int timeout);
const wivrn::from_headset::headset_info_packet & info() const
{
return info_packet;
}
template <typename T>
int poll(T && visitor, int timeout)
{