This commit is contained in:
Your Name
2025-04-30 21:30:55 +12:00
parent 69ecc77d51
commit fe9c940a22
14 changed files with 26367 additions and 2 deletions

47
src/server.hpp Normal file
View File

@@ -0,0 +1,47 @@
#ifndef SERVER_HPP
#define SERVER_HPP
#include "config.hpp"
#include <string>
#include <unordered_map>
#include <memory>
#include <thread>
#include <atomic>
namespace dropshell {
class Server {
public:
Server(const ServerConfig& config);
~Server();
bool start();
void stop();
private:
struct ObjectInfo {
std::string label;
std::string tag;
uint64_t hash;
};
void handle_connection(int client_socket);
void handle_get_object(int client_socket, const std::string& path);
void handle_get_hash(int client_socket, const std::string& path);
void handle_get_directory(int client_socket);
void handle_put_object(int client_socket, const std::string& token, const std::string& label_tag);
void send_response(int client_socket, int status_code, const std::string& content_type, const std::string& body);
void send_file(int client_socket, const std::filesystem::path& file_path);
bool validate_write_token(const std::string& token) const;
std::pair<std::string, std::string> parse_label_tag(const std::string& label_tag) const;
const ServerConfig& config_;
int server_socket_;
std::atomic<bool> running_;
std::unordered_map<uint64_t, ObjectInfo> object_index_;
std::unordered_map<std::string, uint64_t> label_tag_index_;
};
} // namespace dropshell
#endif