Stub of FLpxSockets is now in place

This commit is contained in:
2023-06-23 16:27:23 -04:00
parent 42f3e02ec2
commit d5d4e0a650
6 changed files with 220 additions and 51 deletions

View File

@@ -0,0 +1,101 @@
#include "LuprexSockets.hpp"
#define UI UI_ST
THIRD_PARTY_INCLUDES_START
#include <openssl/ssl.h>
#include <openssl/rsa.h>
#include <openssl/x509.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include <openssl/pem.h>
#include <openssl/conf.h>
THIRD_PARTY_INCLUDES_END
#undef UI
enum EChanState {
CHAN_INACTIVE,
CHAN_PLAINTEXT,
CHAN_SSL_CONNECTING,
CHAN_SSL_ACCEPTING,
CHAN_SSL_READWRITE,
};
// A communication socket.
class FLpxChannel
{
int ChannelID;
FSocket* Socket;
SSL* SSLState;
BIO* RecvBIO;
BIO* SendBIO;
// If recent_error is set, that means that a recent IO operation generated
// an error. As a special case, EOF on read is considered an error, we use
// the string "EOF" for this case.
std::string RecentError;
// OpenSSL has a rule: if you try to SSL_write and it returns
// SSL_ERROR_WANT_READ, then you have to retry the write with the same
// number of bytes. In this event, we record how many bytes we
// attempted to write, which will enable us to retry.
int RetryWriteNBytes;
// True if the channel needs to be advanced.
bool NeedAdvance;
EChanState State;
uint32_t NBytes;
const char* Bytes;
};
// A port-listening socket.
class FLpxListener
{
int BoundPort;
FSocket* Socket;
};
class FLpxSocketsI : public FLpxSockets
{
public:
// We don't own the wrapper, we just have a pointer to it.
// We require a guarantee that it outlives us.
EngineWrapper* Luprex;
TArray<FLpxChannel> Channels;
TArray<FLpxListener> Listeners;
SSL_CTX* ServerCTX;
SSL_CTX* ClientSecureCTX;
SSL_CTX* ClientInsecureCTX;
FLpxSocketsI(EngineWrapper* w);
virtual ~FLpxSocketsI() override;
virtual void Update() override;
};
FLpxSocketsI::FLpxSocketsI(EngineWrapper *w)
{
Luprex = w;
ServerCTX = nullptr;
ClientSecureCTX = nullptr;
ClientInsecureCTX = nullptr;
}
FLpxSocketsI::~FLpxSocketsI()
{
}
void FLpxSocketsI::Update()
{
}
FLpxSockets* FLpxSockets::Create(EngineWrapper* w)
{
return new FLpxSocketsI(w);
}