SVCS - English Documentation
Loading...
Searching...
No Matches
SSHServer.hxx
Go to the documentation of this file.
1
15
16#pragma once
17
18#include "SSHConfig.hxx"
19#include "SSHSession.hxx"
23
24#include <cstring>
25#include <memory>
26#include <string>
27#include <atomic>
28#include <thread>
29#include <vector>
30#include <mutex>
31
32namespace svcs::server::ssh {
33
36 * @class SSHServer
37 * @brief Main SSH server class
38 * @details Manages SSH connections and executes repository operations
39 *
40 * @russian
41 * @class SSHServer
42 * @brief Основной класс SSH сервера
43 * @details Управляет SSH соединениями и выполняет операции с репозиториями
44 */
45class SSHServer {
46public:
60 SSHServer(const SSHConfig& config,
61 std::shared_ptr<svcs::core::RepositoryManager> repo_manager,
62 std::shared_ptr<svcs::services::ISubject> event_bus);
63
71 ~SSHServer();
72
73 SSHServer(const SSHServer&) = delete;
74 SSHServer& operator=(const SSHServer&) = delete;
75
85 bool start();
86
94 void stop();
95
105 bool isRunning() const { return running_; }
106
116 size_t getActiveConnections() const;
117
125
129 void addUserKey(const std::string& username,
130 const std::string& public_key);
131
143 void setUserPassword(const std::string& username,
144 const std::string& password);
145
146private:
147 void run();
148 void handleClient(svcs::platform::SocketHandle client_fd);
149 bool initializeSSH();
150 void cleanup();
151 void logEvent(const std::string& message, bool is_error = false) const;
152 bool handleSVCSCommand(const std::string& command, ssh_channel channel);
153
154 SSHConfig config_;
155 std::shared_ptr<svcs::core::RepositoryManager> repo_manager_;
156 std::shared_ptr<svcs::services::ISubject> event_bus_;
157
158 std::atomic<bool> running_{false};
159 std::thread server_thread_;
160
161 svcs::platform::SocketHandle server_socket_ = INVALID_SOCKET_HANDLE;
162 ssh_bind ssh_bind_ = nullptr;
163
164 mutable std::mutex connections_mutex_;
165 std::vector<std::thread> client_threads_;
166 std::atomic<size_t> active_connections_{0};
167};
168
169}
Defines the interface for the Subject (Publisher) component of the Observer pattern.
Cross-platform network utilities.
Declaration of the RepositoryManager class, managing all repository-level file operations.
SSH server configuration.
SSH session handler.
void setUserPassword(const std::string &username, const std::string &password)
Set password for user.
Definition SSHServer.cxx:278
void stop()
Stop server.
Definition SSHServer.cxx:240
~SSHServer()
Destructor.
Definition SSHServer.cxx:203
SSHServer(const SSHConfig &config, std::shared_ptr< svcs::core::RepositoryManager > repo_manager, std::shared_ptr< svcs::services::ISubject > event_bus)
Constructor.
void addUserKey(const std::string &username, const std::string &public_key)
Add public key for user.
Definition SSHServer.cxx:268
bool isRunning() const
Check if running.
Definition SSHServer.hxx:76
size_t getActiveConnections() const
Get active connections.
Definition SSHServer.cxx:264
bool start()
Start server.
Definition SSHServer.cxx:207
SSH server configuration.
Definition SSHConfig.hxx:23