-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSession.h
More file actions
67 lines (55 loc) · 1.9 KB
/
Copy pathSession.h
File metadata and controls
67 lines (55 loc) · 1.9 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
/*
* Copyright (C) 2021 Ilya Entin
*/
#pragma once
#include <memory>
#include <boost/core/noncopyable.hpp>
#include "CryptoOperations.h"
#include "IOUtility.h"
using namespace cryptooperations;
using ServerWeakPtr = std::weak_ptr<class Server>;
using TaskPtr = std::shared_ptr<class Task>;
class Session : private boost::noncopyable {
protected:
std::size_t _clientId = 0;
HEADER _header;
std::string _request;
TaskPtr _task;
std::string _responseData;
std::string _buffer;
ServerWeakPtr _server;
CryptoSodiumPtr _primarySodiumEncryptor;
CryptoSodiumPtr _secondarySodiumEncryptor;
CryptoPlPlPtr _primaryCryptoppEncryptor;
CryptoPlPlPtr _secondaryCryptoppEncryptor;
std::tuple<CryptoWeakSodiumPtr, CryptoWeakPlPlPtr> _encryptors;
// key exchange parametera
std::string _primaryPubKeyAes;
std::string _secondaryPubKeyAes;
HEADER _keyExchangeHeader;
Session(ServerWeakPtr server,
std::string_view primarySignatureWithKey,
std::string_view primaryPubKeyAes,
std::string_view secondarySignatureWithKey,
std::string_view secondaryPubKeyAes);
virtual ~Session() = default;
std::pair<HEADER, std::string_view>
buildReply(std::atomic<STATUS>& status);
bool processTask();
template <typename L>
void sendStatusToClient(L& lambda, STATUS status) {
std::string clientIdStr;
clientIdStr = ioutility::toCharsBoost(_clientId);
_keyExchangeHeader = { HEADERTYPE::DH_HANDSHAKE, clientIdStr.size(), _primaryPubKeyAes.size(),
COMPRESSORS::NONE, DIAGNOSTICS::NONE, status, _secondaryPubKeyAes.size(), 0};
lambda(_keyExchangeHeader, clientIdStr, _primaryPubKeyAes, _secondaryPubKeyAes);
}
void displayCapacityCheck(std::string_view type,
unsigned totalNumberObjects,
unsigned numberObjects,
unsigned numberRunningByType,
unsigned maxNumberRunningByType,
STATUS status);
public:
std::size_t getId() const { return _clientId; }
};