Added the capability for custom encryption's to be added to EHC.

This commit is contained in:
2024-10-06 22:54:29 -07:00
parent 1feff0a25c
commit 8b01ee3c46
15 changed files with 392 additions and 182 deletions

View File

@@ -1,7 +1,7 @@
#pragma once
#include "ehs/io/socket/ehc/Utils.h"
#include "ehs/io/socket/ehc/NetUtils.h"
#include "ehs/io/socket/ehc/NetEnc.h"
#include "ehs/Serializer.h"
#include "ehs/Vector.h"
#include "ehs/Array.h"
@@ -10,7 +10,7 @@
namespace ehs
{
class NetSystem;
class NetSys;
class NetEnd;
class EHC;
@@ -24,6 +24,7 @@ namespace ehs
class EHC
{
private:
friend class NetEnc;
friend class NetEnd;
static const Version version;
@@ -47,7 +48,8 @@ namespace ehs
bool dropPackets;
Byte* buffer;
UInt_32 bufferSize;
Array<NetSystem *> systems;
Array<NetEnc *> encryptions;
Array<NetSys *> systems;
UInt_32 maxEndpoints;
UInt_64 lastTSC;
float delta;
@@ -90,13 +92,13 @@ namespace ehs
bool Disconnect(EndDisp endDisp, const Char_8 token[64], const Str_8& msg);
void Broadcast(EndDisp endDisp, Status endStatus, bool deltaLocked, bool encrypted,
void Broadcast(EndDisp endDisp, Status endStatus, bool deltaLocked, UInt_64 encHashId,
bool ensure, UInt_64 sysHashId, UInt_64 opHashId,
const Serializer<>& payload);
const Serializer<UInt_64> &payload);
void Broadcast(EndDisp endDisp, Status endStatus, bool deltaLocked, bool encrypted,
bool ensure, const Str_8& sysId, const Str_8& opId,
const Serializer<>& payload);
void Broadcast(EndDisp endDisp, Status endStatus, bool deltaLocked, const Str_8 &encId,
bool ensure, const Str_8 &sysId, const Str_8 &opId,
const Serializer<UInt_64> &payload);
void Poll();
@@ -124,15 +126,25 @@ namespace ehs
bool IsDropPacketsEnabled() const;
bool HasEncryption(UInt_64 encHashId) const;
bool HasEncryption(const Str_8& encId) const;
bool AddEncryption(NetEnc *enc);
NetEnc* GetEncryption(UInt_64 encHashId) const;
NetEnc* GetEncryption(const Str_8& encId) const;
bool HasSystem(UInt_64 sysHashId) const;
bool HasSystem(const Str_8& sysId) const;
bool AddSystem(NetSystem *sys);
bool AddSystem(NetSys *sys);
NetSystem* GetSystem(UInt_64 sysHashId) const;
NetSys* GetSystem(UInt_64 sysHashId) const;
NetSystem* GetSystem(const Str_8& sysId) const;
NetSys* GetSystem(const Str_8& sysId) const;
bool HasEndpoint(EndDisp endDisp, Status endStatus, const Char_8 token[64]) const;

View File

@@ -1,43 +0,0 @@
#pragma once
#include "Utils.h"
#include <ehs/Serializer.h>
namespace ehs
{
class Fragments
{
private:
Header header;
Serializer<UInt_64>* data;
UInt_64 size;
public:
~Fragments();
Fragments();
Fragments(const Header &header, const Serializer<UInt_64> &payload);
Fragments(const Header &header, UInt_64 size);
Fragments(Fragments &&frags) noexcept;
Fragments(const Fragments &frags);
Fragments &operator=(Fragments &&frags) noexcept;
Fragments &operator=(const Fragments &frags);
operator Serializer<UInt_64> *() const;
Header GetHeader() const;
UInt_64 Size() const;
bool IsComplete() const;
Packet Combine() const;
};
}

View File

@@ -0,0 +1,43 @@
#pragma once
#include "ehs/Str.h"
namespace ehs
{
class EHC;
class NetEnc
{
private:
friend class EHC;
EHC *owner;
UInt_64 hashId;
Str_8 id;
public:
virtual ~NetEnc() = default;
NetEnc();
NetEnc(Str_8 id);
NetEnc(NetEnc &&enc) noexcept;
NetEnc(const NetEnc &enc);
NetEnc &operator=(NetEnc &&enc) noexcept;
NetEnc &operator=(const NetEnc &enc);
EHC *GetOwner() const;
UInt_64 GetHashId() const;
Str_8 GetId() const;
virtual void Encrypt(Byte *data, UInt_64 size) const;
virtual void Decrypt(Byte *data, UInt_64 size) const;
};
}

View File

@@ -1,12 +1,12 @@
#pragma once
#include "Utils.h"
#include "Fragments.h"
#include "NetUtils.h"
#include "NetFrags.h"
#include <ehs/Str.h>
#include <ehs/Vector.h>
#include <ehs/Serializer.h>
#include <ehs/io/socket/Socket.h>
#include "ehs/Str.h"
#include "ehs/Vector.h"
#include "ehs/Serializer.h"
#include "ehs/io/socket/Socket.h"
namespace ehs
{
@@ -27,7 +27,7 @@ namespace ehs
UInt_64 nextSendId;
Vector<Insurance> sent;
UInt_64 nextRecvId;
Vector<Fragments> received;
Vector<NetFrags> received;
AddrType type;
Str_8 address;
UInt_16 port;
@@ -68,21 +68,21 @@ namespace ehs
/// Sends data to the remote endpoint.
/// @param [in] deltaLocked Whether or not to match the remote endpoint's delta time to prevent overloading the client. This will drop data if delta time does not match.
/// @param [in] encrypted Whether or not to encrypt this data before sending to the remote endpoint.
/// @param [in] encHashId The hash id of the encryption to use. Can be zero for none.
/// @param [in] ensure Whether or not to ensure the data was received by the remote endpoint.
/// @param [in] sys The system hash id to execute an operation from.
/// @param [in] op The operation hash id in the system to execute.
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
void Send(bool deltaLocked, bool encrypted, bool ensure, UInt_64 sys, UInt_64 op, const Serializer<UInt_64>& payload);
void Send(bool deltaLocked, UInt_64 encHashId, bool ensure, UInt_64 sys, UInt_64 op, const Serializer<UInt_64>& payload);
/// Sends data to the remote endpoint.
/// @param [in] deltaLocked Whether or not to match the remote endpoint's delta time to prevent overloading the client. This will drop data if delta time does not match.
/// @param [in] encrypted Whether or not to encrypt this data before sending to the remote endpoint.
/// @param [in] encId The id of the encryption to use. Can be empty for none.
/// @param [in] ensure Whether or not to ensure the data was received by the remote endpoint.
/// @param [in] sys The system string id to execute an operation from.
/// @param [in] op The operation string id in the system to execute.
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
void Send(bool deltaLocked, bool encrypted, bool ensure, const Str_8& sys, const Str_8& op, const Serializer<UInt_64>& payload);
void Send(bool deltaLocked, const Str_8 &encID, bool ensure, const Str_8& sys, const Str_8& op, const Serializer<UInt_64>& payload);
UInt_64 GetNextRecvId() const;
@@ -113,7 +113,7 @@ namespace ehs
void AddReceived(const Header& header, const Serializer<>& payload);
Vector<Fragments>* GetReceived();
Vector<NetFrags>* GetReceived();
void Ping(float delta);
@@ -123,7 +123,7 @@ namespace ehs
void SetQueueSlot(UInt_64 slot);
Fragments FragmentData(const Header& header, const Serializer<>& data);
NetFrags FragmentData(const Header& header, const Serializer<>& data);
void Send(const Header& header, const Serializer<>& payload);

View File

@@ -0,0 +1,43 @@
#pragma once
#include "NetUtils.h"
#include <ehs/Serializer.h>
namespace ehs
{
class NetFrags
{
private:
Header header;
Serializer<UInt_64>* data;
UInt_64 size;
public:
~NetFrags();
NetFrags();
NetFrags(const Header &header, const Serializer<UInt_64> &payload);
NetFrags(const Header &header, UInt_64 size);
NetFrags(NetFrags &&frags) noexcept;
NetFrags(const NetFrags &frags);
NetFrags &operator=(NetFrags &&frags) noexcept;
NetFrags &operator=(const NetFrags &frags);
operator Serializer<UInt_64> *() const;
Header GetHeader() const;
UInt_64 Size() const;
bool IsComplete() const;
Packet Combine() const;
};
}

View File

@@ -1,18 +1,18 @@
#pragma once
#include <ehs/Str.h>
#include <ehs/Serializer.h>
#include "ehs/Str.h"
#include "ehs/Serializer.h"
namespace ehs
{
class EHC;
class NetSystem;
class NetSys;
class NetEnd;
class NetOp
{
private:
friend class NetSystem;
friend class NetSys;
UInt_64 hashId;
Str_8 id;
@@ -37,6 +37,6 @@ namespace ehs
UInt_64 GetHashId() const;
private:
virtual void Process(EHC *ehc, NetEnd *endpoint, NetSystem *sys, Serializer<UInt_64> &payload);
virtual void Process(EHC *ehc, NetEnd *endpoint, NetSys *sys, Serializer<UInt_64> &payload);
};
}

View File

@@ -1,8 +1,8 @@
#pragma once
#include <ehs/Str.h>
#include <ehs/Array.h>
#include <ehs/Serializer.h>
#include "ehs/Str.h"
#include "ehs/Array.h"
#include "ehs/Serializer.h"
namespace ehs
{
@@ -10,7 +10,7 @@ namespace ehs
class NetEnd;
class NetOp;
class NetSystem
class NetSys
{
private:
friend class EHC;
@@ -20,19 +20,19 @@ namespace ehs
Array<NetOp*> ops;
public:
virtual ~NetSystem();
virtual ~NetSys();
NetSystem();
NetSys();
NetSystem(Str_8 id);
NetSys(Str_8 id);
NetSystem(NetSystem &&sys) noexcept;
NetSys(NetSys &&sys) noexcept;
NetSystem(const NetSystem &sys);
NetSys(const NetSys &sys);
NetSystem &operator=(NetSystem &&sys) noexcept;
NetSys &operator=(NetSys &&sys) noexcept;
NetSystem &operator=(const NetSystem &sys);
NetSys &operator=(const NetSys &sys);
Str_8 GetId() const;

View File

@@ -1,6 +1,6 @@
#pragma once
#include <ehs/Serializer.h>
#include "ehs/Serializer.h"
namespace ehs
{
@@ -20,7 +20,7 @@ namespace ehs
struct Header
{
bool encrypted = true;
UInt_64 encHashId = 0;
UInt_64 id = 0;
UInt_64 fragments = 0;
UInt_64 fragment = 0;
@@ -45,10 +45,10 @@ namespace ehs
};
}
#ifndef COMMS_IPV4_PAYLOAD
#define COMMS_IPV4_PAYLOAD (EHS_IPV4_UDP_PAYLOAD - (UInt_16)sizeof(Header))
#ifndef EHC_IPV4_PAYLOAD
#define EHC_IPV4_PAYLOAD (EHS_IPV4_UDP_PAYLOAD - (UInt_16)sizeof(Header))
#endif
#ifndef COMMS_IPV6_PAYLOAD
#define COMMS_IPV6_PAYLOAD (EHS_IPV6_UDP_PAYLOAD - (UInt_16)sizeof(Header))
#ifndef EHC_IPV6_PAYLOAD
#define EHC_IPV6_PAYLOAD (EHS_IPV6_UDP_PAYLOAD - (UInt_16)sizeof(Header))
#endif