Finished implementing, now for the testing phase.
This commit is contained in:
@@ -1,53 +1,46 @@
|
||||
#include "ehs/io/socket/ehc/NetEnd.h"
|
||||
#include "ehs/io/socket/EHC.h"
|
||||
#include "ehs/io/socket/ehc/NetEnc.h"
|
||||
#include "ehs/io/socket/ehc/NetServerCh.h"
|
||||
#include "ehs/system/CPU.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
NetEnd::NetEnd()
|
||||
: owner(nullptr), disposition(EndDisp::ENDPOINT), hashName(0), status(Status::PENDING),
|
||||
arch(Architecture::UNKNOWN), token{}, nextSendId(0), nextRecvId(0), type(AddrType::IPV6), port(0),
|
||||
deltaDuration(0.0f), deltaRate(1.0f / 60.0f), timeout(0.0f), lastPing(0.0f), oldLatency(0.0f), latency(0.0f),
|
||||
queueSlot(0)
|
||||
{
|
||||
}
|
||||
|
||||
NetEnd::NetEnd(const EndDisp disposition, Str_8 id, const Architecture arch, const AddrType type,
|
||||
Str_8 address, const UInt_16 port)
|
||||
: owner(nullptr), disposition(disposition), hashName(id.Hash_64()), name((Str_8&&)id), status(Status::ACTIVE),
|
||||
arch(arch), token{}, nextSendId(0), nextRecvId(0), type(type), address((Str_8&&)address), port(port),
|
||||
deltaDuration(0.0f), deltaRate(1.0f / 60.0f), timeout(0.0f), lastPing(0.0f), oldLatency(0.0f), latency(0.0f),
|
||||
queueSlot(0)
|
||||
{
|
||||
}
|
||||
|
||||
NetEnd::NetEnd(const AddrType type, Str_8 address, const UInt_16 port)
|
||||
: owner(nullptr), disposition(EndDisp::ENDPOINT), hashName(0), status(Status::PENDING),
|
||||
arch(Architecture::UNKNOWN), token{}, nextSendId(0), nextRecvId(0), type(type), address((Str_8&&)address),
|
||||
port(port), deltaDuration(0.0f), deltaRate(1.0f / 60.0f), timeout(0.0f), lastPing(0.0f), oldLatency(0.0f),
|
||||
: owner(nullptr), id(0), status(NetStatus::PENDING), token{}, nextSendId(0), nextRecvId(0),
|
||||
deltaDuration(0.0f), deltaRate(1.0f / 60.0f), timeout(0.0f), lastPing(0.0f), oldLatency(0.0f),
|
||||
latency(0.0f), queueSlot(0)
|
||||
{
|
||||
}
|
||||
|
||||
NetEnd::NetEnd(Str_8 id, Endpoint endpoint)
|
||||
: owner(nullptr), id(id.Hash_64()), name((Str_8&&)id), status(NetStatus::ACTIVE), token{}, nextSendId(0),
|
||||
nextRecvId(0), endpoint((Endpoint &&)endpoint), deltaDuration(0.0f), deltaRate(1.0f / 60.0f),
|
||||
timeout(0.0f), lastPing(0.0f), oldLatency(0.0f), latency(0.0f), queueSlot(0)
|
||||
{
|
||||
}
|
||||
|
||||
NetEnd::NetEnd(Endpoint endpoint)
|
||||
: owner(nullptr), id(0), status(NetStatus::PENDING), token{}, nextSendId(0), nextRecvId(0),
|
||||
endpoint((Endpoint &&)endpoint), deltaDuration(0.0f), deltaRate(1.0f / 60.0f), timeout(0.0f), lastPing(0.0f),
|
||||
oldLatency(0.0f), latency(0.0f), queueSlot(0)
|
||||
{
|
||||
}
|
||||
|
||||
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{},
|
||||
: owner(end.owner), id(end.id), name((Str_8&&)end.name), status(end.status), token{},
|
||||
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),
|
||||
received((Vector<NetFrag>&&)end.received), endpoint((Endpoint &&)end.endpoint),
|
||||
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;
|
||||
end.hashName = 0;
|
||||
end.status = Status::PENDING;
|
||||
end.arch = Architecture::UNKNOWN;
|
||||
end.id = 0;
|
||||
end.status = NetStatus::PENDING;
|
||||
Util::Copy(token, end.token, 64);
|
||||
Util::Zero(end.token, 64);
|
||||
end.nextSendId = 0;
|
||||
end.nextRecvId = 0;
|
||||
end.type = AddrType::IPV6;
|
||||
end.port = 0;
|
||||
end.deltaDuration = 0.0f;
|
||||
end.deltaRate = 1.0f / 60.0f;
|
||||
end.timeout = 0.0f;
|
||||
@@ -58,9 +51,9 @@ namespace ehs
|
||||
}
|
||||
|
||||
NetEnd::NetEnd(const NetEnd& end)
|
||||
: owner(nullptr), disposition(EndDisp::ENDPOINT), hashName(end.hashName), name(end.name), status(Status::PENDING), arch(Architecture::UNKNOWN),
|
||||
token{}, nextSendId(0), nextRecvId(0), type(end.type), port(0), deltaDuration(0.0f), deltaRate(1.0f / 60.0f),
|
||||
timeout(0.0f), lastPing(0.0f), oldLatency(0.0f), latency(0.0f), queueSlot(0)
|
||||
: owner(nullptr), id(end.id), name(end.name), status(NetStatus::PENDING), token{}, nextSendId(0),
|
||||
nextRecvId(0), deltaDuration(0.0f), deltaRate(1.0f / 60.0f), timeout(0.0f), lastPing(0.0f), oldLatency(0.0f),
|
||||
latency(0.0f), queueSlot(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -70,19 +63,15 @@ namespace ehs
|
||||
return *this;
|
||||
|
||||
owner = end.owner;
|
||||
disposition = end.disposition;
|
||||
hashName = end.hashName;
|
||||
id = end.id;
|
||||
name = (Str_8&&)end.name;
|
||||
status = end.status;
|
||||
arch = end.arch;
|
||||
Util::Copy(token, end.token, 64);
|
||||
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;
|
||||
received = (Vector<NetFrag>&&)end.received;
|
||||
endpoint = (Endpoint &&)end.endpoint;
|
||||
deltaDuration = end.deltaDuration;
|
||||
deltaRate = end.deltaRate;
|
||||
timeout = end.timeout;
|
||||
@@ -92,15 +81,11 @@ namespace ehs
|
||||
queueSlot = end.queueSlot;
|
||||
|
||||
end.owner = nullptr;
|
||||
end.disposition = EndDisp::ENDPOINT;
|
||||
end.hashName = 0;
|
||||
end.status = Status::PENDING;
|
||||
end.arch = Architecture::UNKNOWN;
|
||||
end.id = 0;
|
||||
end.status = NetStatus::PENDING;
|
||||
Util::Zero(end.token, 64);
|
||||
end.nextSendId = 0;
|
||||
end.nextRecvId = 0;
|
||||
end.type = AddrType::IPV6;
|
||||
end.port = 0;
|
||||
end.deltaDuration = 0.0f;
|
||||
end.deltaRate = 1.0f / 60.0f;
|
||||
end.timeout = 0.0f;
|
||||
@@ -118,19 +103,15 @@ namespace ehs
|
||||
return *this;
|
||||
|
||||
owner = nullptr;
|
||||
disposition = EndDisp::ENDPOINT;
|
||||
hashName = end.hashName;
|
||||
id = end.id;
|
||||
name = end.name;
|
||||
status = Status::PENDING;
|
||||
arch = Architecture::UNKNOWN;
|
||||
status = NetStatus::PENDING;
|
||||
Util::Zero(token, 64);
|
||||
nextSendId = 0;
|
||||
sent = {};
|
||||
nextRecvId = 0;
|
||||
received = {};
|
||||
type = AddrType::IPV6;
|
||||
address = {};
|
||||
port = 0;
|
||||
endpoint = {};
|
||||
deltaDuration = 0.0f;
|
||||
deltaRate = 1.0f / 60.0f;
|
||||
timeout = 0.0f;
|
||||
@@ -142,14 +123,9 @@ namespace ehs
|
||||
return *this;
|
||||
}
|
||||
|
||||
EndDisp NetEnd::GetDisposition() const
|
||||
UInt_64 NetEnd::GetId() const
|
||||
{
|
||||
return disposition;
|
||||
}
|
||||
|
||||
UInt_64 NetEnd::GetHashName() const
|
||||
{
|
||||
return hashName;
|
||||
return id;
|
||||
}
|
||||
|
||||
Str_8 NetEnd::GetName() const
|
||||
@@ -157,44 +133,54 @@ namespace ehs
|
||||
return name;
|
||||
}
|
||||
|
||||
Status NetEnd::GetStatus() const
|
||||
NetStatus NetEnd::GetStatus() const
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
Architecture NetEnd::GetArchitecture() const
|
||||
{
|
||||
return arch;
|
||||
}
|
||||
|
||||
UInt_64 NetEnd::GetNextSendId() const
|
||||
{
|
||||
return nextSendId;
|
||||
}
|
||||
|
||||
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)
|
||||
void NetEnd::Send(const bool deltaLocked, const UInt_64 encId, const bool ensure, const UInt_64 sysId,
|
||||
const UInt_64 opId, const Serializer<UInt_64> &payload)
|
||||
{
|
||||
if (deltaLocked && deltaDuration < deltaRate)
|
||||
if (!owner || !owner->GetOwner() || (deltaLocked && deltaDuration < deltaRate))
|
||||
return;
|
||||
|
||||
EHC *ehc = owner->GetOwner();
|
||||
|
||||
NetEnc *enc = ehc->GetEncryption(encId);
|
||||
if (!enc)
|
||||
{
|
||||
EHS_LOG_INT(LogType::WARN, 0, "Encryption with the Id, \"" + Str_8::FromNum(encId) + "\", does not exist.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Header header = {
|
||||
encHashId,
|
||||
nextSendId++,
|
||||
1,
|
||||
0,
|
||||
ensure,
|
||||
owner->GetDisposition(),
|
||||
"",
|
||||
sys,
|
||||
op
|
||||
EHC::GetVersion(),
|
||||
encId,
|
||||
enc->GetVersion(),
|
||||
GetId(),
|
||||
NetChannelType::SERVER,
|
||||
GetVersion(),
|
||||
nextSendId++,
|
||||
1,
|
||||
0,
|
||||
ensure,
|
||||
"",
|
||||
sysId,
|
||||
opId
|
||||
};
|
||||
|
||||
Util::Copy(header.token, token, 64);
|
||||
|
||||
if ((owner->GetLocalAddressType() == AddrType::IPV6 && payload.Size() > EHC_IPV6_PAYLOAD) || (owner->GetLocalAddressType() == AddrType::IPV4 && payload.Size() > EHC_IPV4_PAYLOAD))
|
||||
if ((ehc->GetLocalEndpoint().version == IP::V6 && payload.Size() > EHC_IPV6_PAYLOAD) ||
|
||||
(ehc->GetLocalEndpoint().version == IP::V4 && payload.Size() > EHC_IPV4_PAYLOAD))
|
||||
{
|
||||
NetFrags frags = FragmentData(header, payload);
|
||||
NetFrag frags = FragmentData(header, payload);
|
||||
for (UInt_64 i = 0; i < frags.Size(); ++i)
|
||||
{
|
||||
Header newHeader = frags.GetHeader();
|
||||
@@ -209,10 +195,10 @@ namespace ehs
|
||||
}
|
||||
}
|
||||
|
||||
void NetEnd::Send(const bool deltaLocked, const Str_8 &encId, const bool ensure, const Str_8& sys,
|
||||
const Str_8& op, const Serializer<>& payload)
|
||||
void NetEnd::Send(const bool deltaLocked, const Str_8 &encName, const bool ensure, const Str_8& sysName,
|
||||
const Str_8& opName, const Serializer<>& payload)
|
||||
{
|
||||
Send(deltaLocked, encId.Hash_64(), ensure, sys.Hash_64(), op.Hash_64(), payload);
|
||||
Send(deltaLocked, encName.Hash_64(), ensure, sysName.Hash_64(), opName.Hash_64(), payload);
|
||||
}
|
||||
|
||||
UInt_64 NetEnd::GetNextRecvId() const
|
||||
@@ -220,14 +206,9 @@ namespace ehs
|
||||
return nextRecvId;
|
||||
}
|
||||
|
||||
Str_8 NetEnd::GetAddress() const
|
||||
Endpoint NetEnd::GetEndpoint() const
|
||||
{
|
||||
return address;
|
||||
}
|
||||
|
||||
UInt_16 NetEnd::GetPort() const
|
||||
{
|
||||
return port;
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
float NetEnd::GetDeltaRate() const
|
||||
@@ -273,17 +254,21 @@ namespace ehs
|
||||
sent[i].lastResend += delta;
|
||||
if (sent[i].lastResend >= owner->GetResendRate())
|
||||
{
|
||||
EHC *ehc = owner->GetOwner();
|
||||
|
||||
Serializer result(Endianness::LE);
|
||||
result.Write(sent[i].header);
|
||||
result.WriteSer(sent[i].payload);
|
||||
|
||||
if (sent[i].header.encHashId)
|
||||
if (sent[i].header.encId)
|
||||
{
|
||||
NetEnc *enc = owner->GetEncryption(sent[i].header.encHashId);
|
||||
|
||||
|
||||
NetEnc *enc = ehc->GetEncryption(sent[i].header.encId);
|
||||
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.");
|
||||
Str_8::FromNum(sent[i].header.encId) + ", does not exist.");
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -291,24 +276,21 @@ namespace ehs
|
||||
enc->Encrypt(&result[sizeof(bool)], result.Size() - sizeof(bool));
|
||||
}
|
||||
|
||||
owner->udp.Send(type, address, port, result, result.Size());
|
||||
ehc->udp.Send(endpoint, result, result.Size());
|
||||
|
||||
sent[i].lastResend = Math::Mod(sent[i].lastResend, owner->GetResendRate());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (owner->GetDisposition() == EndDisp::SERVICE)
|
||||
{
|
||||
lastPing += delta;
|
||||
if (lastPing >= 1.0f)
|
||||
Ping(delta);
|
||||
}
|
||||
lastPing += delta;
|
||||
if (lastPing >= 1.0f)
|
||||
Ping(delta);
|
||||
|
||||
EHS_LOG_SUCCESS();
|
||||
}
|
||||
|
||||
void NetEnd::SetStatus(const Status newStatus)
|
||||
void NetEnd::SetStatus(const NetStatus newStatus)
|
||||
{
|
||||
status = newStatus;
|
||||
}
|
||||
@@ -329,7 +311,7 @@ namespace ehs
|
||||
|
||||
void NetEnd::AddReceived(const Header& header, const Serializer<>& payload)
|
||||
{
|
||||
NetFrags* frags = nullptr;
|
||||
NetFrag* frags = nullptr;
|
||||
|
||||
for (UInt_64 i = 0; i < received.Size(); ++i)
|
||||
{
|
||||
@@ -354,7 +336,7 @@ namespace ehs
|
||||
timeout = 0.0f;
|
||||
}
|
||||
|
||||
Vector<NetFrags>* NetEnd::GetReceived()
|
||||
Vector<NetFrag>* NetEnd::GetReceived()
|
||||
{
|
||||
return &received;
|
||||
}
|
||||
@@ -374,16 +356,6 @@ namespace ehs
|
||||
latency = 0.0f;
|
||||
}
|
||||
|
||||
void NetEnd::Pong(const float delta)
|
||||
{
|
||||
Serializer payload(Endianness::LE);
|
||||
payload.Write(delta);
|
||||
|
||||
Send(false, true, false, "Internal", "Pong", payload);
|
||||
|
||||
timeout = 0.0f;
|
||||
}
|
||||
|
||||
void NetEnd::SendLatency()
|
||||
{
|
||||
oldLatency = latency * 1000;
|
||||
@@ -407,17 +379,19 @@ namespace ehs
|
||||
queueSlot = slot;
|
||||
}
|
||||
|
||||
NetFrags NetEnd::FragmentData(const Header& header, const Serializer<>& data)
|
||||
NetFrag NetEnd::FragmentData(const Header& header, const Serializer<>& data)
|
||||
{
|
||||
NetFrags result;
|
||||
NetFrag result;
|
||||
|
||||
if (owner->GetLocalAddressType() == AddrType::IPV6)
|
||||
EHC *ehc = owner->GetOwner();
|
||||
|
||||
if (ehc->GetLocalEndpoint().version == IP::V6)
|
||||
{
|
||||
UInt_64 frags = data.Size() / EHC_IPV6_PAYLOAD;
|
||||
if (data.Size() % EHC_IPV6_PAYLOAD)
|
||||
++frags;
|
||||
|
||||
result = NetFrags(header, frags);
|
||||
result = NetFrag(header, frags);
|
||||
|
||||
UInt_64 size = EHC_IPV6_PAYLOAD;
|
||||
|
||||
@@ -430,13 +404,13 @@ namespace ehs
|
||||
result[i] = {data.GetEndianness(), &data[i * EHC_IPV6_PAYLOAD], size};
|
||||
}
|
||||
}
|
||||
else if (owner->GetLocalAddressType() == AddrType::IPV4)
|
||||
else if (ehc->GetLocalEndpoint().version == IP::V4)
|
||||
{
|
||||
UInt_64 frags = data.Size() / EHC_IPV4_PAYLOAD;
|
||||
if (data.Size() % EHC_IPV4_PAYLOAD)
|
||||
++frags;
|
||||
|
||||
result = NetFrags(header, frags);
|
||||
result = NetFrag(header, frags);
|
||||
|
||||
UInt_64 size = EHC_IPV4_PAYLOAD;
|
||||
|
||||
@@ -455,17 +429,19 @@ namespace ehs
|
||||
|
||||
void NetEnd::Send(const Header& header, const Serializer<UInt_64>& payload)
|
||||
{
|
||||
EHC *ehc = owner->GetOwner();
|
||||
|
||||
Serializer result(Endianness::LE);
|
||||
result.Write(header);
|
||||
result.WriteSer(payload);
|
||||
|
||||
if (header.encHashId)
|
||||
if (header.encId)
|
||||
{
|
||||
NetEnc *enc = owner->GetEncryption(header.encHashId);
|
||||
NetEnc *enc = ehc->GetEncryption(header.encId);
|
||||
if (!enc)
|
||||
{
|
||||
EHS_LOG_INT(LogType::WARN, 0, "The network encryption with the hash id " +
|
||||
Str_8::FromNum(header.encHashId) + ", does not exist.");
|
||||
Str_8::FromNum(header.encId) + ", does not exist.");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -476,7 +452,7 @@ namespace ehs
|
||||
if (header.ensure)
|
||||
sent.Push({header, payload});
|
||||
|
||||
owner->udp.Send(type, address, port, result, result.Size());
|
||||
ehc->udp.Send(endpoint, result, result.Size());
|
||||
}
|
||||
|
||||
bool NetEnd::SortingNeeded() const
|
||||
@@ -499,7 +475,7 @@ namespace ehs
|
||||
if (!SortingNeeded())
|
||||
return;
|
||||
|
||||
Vector<NetFrags> sorted(0, received.Stride());
|
||||
Vector<NetFrag> sorted(0, received.Stride());
|
||||
|
||||
for (UInt_64 a = 0; a < received.Size(); ++a)
|
||||
{
|
||||
|
Reference in New Issue
Block a user