-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSession.h
More file actions
90 lines (72 loc) · 3.2 KB
/
Session.h
File metadata and controls
90 lines (72 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// Created by stefano on 30/08/20.
//
#ifndef SERVERBACKUP_SESSION_H
#define SERVERBACKUP_SESSION_H
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include "SyncedFileServer.h"
#include <boost/asio/buffer.hpp>
#include <set>
#include <shared_mutex>
#include "Server.h"
#include "protocolMode.h"
using boost::asio::ip::tcp;
typedef boost::asio::ssl::stream<tcp::socket> ssl_socket;
class Session: public std::enable_shared_from_this<Session> {
private:
const static int N = 10240;
unsigned retry_count;
static std::set<std::string> subscribers_;
static std::shared_mutex subscribers_mutex;
std::shared_ptr<std::unordered_map<std::string, std::shared_ptr<SyncedFileServer>>> user_map;
ssl_socket socket_;
std::string username;
boost::asio::streambuf buf;
char data_[N+1];
ProtocolMode mode;
std::unordered_map<std::string, std::shared_ptr<SyncedFileServer>>::iterator next_file;
void saveMap();
void sendKORespAndRestart(const std::shared_ptr<Session>& session);
void sendNORespAndGetFile(const std::shared_ptr<Session>& self, const std::shared_ptr<SyncedFileServer>& sfp);
void getFile(const std::shared_ptr<Session>& self, const std::shared_ptr<SyncedFileServer>& sfp);
void getInfoFile(const std::shared_ptr<Session>& session);
void sendInfoFile(const std::shared_ptr<Session>& session);
void sendJSONFileR(const std::shared_ptr<Session>& session);
void getResp(const std::shared_ptr<Session>& session);
void sendBinaryFile(const std::shared_ptr<Session>& session);
void sendBinaryFileR(const std::shared_ptr<Session>& session, const std::shared_ptr<std::ifstream>& file_to_send);
void sendEndRestoreAndClose(const std::shared_ptr<Session>& session);
static std::string tempFilePath();
void getFileEnd(
const std::shared_ptr<Session>& self,
const std::shared_ptr<SyncedFileServer>& sfp,
const std::string& filePath);
void getFileR(
const std::shared_ptr<Session>& self,
const std::shared_ptr<SyncedFileServer>& sfp,
const std::shared_ptr<std::ofstream>& file_ptr,
const std::string& filePath,
ssize_t sizeRead
);
void moveFile(const std::shared_ptr<SyncedFileServer> &sfp, const std::string &tempPath);
void deleteFile(const std::shared_ptr<SyncedFileServer> &sfp);
void deleteFileMap(const std::shared_ptr<Session>& self, const std::shared_ptr<SyncedFileServer> &sfp);
boost::asio::ssl::stream<tcp::socket> &getSocket();
void clearBuffer();
void getMode(const std::shared_ptr<Session>& session);
friend class Server;
public:
~Session();
void sendOKRespAndRestart(const std::shared_ptr<Session>& session);
void sendKORespAndClose(std::shared_ptr<Session> self);
void setMap(std::shared_ptr<std::unordered_map<std::string, std::shared_ptr<SyncedFileServer>>> userMap);
void setUsername(std::string username);
static bool isLogged(const std::string& username);
static std::shared_ptr<Session> create(tcp::socket socket, boost::asio::ssl::context &context);
Session(
tcp::socket socket,
boost::asio::ssl::context& context
);
};
#endif //SERVERBACKUP_SESSION_H