Added the capability for custom encryption's to be added to EHC.
This commit is contained in:
76
src/io/socket/ehc/NetEnc.cpp
Normal file
76
src/io/socket/ehc/NetEnc.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include "ehs/io/socket/ehc/NetEnc.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
NetEnc::NetEnc()
|
||||
: owner(nullptr), hashId(0)
|
||||
{
|
||||
}
|
||||
|
||||
NetEnc::NetEnc(Str_8 id)
|
||||
: owner(nullptr), hashId(id.Hash_64()), id((Str_8 &&)id)
|
||||
{
|
||||
}
|
||||
|
||||
NetEnc::NetEnc(NetEnc&& enc) noexcept
|
||||
: owner(enc.owner), hashId(enc.hashId), id((Str_8 &&)enc.id)
|
||||
{
|
||||
enc.owner = nullptr;
|
||||
enc.hashId = 0;
|
||||
}
|
||||
|
||||
NetEnc::NetEnc(const NetEnc& enc)
|
||||
: owner(nullptr), hashId(enc.hashId), id(enc.id)
|
||||
{
|
||||
}
|
||||
|
||||
NetEnc& NetEnc::operator=(NetEnc&& enc) noexcept
|
||||
{
|
||||
if (this == &enc)
|
||||
return *this;
|
||||
|
||||
owner = enc.owner;
|
||||
hashId = enc.hashId;
|
||||
id = (Str_8 &&)enc.id;
|
||||
|
||||
enc.owner = nullptr;
|
||||
enc.hashId = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NetEnc& NetEnc::operator=(const NetEnc& enc)
|
||||
{
|
||||
if (this == &enc)
|
||||
return *this;
|
||||
|
||||
owner = nullptr;
|
||||
hashId = enc.hashId;
|
||||
id = enc.id;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
EHC* NetEnc::GetOwner() const
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
|
||||
UInt_64 NetEnc::GetHashId() const
|
||||
{
|
||||
return hashId;
|
||||
}
|
||||
|
||||
Str_8 NetEnc::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
void NetEnc::Encrypt(Byte *data, UInt_64 size) const
|
||||
{
|
||||
}
|
||||
|
||||
void NetEnc::Decrypt(Byte *data, UInt_64 size) const
|
||||
{
|
||||
}
|
||||
}
|
@@ -1,8 +1,7 @@
|
||||
#include "ehs/io/socket/ehc/NetEnd.h"
|
||||
#include "ehs/io/socket/EHC.h"
|
||||
|
||||
#include <ehs/system/CPU.h>
|
||||
#include <ehe/Encryption.h>
|
||||
#include "ehs/io/socket/ehc/NetEnc.h"
|
||||
#include "ehs/system/CPU.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
@@ -33,10 +32,10 @@ namespace ehs
|
||||
|
||||
NetEnd::NetEnd(NetEnd &&end) noexcept
|
||||
: owner(end.owner), disposition(end.disposition), hashName(end.hashName), name((Str_8&&)end.name), status(end.status), arch(end.arch), token{},
|
||||
nextSendId(end.nextSendId), sent((Vector<Insurance>&&)end.sent), nextRecvId(end.nextRecvId),
|
||||
received((Vector<Fragments>&&)end.received), type(end.type), address((Str_8&&)end.address), port(end.port),
|
||||
deltaDuration(end.deltaDuration), deltaRate(end.deltaRate), timeout(end.timeout), lastPing(end.lastPing),
|
||||
oldLatency(end.oldLatency), latency(end.latency), queueSlot(end.queueSlot)
|
||||
nextSendId(end.nextSendId), sent((Vector<Insurance>&&)end.sent), nextRecvId(end.nextRecvId),
|
||||
received((Vector<NetFrags>&&)end.received), type(end.type), address((Str_8&&)end.address), port(end.port),
|
||||
deltaDuration(end.deltaDuration), deltaRate(end.deltaRate), timeout(end.timeout), lastPing(end.lastPing),
|
||||
oldLatency(end.oldLatency), latency(end.latency), queueSlot(end.queueSlot)
|
||||
{
|
||||
end.owner = nullptr;
|
||||
end.disposition = EndDisp::ENDPOINT;
|
||||
@@ -80,7 +79,7 @@ namespace ehs
|
||||
nextSendId = end.nextSendId;
|
||||
sent = (Vector<Insurance>&&)end.sent;
|
||||
nextRecvId = end.nextRecvId;
|
||||
received = (Vector<Fragments>&&)end.received;
|
||||
received = (Vector<NetFrags>&&)end.received;
|
||||
type = end.type;
|
||||
address = (Str_8&&)end.address;
|
||||
port = end.port;
|
||||
@@ -173,14 +172,14 @@ namespace ehs
|
||||
return nextSendId;
|
||||
}
|
||||
|
||||
void NetEnd::Send(const bool deltaLocked, const bool encrypted, const bool ensure, const UInt_64 sys,
|
||||
const UInt_64 op, const Serializer<>& payload)
|
||||
void NetEnd::Send(const bool deltaLocked, const UInt_64 encHashId, const bool ensure, const UInt_64 sys,
|
||||
const UInt_64 op, const Serializer<UInt_64> &payload)
|
||||
{
|
||||
if (deltaLocked && deltaDuration < deltaRate)
|
||||
return;
|
||||
|
||||
Header header = {
|
||||
encrypted,
|
||||
encHashId,
|
||||
nextSendId++,
|
||||
1,
|
||||
0,
|
||||
@@ -193,9 +192,9 @@ namespace ehs
|
||||
|
||||
Util::Copy(header.token, token, 64);
|
||||
|
||||
if ((owner->GetLocalAddressType() == AddrType::IPV6 && payload.Size() > COMMS_IPV6_PAYLOAD) || (owner->GetLocalAddressType() == AddrType::IPV4 && payload.Size() > COMMS_IPV4_PAYLOAD))
|
||||
if ((owner->GetLocalAddressType() == AddrType::IPV6 && payload.Size() > EHC_IPV6_PAYLOAD) || (owner->GetLocalAddressType() == AddrType::IPV4 && payload.Size() > EHC_IPV4_PAYLOAD))
|
||||
{
|
||||
Fragments frags = FragmentData(header, payload);
|
||||
NetFrags frags = FragmentData(header, payload);
|
||||
for (UInt_64 i = 0; i < frags.Size(); ++i)
|
||||
{
|
||||
Header newHeader = frags.GetHeader();
|
||||
@@ -210,10 +209,10 @@ namespace ehs
|
||||
}
|
||||
}
|
||||
|
||||
void NetEnd::Send(const bool deltaLocked, const bool encrypted, const bool ensure, const Str_8& sys,
|
||||
const Str_8& op, const Serializer<>& payload)
|
||||
void NetEnd::Send(const bool deltaLocked, const Str_8 &encId, const bool ensure, const Str_8& sys,
|
||||
const Str_8& op, const Serializer<>& payload)
|
||||
{
|
||||
Send(deltaLocked, encrypted, ensure, sys.Hash_64(), op.Hash_64(), payload);
|
||||
Send(deltaLocked, encId.Hash_64(), ensure, sys.Hash_64(), op.Hash_64(), payload);
|
||||
}
|
||||
|
||||
UInt_64 NetEnd::GetNextRecvId() const
|
||||
@@ -278,8 +277,19 @@ namespace ehs
|
||||
result.Write(sent[i].header);
|
||||
result.WriteSer(sent[i].payload);
|
||||
|
||||
if (sent[i].header.encrypted)
|
||||
Encryption::Encrypt_64(result.Size() - sizeof(bool), &result[sizeof(bool)]);
|
||||
if (sent[i].header.encHashId)
|
||||
{
|
||||
NetEnc *enc = owner->GetEncryption(sent[i].header.encHashId);
|
||||
if (!enc)
|
||||
{
|
||||
EHS_LOG_INT(LogType::WARN, 0, "The network encryption with the hash id " +
|
||||
Str_8::FromNum(sent[i].header.encHashId) + ", does not exist.");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
enc->Encrypt(&result[sizeof(bool)], result.Size() - sizeof(bool));
|
||||
}
|
||||
|
||||
owner->udp.Send(type, address, port, result, result.Size());
|
||||
|
||||
@@ -294,6 +304,8 @@ namespace ehs
|
||||
if (lastPing >= 1.0f)
|
||||
Ping(delta);
|
||||
}
|
||||
|
||||
EHS_LOG_SUCCESS();
|
||||
}
|
||||
|
||||
void NetEnd::SetStatus(const Status newStatus)
|
||||
@@ -317,7 +329,7 @@ namespace ehs
|
||||
|
||||
void NetEnd::AddReceived(const Header& header, const Serializer<>& payload)
|
||||
{
|
||||
Fragments* frags = nullptr;
|
||||
NetFrags* frags = nullptr;
|
||||
|
||||
for (UInt_64 i = 0; i < received.Size(); ++i)
|
||||
{
|
||||
@@ -342,7 +354,7 @@ namespace ehs
|
||||
timeout = 0.0f;
|
||||
}
|
||||
|
||||
Vector<Fragments>* NetEnd::GetReceived()
|
||||
Vector<NetFrags>* NetEnd::GetReceived()
|
||||
{
|
||||
return &received;
|
||||
}
|
||||
@@ -395,46 +407,46 @@ namespace ehs
|
||||
queueSlot = slot;
|
||||
}
|
||||
|
||||
Fragments NetEnd::FragmentData(const Header& header, const Serializer<>& data)
|
||||
NetFrags NetEnd::FragmentData(const Header& header, const Serializer<>& data)
|
||||
{
|
||||
Fragments result;
|
||||
NetFrags result;
|
||||
|
||||
if (owner->GetLocalAddressType() == AddrType::IPV6)
|
||||
{
|
||||
UInt_64 frags = data.Size() / COMMS_IPV6_PAYLOAD;
|
||||
if (data.Size() % COMMS_IPV6_PAYLOAD)
|
||||
UInt_64 frags = data.Size() / EHC_IPV6_PAYLOAD;
|
||||
if (data.Size() % EHC_IPV6_PAYLOAD)
|
||||
++frags;
|
||||
|
||||
result = Fragments(header, frags);
|
||||
result = NetFrags(header, frags);
|
||||
|
||||
UInt_64 size = COMMS_IPV6_PAYLOAD;
|
||||
UInt_64 size = EHC_IPV6_PAYLOAD;
|
||||
|
||||
for (UInt_64 i = 0; i < result.Size(); ++i)
|
||||
{
|
||||
size = COMMS_IPV6_PAYLOAD;
|
||||
size = EHC_IPV6_PAYLOAD;
|
||||
if (i == result.Size() - 1)
|
||||
size = data.Size() % COMMS_IPV6_PAYLOAD;
|
||||
size = data.Size() % EHC_IPV6_PAYLOAD;
|
||||
|
||||
result[i] = {data.GetEndianness(), &data[i * COMMS_IPV6_PAYLOAD], size};
|
||||
result[i] = {data.GetEndianness(), &data[i * EHC_IPV6_PAYLOAD], size};
|
||||
}
|
||||
}
|
||||
else if (owner->GetLocalAddressType() == AddrType::IPV4)
|
||||
{
|
||||
UInt_64 frags = data.Size() / COMMS_IPV4_PAYLOAD;
|
||||
if (data.Size() % COMMS_IPV4_PAYLOAD)
|
||||
UInt_64 frags = data.Size() / EHC_IPV4_PAYLOAD;
|
||||
if (data.Size() % EHC_IPV4_PAYLOAD)
|
||||
++frags;
|
||||
|
||||
result = Fragments(header, frags);
|
||||
result = NetFrags(header, frags);
|
||||
|
||||
UInt_64 size = COMMS_IPV4_PAYLOAD;
|
||||
UInt_64 size = EHC_IPV4_PAYLOAD;
|
||||
|
||||
for (UInt_64 i = 0; i < result.Size(); ++i)
|
||||
{
|
||||
size = COMMS_IPV4_PAYLOAD;
|
||||
size = EHC_IPV4_PAYLOAD;
|
||||
if (i == result.Size() - 1)
|
||||
size = data.Size() % COMMS_IPV4_PAYLOAD;
|
||||
size = data.Size() % EHC_IPV4_PAYLOAD;
|
||||
|
||||
result[i] = {data.GetEndianness(), &data[i * COMMS_IPV4_PAYLOAD], size};
|
||||
result[i] = {data.GetEndianness(), &data[i * EHC_IPV4_PAYLOAD], size};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,8 +459,19 @@ namespace ehs
|
||||
result.Write(header);
|
||||
result.WriteSer(payload);
|
||||
|
||||
if (header.encrypted)
|
||||
Encryption::Encrypt_64(result.Size() - sizeof(bool), &result[sizeof(bool)]);
|
||||
if (header.encHashId)
|
||||
{
|
||||
NetEnc *enc = owner->GetEncryption(header.encHashId);
|
||||
if (!enc)
|
||||
{
|
||||
EHS_LOG_INT(LogType::WARN, 0, "The network encryption with the hash id " +
|
||||
Str_8::FromNum(header.encHashId) + ", does not exist.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
enc->Encrypt(&result[sizeof(bool)], result.Size() - sizeof(bool));
|
||||
}
|
||||
|
||||
if (header.ensure)
|
||||
sent.Push({header, payload});
|
||||
@@ -476,7 +499,7 @@ namespace ehs
|
||||
if (!SortingNeeded())
|
||||
return;
|
||||
|
||||
Vector<Fragments> sorted(0, received.Stride());
|
||||
Vector<NetFrags> sorted(0, received.Stride());
|
||||
|
||||
for (UInt_64 a = 0; a < received.Size(); ++a)
|
||||
{
|
||||
|
@@ -1,32 +1,32 @@
|
||||
#include "ehs/io/socket/ehc/Fragments.h"
|
||||
#include "ehs/io/socket/ehc/NetFrags.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
Fragments::~Fragments()
|
||||
NetFrags::~NetFrags()
|
||||
{
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
Fragments::Fragments()
|
||||
NetFrags::NetFrags()
|
||||
: data(nullptr), size(0)
|
||||
{
|
||||
}
|
||||
|
||||
Fragments::Fragments(const Header &header, const Serializer<UInt_64> &payload)
|
||||
NetFrags::NetFrags(const Header &header, const Serializer<UInt_64> &payload)
|
||||
: header(header), data(new Serializer<UInt_64>[header.fragments]), size(header.fragments)
|
||||
{
|
||||
this->header.fragment = 0;
|
||||
data[header.fragment] = payload;
|
||||
}
|
||||
|
||||
Fragments::Fragments(const Header &header, const UInt_64 size)
|
||||
NetFrags::NetFrags(const Header &header, const UInt_64 size)
|
||||
: header(header), data(new Serializer<UInt_64>[size]), size(size)
|
||||
{
|
||||
this->header.fragments = size;
|
||||
this->header.fragment = 0;
|
||||
}
|
||||
|
||||
Fragments::Fragments(Fragments &&frags) noexcept
|
||||
NetFrags::NetFrags(NetFrags &&frags) noexcept
|
||||
: header(frags.header), data(frags.data), size(frags.size)
|
||||
{
|
||||
frags.header = {};
|
||||
@@ -34,14 +34,14 @@ namespace ehs
|
||||
frags.size = 0;
|
||||
}
|
||||
|
||||
Fragments::Fragments(const Fragments &frags)
|
||||
NetFrags::NetFrags(const NetFrags &frags)
|
||||
: header(frags.header), data(new Serializer<UInt_64>[frags.size]), size(frags.size)
|
||||
{
|
||||
for (UInt_64 i = 0; i < size; ++i)
|
||||
data[i] = frags.data[i];
|
||||
}
|
||||
|
||||
Fragments &Fragments::operator=(Fragments &&frags) noexcept
|
||||
NetFrags &NetFrags::operator=(NetFrags &&frags) noexcept
|
||||
{
|
||||
if (this == &frags)
|
||||
return *this;
|
||||
@@ -60,7 +60,7 @@ namespace ehs
|
||||
return *this;
|
||||
}
|
||||
|
||||
Fragments &Fragments::operator=(const Fragments &frags)
|
||||
NetFrags &NetFrags::operator=(const NetFrags &frags)
|
||||
{
|
||||
if (this == &frags)
|
||||
return *this;
|
||||
@@ -75,22 +75,22 @@ namespace ehs
|
||||
return *this;
|
||||
}
|
||||
|
||||
Fragments::operator Serializer<UInt_64> *() const
|
||||
NetFrags::operator Serializer<UInt_64> *() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
Header Fragments::GetHeader() const
|
||||
Header NetFrags::GetHeader() const
|
||||
{
|
||||
return header;
|
||||
}
|
||||
|
||||
UInt_64 Fragments::Size() const
|
||||
UInt_64 NetFrags::Size() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
bool Fragments::IsComplete() const
|
||||
bool NetFrags::IsComplete() const
|
||||
{
|
||||
for (UInt_64 i = 0; i < size; ++i)
|
||||
if (!data[i].Size())
|
||||
@@ -99,7 +99,7 @@ namespace ehs
|
||||
return true;
|
||||
}
|
||||
|
||||
Packet Fragments::Combine() const
|
||||
Packet NetFrags::Combine() const
|
||||
{
|
||||
UInt_64 rSize = 0;
|
||||
for (UInt_64 i = 0; i < size; ++i)
|
@@ -1,7 +1,7 @@
|
||||
#include "ehs/io/socket/ehc/NetOp.h"
|
||||
#include "ehs/io/socket/EHC.h"
|
||||
#include "ehs/io/socket/ehc/NetEnd.h"
|
||||
#include "ehs/io/socket/ehc/NetSystem.h"
|
||||
#include "ehs/io/socket/ehc/NetSys.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
@@ -60,7 +60,7 @@ namespace ehs
|
||||
return hashId;
|
||||
}
|
||||
|
||||
void NetOp::Process(EHC *ehc, NetEnd *endpoint, NetSystem *sys, Serializer<UInt_64> &payload)
|
||||
void NetOp::Process(EHC *ehc, NetEnd *endpoint, NetSys *sys, Serializer<UInt_64> &payload)
|
||||
{
|
||||
}
|
||||
}
|
@@ -1,11 +1,11 @@
|
||||
#include "ehs/io/socket/ehc/NetSystem.h"
|
||||
#include "ehs/io/socket/ehc/NetSys.h"
|
||||
#include "ehs/io/socket/EHC.h"
|
||||
#include "ehs/io/socket/ehc/NetEnd.h"
|
||||
#include "ehs/io/socket/ehc/NetOp.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
NetSystem::~NetSystem()
|
||||
NetSys::~NetSys()
|
||||
{
|
||||
for (UInt_64 i = 0; i < ops.Size(); ++i)
|
||||
delete ops[i];
|
||||
@@ -13,28 +13,28 @@ namespace ehs
|
||||
ops.Clear();
|
||||
}
|
||||
|
||||
NetSystem::NetSystem()
|
||||
NetSys::NetSys()
|
||||
: hashId(0)
|
||||
{
|
||||
}
|
||||
|
||||
NetSystem::NetSystem(Str_8 id)
|
||||
NetSys::NetSys(Str_8 id)
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id)
|
||||
{
|
||||
}
|
||||
|
||||
NetSystem::NetSystem(NetSystem&& sys) noexcept
|
||||
NetSys::NetSys(NetSys&& sys) noexcept
|
||||
: hashId(sys.hashId), id((Str_8&&)sys.id), ops((Array<NetOp*>&&)sys.ops)
|
||||
{
|
||||
sys.hashId = 0;
|
||||
}
|
||||
|
||||
NetSystem::NetSystem(const NetSystem& sys)
|
||||
NetSys::NetSys(const NetSys& sys)
|
||||
: hashId(sys.hashId), id(sys.id)
|
||||
{
|
||||
}
|
||||
|
||||
NetSystem& NetSystem::operator=(NetSystem&& sys) noexcept
|
||||
NetSys& NetSys::operator=(NetSys&& sys) noexcept
|
||||
{
|
||||
if (this == &sys)
|
||||
return *this;
|
||||
@@ -48,7 +48,7 @@ namespace ehs
|
||||
return *this;
|
||||
}
|
||||
|
||||
NetSystem& NetSystem::operator=(const NetSystem& sys)
|
||||
NetSys& NetSys::operator=(const NetSys& sys)
|
||||
{
|
||||
if (this == &sys)
|
||||
return *this;
|
||||
@@ -60,17 +60,17 @@ namespace ehs
|
||||
return *this;
|
||||
}
|
||||
|
||||
Str_8 NetSystem::GetId() const
|
||||
Str_8 NetSys::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
UInt_64 NetSystem::GetHashId() const
|
||||
UInt_64 NetSys::GetHashId() const
|
||||
{
|
||||
return hashId;
|
||||
}
|
||||
|
||||
bool NetSystem::HasOperation(const UInt_64 hashId) const
|
||||
bool NetSys::HasOperation(const UInt_64 hashId) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < ops.Size(); ++i)
|
||||
if (ops[i]->GetHashId() == hashId)
|
||||
@@ -79,7 +79,7 @@ namespace ehs
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetSystem::AddOperation(NetOp* op)
|
||||
bool NetSys::AddOperation(NetOp* op)
|
||||
{
|
||||
if (HasOperation(op->GetHashId()))
|
||||
return false;
|
||||
@@ -89,7 +89,7 @@ namespace ehs
|
||||
return true;
|
||||
}
|
||||
|
||||
void NetSystem::Execute(EHC *ehc, NetEnd *endpoint, const UInt_64 hashId, Serializer<UInt_64> &payload)
|
||||
void NetSys::Execute(EHC *ehc, NetEnd *endpoint, const UInt_64 hashId, Serializer<UInt_64> &payload)
|
||||
{
|
||||
for (UInt_64 i = 0; i < ops.Size(); ++i)
|
||||
{
|
Reference in New Issue
Block a user