/
isachkov
/
crypto_server
Обзор
Документация
Войти
/
isachkov
/
crypto_server
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
include/crypto_chat/client_session.hpp
45 строк
1 KB
Ivan Sachkov
CryptoServer
15 май 2024, 20:26
15 май 2024, 20:26
9de0f1f
Код
Авторство
О чём код?
#pragma once #include "secure_layer.hpp" #include <function2/function2.hpp> #include <memory> enum class ClientSessionState { Created, LoggedIn }; class ClientSession { public: using Descriptor = int; using OnBroadcast = fu2::function<void(const std::string&)>; ClientSession(Descriptor, SSLProvider&); ClientSession(const ClientSession&) = delete; ClientSession(ClientSession&&) = delete; ClientSession& operator=(const ClientSession&) = delete; ClientSession& operator=(ClientSession&&) = delete; void receive(std::vector<uint8_t>); void write(const std::string&); void on_broadcast(OnBroadcast); [[nodiscard]] bool init(); private: void dispatch_message(std::vector<uint8_t>); void receive_name(std::vector<uint8_t>); void receive_message(std::vector<uint8_t>); // We do not own it, higher level executor would close it for us Descriptor socket_{-1}; OnBroadcast on_broadcast_; SecureLayer secure_layer_; std::string user_name_; // Created -> next message would name the session ClientSessionState state_{ClientSessionState::Created}; }; using ClientSessionPtr = std::unique_ptr<ClientSession>;