45 lines
897 B
C++
45 lines
897 B
C++
#pragma once
|
|
|
|
#include <thread>
|
|
#include <atomic>
|
|
#include <string>
|
|
#include <openssl/ssl.h>
|
|
#include <openssl/err.h>
|
|
#include "ssl.h"
|
|
#include <nerutils/callback.h>
|
|
|
|
/*
|
|
TO-DO:
|
|
use random port, test availability
|
|
*/
|
|
#define PROXY_PORT 58421
|
|
|
|
typedef unsigned __int64 SOCKET;
|
|
|
|
class Proxy
|
|
{
|
|
public:
|
|
Proxy();
|
|
~Proxy();
|
|
|
|
bool init();
|
|
void shutdown();
|
|
|
|
CallbackEvent<std::string&, const std::string&, std::string&> OnClientRequest;
|
|
CallbackEvent<const std::string&, std::string&, std::string&> OnServerResponse;
|
|
|
|
private:
|
|
void loop();
|
|
void handleClient(SOCKET clientSocket);
|
|
|
|
bool initSSL();
|
|
void cleanupSSL();
|
|
|
|
SOCKET _listenSocket = 0;
|
|
std::thread _workerThread;
|
|
std::atomic<bool> _running = false;
|
|
|
|
CertManager _certManager;
|
|
SSL_CTX* _clientCtx = nullptr;
|
|
};
|