Finished implementing, now for the testing phase.
This commit is contained in:
183
src/io/socket/ehc/NetChannel.cpp
Normal file
183
src/io/socket/ehc/NetChannel.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
#include "ehs/io/socket/ehc/NetChannel.h"
|
||||
#include "ehs/io/socket/ehc/NetEnd.h"
|
||||
#include "ehs/io/socket/ehc/NetSys.h"
|
||||
#include "ehs/io/socket/EHC.h"
|
||||
#include "ehs/PRNG.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
const UInt_64 NetChannel::internalSys = Str_8::Hash_64("Internal");
|
||||
|
||||
NetChannel::~NetChannel()
|
||||
{
|
||||
}
|
||||
|
||||
NetChannel::NetChannel()
|
||||
: owner(nullptr), id(0), maxTimeout(5.0f), resendRate(0.5f)
|
||||
{
|
||||
}
|
||||
|
||||
NetChannel::NetChannel(Str_8 name, const Version &version)
|
||||
: owner(nullptr), id(name.Hash_64()), name((Str_8 &&)name), version(version), maxTimeout(5.0f),
|
||||
resendRate(0.5f)
|
||||
{
|
||||
}
|
||||
|
||||
NetChannel::NetChannel(NetChannel &&channel) noexcept
|
||||
: owner(channel.owner), id(channel.id), name((Str_8 &&)channel.name), version(channel.version),
|
||||
maxTimeout(channel.maxTimeout), resendRate(channel.resendRate)
|
||||
{
|
||||
channel.owner = nullptr;
|
||||
channel.id = 0;
|
||||
channel.version = {};
|
||||
channel.maxTimeout = 5.0f;
|
||||
channel.resendRate = 0.5f;
|
||||
}
|
||||
|
||||
NetChannel::NetChannel(const NetChannel &channel)
|
||||
: owner(nullptr), id(channel.id), name(channel.name), version(channel.version),
|
||||
maxTimeout(channel.maxTimeout), resendRate(channel.resendRate)
|
||||
{
|
||||
}
|
||||
|
||||
NetChannel &NetChannel::operator=(NetChannel &&channel) noexcept
|
||||
{
|
||||
if (this == &channel)
|
||||
return *this;
|
||||
|
||||
owner = channel.owner;
|
||||
id = channel.id;
|
||||
name = (Str_8 &&)channel.name;
|
||||
version = channel.version;
|
||||
maxTimeout = channel.maxTimeout;
|
||||
resendRate = channel.resendRate;
|
||||
|
||||
channel.owner = nullptr;
|
||||
channel.id = 0;
|
||||
channel.version = {};
|
||||
channel.maxTimeout = 5.0f;
|
||||
channel.resendRate = 0.5f;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NetChannel &NetChannel::operator=(const NetChannel &channel)
|
||||
{
|
||||
if (this == &channel)
|
||||
return *this;
|
||||
|
||||
owner = nullptr;
|
||||
id = channel.id;
|
||||
name = channel.name;
|
||||
version = channel.version;
|
||||
maxTimeout = channel.maxTimeout;
|
||||
resendRate = channel.resendRate;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
EHC *NetChannel::GetOwner() const
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
|
||||
UInt_64 NetChannel::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
Str_8 NetChannel::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
Version NetChannel::GetVersion() const
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
void NetChannel::SetMaxTimeout(const float seconds)
|
||||
{
|
||||
maxTimeout = seconds;
|
||||
}
|
||||
|
||||
float NetChannel::GetMaxTimeout() const
|
||||
{
|
||||
return maxTimeout;
|
||||
}
|
||||
|
||||
void NetChannel::SetResendRate(const float seconds)
|
||||
{
|
||||
resendRate = seconds;
|
||||
}
|
||||
|
||||
float NetChannel::GetResendRate() const
|
||||
{
|
||||
return resendRate;
|
||||
}
|
||||
|
||||
void NetChannel::EnableDropPackets(const bool enable)
|
||||
{
|
||||
dropPackets = enable;
|
||||
}
|
||||
|
||||
bool NetChannel::IsDropPacketsEnabled() const
|
||||
{
|
||||
return dropPackets;
|
||||
}
|
||||
|
||||
bool NetChannel::AddSystem(NetSys *sys)
|
||||
{
|
||||
if (sys->GetHashId() == internalSys)
|
||||
return false;
|
||||
|
||||
if (HasSystem(sys->GetHashId()))
|
||||
return false;
|
||||
|
||||
systems.Push(sys);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NetChannel::IsValid() const
|
||||
{
|
||||
return owner && id;
|
||||
}
|
||||
|
||||
void NetChannel::Process(const float &delta, const Endpoint &endpoint, const Header &header, Serializer<UInt_64> &payload)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NetChannel::Poll(const float &delta)
|
||||
{
|
||||
}
|
||||
|
||||
bool NetChannel::HasSystem(const UInt_64 sysHashId) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < systems.Size(); ++i)
|
||||
if (systems[i]->GetHashId() == sysHashId)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetChannel::HasSystem(const Str_8& sysId) const
|
||||
{
|
||||
return HasSystem(sysId.Hash_64());
|
||||
}
|
||||
|
||||
NetSys* NetChannel::GetSystem(const UInt_64 sysHashId) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < systems.Size(); ++i)
|
||||
if (systems[i]->GetHashId() == sysHashId)
|
||||
return systems[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NetSys* NetChannel::GetSystem(const Str_8& sysId) const
|
||||
{
|
||||
return GetSystem(sysId.Hash_64());
|
||||
}
|
||||
}
|
||||
385
src/io/socket/ehc/NetClientCh.cpp
Normal file
385
src/io/socket/ehc/NetClientCh.cpp
Normal file
@@ -0,0 +1,385 @@
|
||||
#include "ehs/io/socket/ehc/NetClientCh.h"
|
||||
#include "ehs/io/socket/EHC.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
NetClientCh::~NetClientCh()
|
||||
{
|
||||
}
|
||||
|
||||
NetClientCh::NetClientCh()
|
||||
: token{}, status(NetStatus::DISCONNECTED), queueSlot(0), deltaDuration(0.0f), deltaRate(0.0f), lastPing(0.0f),
|
||||
latency(0.0f), timeout(5.0f), nextSendId(0), nextRecvId(0)
|
||||
{
|
||||
}
|
||||
|
||||
NetClientCh::NetClientCh(Str_8 name, const Version &version, Endpoint remoteEndpoint)
|
||||
: NetChannel((Str_8 &&)name, version), remoteEndpoint((Endpoint &&)remoteEndpoint), token{},
|
||||
status(NetStatus::DISCONNECTED), queueSlot(0), deltaDuration(0.0f), deltaRate(0.0f), lastPing(0.0f),
|
||||
latency(0.0f), timeout(0.0f), nextSendId(0), nextRecvId(0)
|
||||
{
|
||||
}
|
||||
|
||||
NetClientCh::NetClientCh(NetClientCh &&client) noexcept
|
||||
: NetChannel((NetChannel &&)client), remoteEndpoint((Endpoint &&)client.remoteEndpoint), token{},
|
||||
status(client.status), queueSlot(client.queueSlot), deltaDuration(0.0f), deltaRate(0.0f), lastPing(0.0f),
|
||||
latency(0.0f), timeout(0.0f), nextSendId(0), sent((Vector<Insurance> &&)client.sent), nextRecvId(0),
|
||||
received((Vector<NetFrag> &&)client.received)
|
||||
{
|
||||
Util::Copy(token, client.token, 64);
|
||||
|
||||
Util::Zero(client.token, 64);
|
||||
client.status = NetStatus::DISCONNECTED;
|
||||
client.queueSlot = 0;
|
||||
client.deltaDuration = 0.0f;
|
||||
client.deltaRate = 0.0f;
|
||||
client.lastPing = 0.0f;
|
||||
client.latency = 0.0f;
|
||||
client.timeout = 0.0f;
|
||||
client.nextSendId = 0;
|
||||
client.nextRecvId = 0;
|
||||
}
|
||||
|
||||
NetClientCh::NetClientCh(const NetClientCh &client)
|
||||
: NetChannel(client), remoteEndpoint(client.remoteEndpoint), token{}, status(NetStatus::DISCONNECTED),
|
||||
queueSlot(0), deltaDuration(0.0f), deltaRate(0.0f), lastPing(0.0f), latency(0.0f), timeout(0.0f), nextSendId(0),
|
||||
nextRecvId(0)
|
||||
{
|
||||
}
|
||||
|
||||
NetClientCh & NetClientCh::operator=(NetClientCh &&client) noexcept
|
||||
{
|
||||
if (this == &client)
|
||||
return *this;
|
||||
|
||||
NetChannel::operator=((NetChannel &&)client);
|
||||
|
||||
remoteEndpoint = (Endpoint &&)client.remoteEndpoint;
|
||||
Util::Copy(token, client.token, 64);
|
||||
status = client.status;
|
||||
queueSlot = client.queueSlot;
|
||||
deltaDuration = client.deltaDuration;
|
||||
deltaRate = client.deltaRate;
|
||||
lastPing = client.lastPing;
|
||||
latency = client.latency;
|
||||
timeout = client.timeout;
|
||||
nextSendId = client.nextSendId;
|
||||
sent = (Vector<Insurance> &&)client.sent;
|
||||
nextRecvId = client.nextRecvId;
|
||||
received = (Vector<NetFrag> &&)client.received;
|
||||
|
||||
Util::Zero(client.token, 64);
|
||||
client.status = NetStatus::DISCONNECTED;
|
||||
client.queueSlot = 0;
|
||||
client.deltaDuration = 0.0f;
|
||||
client.deltaRate = 0.0f;
|
||||
client.lastPing = 0.0f;
|
||||
client.latency = 0.0f;
|
||||
client.timeout = 0.0f;
|
||||
client.nextSendId = 0;
|
||||
client.nextRecvId = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NetClientCh & NetClientCh::operator=(const NetClientCh &client)
|
||||
{
|
||||
if (this == &client)
|
||||
return *this;
|
||||
|
||||
remoteEndpoint = client.remoteEndpoint;
|
||||
Util::Zero(token, 64);
|
||||
status = NetStatus::DISCONNECTED;
|
||||
queueSlot = 0;
|
||||
deltaDuration = 0.0f;
|
||||
deltaRate = 0.0f;
|
||||
lastPing = 0.0f;
|
||||
latency = 0.0f;
|
||||
timeout = 0.0f;
|
||||
nextSendId = 0;
|
||||
sent = {};
|
||||
nextRecvId = 0;
|
||||
received = {};
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void NetClientCh::OnConnected(Serializer<UInt_64> data)
|
||||
{
|
||||
}
|
||||
|
||||
void NetClientCh::OnActive(Serializer<UInt_64> data)
|
||||
{
|
||||
}
|
||||
|
||||
void NetClientCh::OnQueueUpdate(Serializer<UInt_64> data)
|
||||
{
|
||||
}
|
||||
|
||||
void NetClientCh::OnDisconnected(Serializer<UInt_64> data)
|
||||
{
|
||||
}
|
||||
|
||||
void NetClientCh::OnRejected(Serializer<UInt_64> data)
|
||||
{
|
||||
}
|
||||
|
||||
void NetClientCh::OnTimeout(Serializer<UInt_64> data)
|
||||
{
|
||||
}
|
||||
|
||||
void NetClientCh::Connect(const Endpoint &endpoint, const Serializer<UInt_64> &payload)
|
||||
{
|
||||
if (!GetOwner()->udp.IsValid())
|
||||
return;
|
||||
|
||||
Send(false, true, false, internalSys, connectOp, payload);
|
||||
|
||||
status = NetStatus::PENDING;
|
||||
}
|
||||
|
||||
bool NetClientCh::Disconnect(const Serializer<UInt_64> &payload)
|
||||
{
|
||||
if (!GetOwner()->udp.IsValid())
|
||||
return false;
|
||||
|
||||
Send(false, true, false, internalSys, disconnectOp, payload);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NetClientCh::Send(const bool deltaLocked, UInt_64 encId, const bool ensure, UInt_64 sysId, UInt_64 opId,
|
||||
const Serializer<UInt_64> &payload)
|
||||
{
|
||||
if (!IsValid() || (deltaLocked && deltaDuration < deltaRate))
|
||||
return;
|
||||
|
||||
const EHC *owner = GetOwner();
|
||||
|
||||
NetEnc *enc = owner->GetEncryption(encId);
|
||||
if (!enc)
|
||||
{
|
||||
EHS_LOG_INT(LogType::WARN, 0, "Encryption with the Id, \"" + Str_8::FromNum(encId) + "\", does not exist.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Header header = {
|
||||
EHC::GetVersion(),
|
||||
encId,
|
||||
enc->GetVersion(),
|
||||
GetId(),
|
||||
NetChannelType::SERVER,
|
||||
GetVersion(),
|
||||
nextSendId++,
|
||||
1,
|
||||
0,
|
||||
ensure,
|
||||
"",
|
||||
sysId,
|
||||
opId
|
||||
};
|
||||
|
||||
Util::Copy(header.token, token, 64);
|
||||
|
||||
const Endpoint localEndpoint = owner->GetLocalEndpoint();
|
||||
|
||||
if ((localEndpoint.version == IP::V6 && payload.Size() > EHC_IPV6_PAYLOAD) || (localEndpoint.version == IP::V4 && payload.Size() > EHC_IPV4_PAYLOAD))
|
||||
{
|
||||
NetFrag frags = FragmentData(localEndpoint.version, header, payload);
|
||||
for (UInt_64 i = 0; i < frags.Size(); ++i)
|
||||
{
|
||||
Header newHeader = frags.GetHeader();
|
||||
newHeader.fragment = i;
|
||||
|
||||
Send(enc, newHeader, frags[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Send(enc, header, payload);
|
||||
}
|
||||
}
|
||||
|
||||
void NetClientCh::Send(const bool deltaLocked, const Str_8 &encName, const bool ensure, const Str_8 &sysName,
|
||||
const Str_8 &opName, const Serializer<UInt_64> &payload)
|
||||
{
|
||||
Send(deltaLocked, encName.Hash_64(), ensure, sysName.Hash_64(), opName.Hash_64(), payload);
|
||||
}
|
||||
|
||||
NetStatus NetClientCh::GetStatus() const
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
void NetClientCh::Process(const float &delta, const Endpoint &endpoint, const Header &header, Serializer<UInt_64> &payload)
|
||||
{
|
||||
if (!Util::Compare(token, header.token, 64))
|
||||
return;
|
||||
|
||||
if (!header.ensure && header.token[0] && header.systemId == internalSys && header.opId == connectedOp)
|
||||
{
|
||||
if (status != NetStatus::PENDING)
|
||||
return;
|
||||
|
||||
Util::Copy(token, header.token, 64);
|
||||
|
||||
status = payload.Read<NetStatus>();
|
||||
queueSlot = payload.Read<UInt_64>();
|
||||
|
||||
OnConnected({Endianness::LE, &payload[payload.GetOffset()], payload.Size() - payload.GetOffset()});
|
||||
}
|
||||
else if (!header.ensure && header.token[0] && header.systemId == internalSys && header.opId == disconnectedOp)
|
||||
{
|
||||
OnDisconnected({Endianness::LE, &payload[payload.GetOffset()], payload.Size() - payload.GetOffset()});
|
||||
}
|
||||
else if (!header.ensure && header.token[0] && header.systemId == internalSys && header.opId == rejectedOp)
|
||||
{
|
||||
OnRejected({Endianness::LE, &payload[payload.GetOffset()], payload.Size() - payload.GetOffset()});
|
||||
}
|
||||
else if (!header.ensure && header.token[0] && header.systemId == internalSys && header.opId == statusUpdateOp)
|
||||
{
|
||||
const NetStatus newStatus = payload.Read<NetStatus>();
|
||||
queueSlot = payload.Read<UInt_64>();
|
||||
|
||||
if (status == NetStatus::ACTIVE)
|
||||
OnActive({Endianness::LE, &payload[payload.GetOffset()], payload.Size() - payload.GetOffset()});
|
||||
else if (status == NetStatus::QUEUED && newStatus == NetStatus::QUEUED)
|
||||
OnQueueUpdate({Endianness::LE, &payload[payload.GetOffset()], payload.Size() - payload.GetOffset()});
|
||||
|
||||
status = newStatus;
|
||||
}
|
||||
else if (!header.ensure && header.token[0] && header.systemId == internalSys && header.opId == receivedOp)
|
||||
{
|
||||
const UInt_64 msgId = payload.Read<UInt_64>();
|
||||
const UInt_64 fragment = payload.Read<UInt_64>();
|
||||
|
||||
RemoveInsurance(msgId, fragment);
|
||||
}
|
||||
else if (!header.ensure && header.token[0] && header.systemId == internalSys && header.opId == pingOp)
|
||||
{
|
||||
deltaRate = payload.Read<float>();
|
||||
|
||||
Pong(delta);
|
||||
}
|
||||
else if (!header.ensure && header.token[0] && header.systemId == internalSys && header.opId == latencyOp)
|
||||
{
|
||||
latency = payload.Read<float>();
|
||||
}
|
||||
}
|
||||
|
||||
void NetClientCh::Poll(const float &delta)
|
||||
{
|
||||
}
|
||||
|
||||
NetFrag NetClientCh::FragmentData(const IP version, const Header& header, const Serializer<>& data)
|
||||
{
|
||||
NetFrag result;
|
||||
|
||||
if (version == IP::V6)
|
||||
{
|
||||
UInt_64 frags = data.Size() / EHC_IPV6_PAYLOAD;
|
||||
if (data.Size() % EHC_IPV6_PAYLOAD)
|
||||
++frags;
|
||||
|
||||
result = NetFrag(header, frags);
|
||||
|
||||
UInt_64 size = EHC_IPV6_PAYLOAD;
|
||||
|
||||
for (UInt_64 i = 0; i < result.Size(); ++i)
|
||||
{
|
||||
size = EHC_IPV6_PAYLOAD;
|
||||
if (i == result.Size() - 1)
|
||||
size = data.Size() % EHC_IPV6_PAYLOAD;
|
||||
|
||||
result[i] = {data.GetEndianness(), &data[i * EHC_IPV6_PAYLOAD], size};
|
||||
}
|
||||
}
|
||||
else if (version == IP::V4)
|
||||
{
|
||||
UInt_64 frags = data.Size() / EHC_IPV4_PAYLOAD;
|
||||
if (data.Size() % EHC_IPV4_PAYLOAD)
|
||||
++frags;
|
||||
|
||||
result = NetFrag(header, frags);
|
||||
|
||||
UInt_64 size = EHC_IPV4_PAYLOAD;
|
||||
|
||||
for (UInt_64 i = 0; i < result.Size(); ++i)
|
||||
{
|
||||
size = EHC_IPV4_PAYLOAD;
|
||||
if (i == result.Size() - 1)
|
||||
size = data.Size() % EHC_IPV4_PAYLOAD;
|
||||
|
||||
result[i] = {data.GetEndianness(), &data[i * EHC_IPV4_PAYLOAD], size};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void NetClientCh::Send(NetEnc *enc, const Header& header, const Serializer<UInt_64>& payload)
|
||||
{
|
||||
Serializer result(Endianness::LE);
|
||||
result.Write(header);
|
||||
result.WriteSer(payload);
|
||||
|
||||
enc->Encrypt(&result[sizeof(bool)], result.Size() - sizeof(bool));
|
||||
|
||||
if (header.ensure)
|
||||
sent.Push({header, payload});
|
||||
|
||||
GetOwner()->udp.Send(remoteEndpoint, result, result.Size());
|
||||
}
|
||||
|
||||
void NetClientCh::Pong(const float delta)
|
||||
{
|
||||
Serializer payload(Endianness::LE);
|
||||
payload.Write(delta);
|
||||
|
||||
Send(false, true, false, internalSys, pongOp, payload);
|
||||
|
||||
timeout = 0.0f;
|
||||
}
|
||||
|
||||
void NetClientCh::RemoveInsurance(const UInt_64 msgId, const UInt_64 fragment)
|
||||
{
|
||||
for (UInt_64 i = 0; i < sent.Size(); ++i)
|
||||
{
|
||||
if (sent[i].header.id == msgId && sent[i].header.fragment == fragment)
|
||||
{
|
||||
sent.Remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
timeout = 0.0f;
|
||||
}
|
||||
|
||||
void NetClientCh::AddReceived(const Header& header, const Serializer<>& payload)
|
||||
{
|
||||
NetFrag* frags = nullptr;
|
||||
|
||||
for (UInt_64 i = 0; i < received.Size(); ++i)
|
||||
{
|
||||
if (received[i].GetHeader().id == header.id)
|
||||
{
|
||||
if (received[i][header.fragment].Size())
|
||||
return;
|
||||
|
||||
frags = &received[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (header.id > nextRecvId)
|
||||
nextRecvId = header.id + 1;
|
||||
|
||||
if (frags)
|
||||
(*frags)[header.fragment] = payload;
|
||||
else
|
||||
received.Push({header, payload});
|
||||
|
||||
timeout = 0.0f;
|
||||
}
|
||||
}
|
||||
@@ -3,24 +3,24 @@
|
||||
namespace ehs
|
||||
{
|
||||
NetEnc::NetEnc()
|
||||
: owner(nullptr), hashId(0)
|
||||
: id(0)
|
||||
{
|
||||
}
|
||||
|
||||
NetEnc::NetEnc(Str_8 id)
|
||||
: owner(nullptr), hashId(id.Hash_64()), id((Str_8 &&)id)
|
||||
NetEnc::NetEnc(Str_8 name, const Version &version)
|
||||
: id(name.Hash_64()), name((Str_8 &&)name), version(version)
|
||||
{
|
||||
}
|
||||
|
||||
NetEnc::NetEnc(NetEnc&& enc) noexcept
|
||||
: owner(enc.owner), hashId(enc.hashId), id((Str_8 &&)enc.id)
|
||||
: id(enc.id), name((Str_8 &&)enc.name), version(enc.version)
|
||||
{
|
||||
enc.owner = nullptr;
|
||||
enc.hashId = 0;
|
||||
enc.id = 0;
|
||||
enc.version = {};
|
||||
}
|
||||
|
||||
NetEnc::NetEnc(const NetEnc& enc)
|
||||
: owner(nullptr), hashId(enc.hashId), id(enc.id)
|
||||
: id(enc.id), name(enc.name), version(enc.version)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -29,12 +29,12 @@ namespace ehs
|
||||
if (this == &enc)
|
||||
return *this;
|
||||
|
||||
owner = enc.owner;
|
||||
hashId = enc.hashId;
|
||||
id = (Str_8 &&)enc.id;
|
||||
id = enc.id;
|
||||
name = (Str_8 &&)enc.name;
|
||||
version = enc.version;
|
||||
|
||||
enc.owner = nullptr;
|
||||
enc.hashId = 0;
|
||||
enc.id = 0;
|
||||
enc.version = {};
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -44,28 +44,28 @@ namespace ehs
|
||||
if (this == &enc)
|
||||
return *this;
|
||||
|
||||
owner = nullptr;
|
||||
hashId = enc.hashId;
|
||||
id = enc.id;
|
||||
name = enc.name;
|
||||
version = enc.version;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
EHC* NetEnc::GetOwner() const
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
|
||||
UInt_64 NetEnc::GetHashId() const
|
||||
{
|
||||
return hashId;
|
||||
}
|
||||
|
||||
Str_8 NetEnc::GetId() const
|
||||
UInt_64 NetEnc::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
Str_8 NetEnc::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
Version NetEnc::GetVersion() const
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
void NetEnc::Encrypt(Byte *data, UInt_64 size) const
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
#include "ehs/io/socket/ehc/NetFrags.h"
|
||||
#include "ehs/io/socket/ehc/NetFrag.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
NetFrags::~NetFrags()
|
||||
NetFrag::~NetFrag()
|
||||
{
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
NetFrags::NetFrags()
|
||||
NetFrag::NetFrag()
|
||||
: data(nullptr), size(0)
|
||||
{
|
||||
}
|
||||
|
||||
NetFrags::NetFrags(const Header &header, const Serializer<UInt_64> &payload)
|
||||
: header(header), data(new Serializer<UInt_64>[header.fragments]), size(header.fragments)
|
||||
NetFrag::NetFrag(const Header &header, const Serializer<UInt_64> &payload)
|
||||
: header(header), data(new Serializer<UInt_64>[header.fragmentCount]), size(header.fragmentCount)
|
||||
{
|
||||
this->header.fragment = 0;
|
||||
data[header.fragment] = payload;
|
||||
}
|
||||
|
||||
NetFrags::NetFrags(const Header &header, const UInt_64 size)
|
||||
NetFrag::NetFrag(const Header &header, const UInt_64 size)
|
||||
: header(header), data(new Serializer<UInt_64>[size]), size(size)
|
||||
{
|
||||
this->header.fragments = size;
|
||||
this->header.fragmentCount = size;
|
||||
this->header.fragment = 0;
|
||||
}
|
||||
|
||||
NetFrags::NetFrags(NetFrags &&frags) noexcept
|
||||
NetFrag::NetFrag(NetFrag &&frags) noexcept
|
||||
: header(frags.header), data(frags.data), size(frags.size)
|
||||
{
|
||||
frags.header = {};
|
||||
@@ -34,14 +34,14 @@ namespace ehs
|
||||
frags.size = 0;
|
||||
}
|
||||
|
||||
NetFrags::NetFrags(const NetFrags &frags)
|
||||
NetFrag::NetFrag(const NetFrag &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];
|
||||
}
|
||||
|
||||
NetFrags &NetFrags::operator=(NetFrags &&frags) noexcept
|
||||
NetFrag &NetFrag::operator=(NetFrag &&frags) noexcept
|
||||
{
|
||||
if (this == &frags)
|
||||
return *this;
|
||||
@@ -60,7 +60,7 @@ namespace ehs
|
||||
return *this;
|
||||
}
|
||||
|
||||
NetFrags &NetFrags::operator=(const NetFrags &frags)
|
||||
NetFrag &NetFrag::operator=(const NetFrag &frags)
|
||||
{
|
||||
if (this == &frags)
|
||||
return *this;
|
||||
@@ -75,22 +75,22 @@ namespace ehs
|
||||
return *this;
|
||||
}
|
||||
|
||||
NetFrags::operator Serializer<UInt_64> *() const
|
||||
NetFrag::operator Serializer<UInt_64> *() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
Header NetFrags::GetHeader() const
|
||||
Header NetFrag::GetHeader() const
|
||||
{
|
||||
return header;
|
||||
}
|
||||
|
||||
UInt_64 NetFrags::Size() const
|
||||
UInt_64 NetFrag::Size() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
bool NetFrags::IsComplete() const
|
||||
bool NetFrag::IsComplete() const
|
||||
{
|
||||
for (UInt_64 i = 0; i < size; ++i)
|
||||
if (!data[i].Size())
|
||||
@@ -99,7 +99,7 @@ namespace ehs
|
||||
return true;
|
||||
}
|
||||
|
||||
Packet NetFrags::Combine() const
|
||||
Packet NetFrag::Combine() const
|
||||
{
|
||||
UInt_64 rSize = 0;
|
||||
for (UInt_64 i = 0; i < size; ++i)
|
||||
@@ -110,7 +110,7 @@ namespace ehs
|
||||
header,
|
||||
{Endianness::LE, rSize}
|
||||
};
|
||||
result.header.fragments = 0;
|
||||
result.header.fragmentCount = 0;
|
||||
|
||||
for (UInt_64 i = 0; i < size; ++i)
|
||||
result.payload.WriteSer(data[i]);
|
||||
@@ -1,7 +1,6 @@
|
||||
#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/NetSys.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
@@ -60,7 +59,7 @@ namespace ehs
|
||||
return hashId;
|
||||
}
|
||||
|
||||
void NetOp::Process(EHC *ehc, NetEnd *endpoint, NetSys *sys, Serializer<UInt_64> &payload)
|
||||
void NetOp::Process(NetChannel *channel, NetEnd *endpoint, NetSys *sys, Serializer<UInt_64> &payload)
|
||||
{
|
||||
}
|
||||
}
|
||||
588
src/io/socket/ehc/NetServerCh.cpp
Normal file
588
src/io/socket/ehc/NetServerCh.cpp
Normal file
@@ -0,0 +1,588 @@
|
||||
#include "ehs/io/socket/ehc/NetServerCh.h"
|
||||
#include "ehs/io/socket/ehc/NetEnd.h"
|
||||
#include "ehs/io/socket/ehc/NetSys.h"
|
||||
#include "ehs/io/socket/EHC.h"
|
||||
#include "ehs/PRNG.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
NetServerCh::~NetServerCh()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
NetServerCh::NetServerCh(const UInt_64 maxEndpoints)
|
||||
: maxEndpoints(maxEndpoints)
|
||||
{
|
||||
}
|
||||
|
||||
NetServerCh::NetServerCh(NetServerCh &&server) noexcept
|
||||
: endpoints((Vector<NetEnd *> &&)server.endpoints), maxEndpoints(server.maxEndpoints)
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); i++)
|
||||
endpoints[i]->owner = this;
|
||||
}
|
||||
|
||||
NetServerCh::NetServerCh(const NetServerCh &server)
|
||||
: maxEndpoints(server.maxEndpoints)
|
||||
{
|
||||
}
|
||||
|
||||
NetServerCh &NetServerCh::operator=(NetServerCh &&server) noexcept
|
||||
{
|
||||
if (this == &server)
|
||||
return *this;
|
||||
|
||||
Shutdown();
|
||||
|
||||
endpoints = (Vector<NetEnd *> &&)server.endpoints;
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); i++)
|
||||
endpoints[i]->owner = this;
|
||||
|
||||
maxEndpoints = server.maxEndpoints;
|
||||
|
||||
server.maxEndpoints = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NetServerCh &NetServerCh::operator=(const NetServerCh &server)
|
||||
{
|
||||
if (this == &server)
|
||||
return *this;
|
||||
|
||||
Shutdown();
|
||||
|
||||
endpoints = {};
|
||||
maxEndpoints = server.maxEndpoints;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool NetServerCh::OnEndpointConnect(NetEnd *endpoint, Serializer<UInt_64> payload)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Serializer<UInt_64> NetServerCh::OnEndpointAccepted(NetEnd *endpoint)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void NetServerCh::OnEndpointDisconnect(NetEnd *endpoint, Serializer<UInt_64> payload)
|
||||
{
|
||||
}
|
||||
|
||||
void NetServerCh::OnEndpointTimeout(NetEnd *endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
void NetServerCh::OnEndpointActive(NetEnd *endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
Serializer<UInt_64> OnShutdown()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void NetServerCh::Broadcast(const NetStatus endStatus, const bool deltaLocked, const UInt_64 encHashId,
|
||||
const bool ensure, const UInt_64 sysHashId, const UInt_64 opHashId, const Serializer<UInt_64> &payload)
|
||||
{
|
||||
if (!GetOwner()->udp.IsValid())
|
||||
return;
|
||||
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
if (endpoints[i]->GetStatus() == endStatus)
|
||||
endpoints[i]->Send(deltaLocked, encHashId, ensure, sysHashId, opHashId, payload);
|
||||
}
|
||||
|
||||
void NetServerCh::Broadcast(const NetStatus endStatus, const bool deltaLocked, const Str_8 &encId, const bool ensure,
|
||||
const Str_8 &sysId, const Str_8 &opId,
|
||||
const Serializer<UInt_64> &payload)
|
||||
{
|
||||
Broadcast(endStatus, deltaLocked, encId.Hash_64(), ensure, sysId.Hash_64(), opId.Hash_64(), payload);
|
||||
}
|
||||
|
||||
bool NetServerCh::HasEndpoint(const NetStatus endStatus, const Char_8 token[64]) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
{
|
||||
if (endpoints[i]->GetStatus() != endStatus)
|
||||
continue;
|
||||
|
||||
if (Util::Compare(endpoints[i]->token, token, 64))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetServerCh::HasEndpoint(const NetStatus endStatus, const UInt_64 hashName) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
{
|
||||
if (endpoints[i]->GetStatus() != endStatus)
|
||||
continue;
|
||||
|
||||
if (endpoints[i]->GetId() == hashName)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetServerCh::HasEndpoint(const NetStatus endStatus, const Str_8 &id) const
|
||||
{
|
||||
return HasEndpoint(endStatus, id.Hash_64());
|
||||
}
|
||||
|
||||
bool NetServerCh::HasEndpoint(const Char_8 token[64]) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
if (Util::Compare(endpoints[i]->token, token, 64))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetServerCh::HasEndpoint(const UInt_64 hashName) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
if (endpoints[i]->GetId() == hashName)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetServerCh::HasEndpoint(const Str_8 &id) const
|
||||
{
|
||||
return HasEndpoint(id.Hash_64());
|
||||
}
|
||||
|
||||
bool NetServerCh::HasEndpoint(const Endpoint &endpoint) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
if (endpoints[i]->GetEndpoint().address == endpoint.address && endpoints[i]->GetEndpoint().port == endpoint.port)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
NetEnd* NetServerCh::GetEndpoint(const NetStatus endStatus, const Char_8 token[64]) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
{
|
||||
if (endpoints[i]->GetStatus() != endStatus)
|
||||
continue;
|
||||
|
||||
if (Util::Compare(endpoints[i]->token, token, 64))
|
||||
return endpoints[i];
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NetEnd *NetServerCh::GetEndpoint(const NetStatus endStatus, const UInt_64 hashName) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
{
|
||||
if (endpoints[i]->GetStatus() != endStatus)
|
||||
continue;
|
||||
|
||||
if (endpoints[i]->GetId() == hashName)
|
||||
return endpoints[i];
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NetEnd *NetServerCh::GetEndpoint(const NetStatus endStatus, const Str_8 &id) const
|
||||
{
|
||||
return GetEndpoint(endStatus, id.Hash_64());
|
||||
}
|
||||
|
||||
NetEnd *NetServerCh::GetEndpoint(const Char_8 token[64]) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
if (Util::Compare(endpoints[i]->token, token, 64))
|
||||
return endpoints[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NetEnd *NetServerCh::GetEndpoint(const UInt_64 hashName) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
if (endpoints[i]->GetId() == hashName)
|
||||
return endpoints[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NetEnd *NetServerCh::GetEndpoint(const Str_8 &id) const
|
||||
{
|
||||
return GetEndpoint(id.Hash_64());
|
||||
}
|
||||
|
||||
NetEnd *NetServerCh::GetEndpoint(const Endpoint &endpoint) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
if (endpoints[i]->GetEndpoint().address == endpoint.address && endpoints[i]->GetEndpoint().port == endpoint.port)
|
||||
return endpoints[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Array<NetEnd *> NetServerCh::GetEndpoints(const NetStatus endStatus)
|
||||
{
|
||||
Array<NetEnd*> result(endpoints.Size());
|
||||
UInt_64 count = 0;
|
||||
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
if (endpoints[i]->GetStatus() == endStatus)
|
||||
result[count++] = endpoints[i];
|
||||
|
||||
result.Resize(count);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UInt_64 NetServerCh::GetEndpointsCount(const NetStatus endStatus)
|
||||
{
|
||||
UInt_64 count = 0;
|
||||
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
if (endpoints[i]->GetStatus() == endStatus)
|
||||
++count;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
UInt_64 NetServerCh::GetMaxEndpoints() const
|
||||
{
|
||||
return maxEndpoints;
|
||||
}
|
||||
|
||||
void NetServerCh::Process(const float &delta, const Endpoint &endpoint, const Header &header, Serializer<UInt_64> &payload)
|
||||
{
|
||||
if (header.channelVer != GetVersion())
|
||||
return;
|
||||
|
||||
if (!header.ensure && !header.token[0] && header.systemId == internalSys && header.opId == connectOp)
|
||||
{
|
||||
NetEnd* end = new NetEnd(payload.ReadStr(), endpoint);
|
||||
end->owner = this;
|
||||
GenerateToken(end->token);
|
||||
end->SetStatus(NetStatus::PENDING);
|
||||
|
||||
Serializer sPayload(Endianness::LE);
|
||||
|
||||
if (!OnEndpointConnect(end, {Endianness::LE, &payload[payload.GetOffset()], payload.Size() - payload.GetOffset()}))
|
||||
{
|
||||
sPayload.WriteStr<Char_8, UInt_64>("Connection rejected.");
|
||||
end->Send(false, true, false, internalSys, rejectedOp, sPayload);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
endpoints.Push(end);
|
||||
|
||||
UInt_64 active = GetEndpointsCount(NetStatus::ACTIVE);
|
||||
|
||||
if (maxEndpoints && active >= maxEndpoints)
|
||||
{
|
||||
end->SetStatus(NetStatus::QUEUED);
|
||||
|
||||
UpdateQueue(active);
|
||||
|
||||
sPayload.Write(NetStatus::QUEUED);
|
||||
sPayload.Write(end->GetQueueSlot());
|
||||
}
|
||||
else
|
||||
{
|
||||
end->SetStatus(NetStatus::ACTIVE);
|
||||
|
||||
OnEndpointActive(end);
|
||||
|
||||
sPayload.Write(NetStatus::ACTIVE);
|
||||
sPayload.Write(0);
|
||||
}
|
||||
|
||||
sPayload.WriteSer(OnEndpointAccepted(end));
|
||||
|
||||
end->Send(false, 0, false, internalSys, connectedOp, sPayload);
|
||||
}
|
||||
else if (!header.ensure && header.token[0] && header.systemId == internalSys && header.opId == disconnectOp)
|
||||
{
|
||||
NetEnd* end = GetEndpoint(header.token);
|
||||
if (!end)
|
||||
return;
|
||||
|
||||
end->Send(false, 0, false, internalSys, disconnectedOp, {});
|
||||
|
||||
OnEndpointDisconnect(end, {Endianness::LE, &payload[payload.GetOffset()], payload.Size() - payload.GetOffset()});
|
||||
|
||||
RemoveEndpoint(end->token);
|
||||
|
||||
UpdateQueue();
|
||||
}
|
||||
else if (!header.ensure && header.token[0] && header.systemId == internalSys && header.opId == pongOp)
|
||||
{
|
||||
NetEnd* end = GetEndpoint(header.token);
|
||||
if (!end)
|
||||
return;
|
||||
|
||||
end->SetDeltaRate(payload.Read<float>());
|
||||
end->SendLatency();
|
||||
}
|
||||
else if (!header.ensure && header.token[0] && header.systemId == internalSys && header.opId == receivedOp)
|
||||
{
|
||||
NetEnd* end = GetEndpoint(header.token);
|
||||
if (!end)
|
||||
return;
|
||||
|
||||
const UInt_64 msgId = payload.Read<UInt_64>();
|
||||
const UInt_64 fragment = payload.Read<UInt_64>();
|
||||
|
||||
end->RemoveInsurance(msgId, fragment);
|
||||
}
|
||||
else if (header.token[0])
|
||||
{
|
||||
NetEnd* end = GetEndpoint(header.token);
|
||||
if (!end)
|
||||
return;
|
||||
|
||||
if (IsDropPacketsEnabled() && !header.ensure && header.id < end->GetNextRecvId())
|
||||
{
|
||||
EHS_LOG_INT(LogType::INFO, 6, "Old packet intentionally dropped.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (header.ensure)
|
||||
{
|
||||
Serializer sPayload(Endianness::LE);
|
||||
sPayload.Write(header.id);
|
||||
sPayload.Write(header.fragment);
|
||||
|
||||
end->Send(false, 0, false, internalSys, receivedOp, sPayload);
|
||||
}
|
||||
|
||||
end->AddReceived(
|
||||
header,
|
||||
Serializer<>(Endianness::LE, &payload[payload.GetOffset()], payload.Size() - payload.GetOffset())
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
EHS_LOG_INT(LogType::INFO, 7, "Corrupted packet.");
|
||||
}
|
||||
}
|
||||
|
||||
void NetServerCh::GenerateToken(Char_8 in[64])
|
||||
{
|
||||
PRNG_u64 rng(CPU::GetTSC());
|
||||
|
||||
for (UInt_64 i = 0; i < 8; ++i)
|
||||
{
|
||||
do
|
||||
((UInt_64*)in)[i] = rng.Generate();
|
||||
while (!i && ((UInt_64*)in)[i] == 0);
|
||||
}
|
||||
|
||||
if (HasEndpoint(in))
|
||||
GenerateToken(in);
|
||||
}
|
||||
|
||||
void NetServerCh::UpdateQueue(UInt_64 active)
|
||||
{
|
||||
UInt_64 slot = 0;
|
||||
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
{
|
||||
if (endpoints[i]->GetStatus() == NetStatus::QUEUED)
|
||||
{
|
||||
if (active < maxEndpoints)
|
||||
{
|
||||
endpoints[i]->SetStatus(NetStatus::ACTIVE);
|
||||
endpoints[i]->SetQueueSlot(0);
|
||||
|
||||
Serializer payload(Endianness::LE);
|
||||
payload.Write(NetStatus::ACTIVE);
|
||||
payload.Write(0);
|
||||
|
||||
endpoints[i]->Send(false, true, false, internalSys, statusUpdateOp, payload);
|
||||
|
||||
OnEndpointActive(endpoints[i]);
|
||||
|
||||
++active;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (endpoints[i]->GetQueueSlot() != slot)
|
||||
{
|
||||
Serializer payload(Endianness::LE);
|
||||
payload.Write(NetStatus::QUEUED);
|
||||
payload.Write(slot);
|
||||
|
||||
endpoints[i]->Send(false, true, false, internalSys, statusUpdateOp, payload);
|
||||
|
||||
endpoints[i]->SetQueueSlot(slot++);
|
||||
}
|
||||
else
|
||||
{
|
||||
++slot;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NetServerCh::UpdateQueue()
|
||||
{
|
||||
UpdateQueue(GetEndpointsCount(NetStatus::ACTIVE));
|
||||
}
|
||||
|
||||
bool NetServerCh::RemoveEndpoint(const Char_8 token[64])
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
{
|
||||
if (Util::Compare(endpoints[i]->token, token, 64))
|
||||
{
|
||||
delete endpoints[i];
|
||||
|
||||
if (i != endpoints.Size() - 1)
|
||||
endpoints.Swap(i, endpoints.End());
|
||||
|
||||
endpoints.Pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetServerCh::RemoveEndpoint(const Endpoint &endpoint)
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
{
|
||||
if (endpoints[i]->GetEndpoint().address == endpoint.address && endpoints[i]->GetEndpoint().port == endpoint.port)
|
||||
{
|
||||
delete endpoints[i];
|
||||
|
||||
if (i != endpoints.Size() - 1)
|
||||
endpoints.Swap(i, endpoints.End());
|
||||
|
||||
endpoints.Pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetServerCh::RemoveEndpoint(const NetEnd* const end)
|
||||
{
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); ++i)
|
||||
{
|
||||
if (endpoints[i] == end)
|
||||
{
|
||||
delete endpoints[i];
|
||||
|
||||
if (i != endpoints.Size() - 1)
|
||||
endpoints.Swap(i, endpoints.End());
|
||||
|
||||
endpoints.Pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void NetServerCh::Poll(const float &delta)
|
||||
{
|
||||
UInt_64 i = 0;
|
||||
while (i < endpoints.Size())
|
||||
{
|
||||
endpoints[i]->Poll(delta);
|
||||
|
||||
if (endpoints[i]->GetStatus() == NetStatus::PENDING)
|
||||
{
|
||||
if (endpoints[i]->GetTimeout() >= GetMaxTimeout())
|
||||
{
|
||||
OnEndpointTimeout(endpoints[i]);
|
||||
|
||||
delete endpoints[i];
|
||||
|
||||
if (i != endpoints.Size() - 1)
|
||||
endpoints.Swap(i, endpoints.End());
|
||||
|
||||
endpoints.Pop();
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (endpoints[i]->GetTimeout() >= GetMaxTimeout())
|
||||
{
|
||||
OnEndpointTimeout(endpoints[i]);
|
||||
|
||||
delete endpoints[i];
|
||||
|
||||
if (i != endpoints.Size() - 1)
|
||||
endpoints.Swap(i, endpoints.End());
|
||||
|
||||
endpoints.Pop();
|
||||
|
||||
UpdateQueue();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector<NetFrag>* frags = endpoints[i]->GetReceived();
|
||||
|
||||
UInt_64 f = 0;
|
||||
while (f < frags->Size())
|
||||
{
|
||||
if (!(*frags)[f].IsComplete())
|
||||
{
|
||||
++f;
|
||||
continue;
|
||||
}
|
||||
|
||||
Packet packet = (*frags)[f].Combine();
|
||||
|
||||
NetSys* sys = GetSystem(packet.header.systemId);
|
||||
if (!sys)
|
||||
{
|
||||
++f;
|
||||
continue;
|
||||
}
|
||||
|
||||
sys->Execute(this, endpoints[i], packet.header.opId, packet.payload);
|
||||
|
||||
frags->Swap(f, frags->End());
|
||||
frags->Pop();
|
||||
}
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void NetServerCh::Shutdown()
|
||||
{
|
||||
Serializer<UInt_64> payload = OnShutdown();
|
||||
for (UInt_64 i = 0; i < endpoints.Size(); i++)
|
||||
{
|
||||
endpoints[i]->Send(false, 0, false, internalSys, disconnectOp, payload);
|
||||
delete endpoints[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,13 +89,13 @@ namespace ehs
|
||||
return true;
|
||||
}
|
||||
|
||||
void NetSys::Execute(EHC *ehc, NetEnd *endpoint, const UInt_64 hashId, Serializer<UInt_64> &payload)
|
||||
void NetSys::Execute(NetChannel *channel, NetEnd *endpoint, const UInt_64 hashId, Serializer<UInt_64> &payload)
|
||||
{
|
||||
for (UInt_64 i = 0; i < ops.Size(); ++i)
|
||||
{
|
||||
if (ops[i]->GetHashId() == hashId)
|
||||
{
|
||||
ops[i]->Process(ehc, endpoint, this, payload);
|
||||
ops[i]->Process(channel, endpoint, this, payload);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
44
src/io/socket/ehc/NetUtils.cpp
Normal file
44
src/io/socket/ehc/NetUtils.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "ehs/io/socket/ehc/NetUtils.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
void WriteHeader(const Header &header, Serializer<UInt_64> &data)
|
||||
{
|
||||
data.WriteVersion(header.version);
|
||||
data.Write(header.encId);
|
||||
data.WriteVersion(header.encVer);
|
||||
data.Write(header.channelId);
|
||||
data.Write(header.channelType);
|
||||
data.WriteVersion(header.channelVer);
|
||||
data.Write(header.id);
|
||||
data.Write(header.fragmentCount);
|
||||
data.Write(header.fragment);
|
||||
data.Write(header.ensure);
|
||||
data.WriteArray(header.token, 64);
|
||||
data.Write(header.systemId);
|
||||
data.Write(header.opId);
|
||||
}
|
||||
|
||||
Header ReadHeader(Serializer<UInt_64> &data)
|
||||
{
|
||||
Header header = {};
|
||||
header.version = data.ReadVersion();
|
||||
header.encId = data.Read<UInt_64>();
|
||||
header.encVer = data.ReadVersion();
|
||||
header.channelId = data.Read<UInt_64>();
|
||||
header.channelType = data.Read<NetChannelType>();
|
||||
header.channelVer = data.ReadVersion();
|
||||
header.id = data.Read<UInt_64>();
|
||||
header.fragmentCount = data.Read<UInt_64>();
|
||||
header.fragment = data.Read<UInt_64>();
|
||||
header.ensure = data.Read<bool>();
|
||||
|
||||
UInt_64 tokenSize = sizeof(header.token) / sizeof(Char_8);
|
||||
data.ReadArray<Char_8, UInt_64>(header.token, &tokenSize);
|
||||
|
||||
header.systemId = data.Read<UInt_64>();
|
||||
header.opId = data.Read<UInt_64>();
|
||||
|
||||
return header;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user