EHS/include/IO/Socket/Endpoint.h

138 lines
3.8 KiB
C
Raw Normal View History

2023-12-17 03:29:08 -08:00
#pragma once
#include "../../EHS.h"
#include "../../Str.h"
#include "../../BaseObj.h"
#include "../../Vector.h"
#include "../../Serializer.h"
#include "../../IO/Socket/Socket.h"
#include "Utils.h"
#include "Fragments.h"
namespace lwe
{
class Comms;
class Endpoint : public BaseObj
{
private:
Socket hdl;
EndDisp disposition;
Status status;
Architecture arch;
Str_8 id;
UInt_64 hashId;
UInt_64 nextSendId;
Vector<Insurance> sent;
UInt_64 nextRecvId;
Vector<Fragments> received;
Str_8 address;
UInt_16 port;
float deltaDuration;
float deltaRate;
float timeout;
float lastPing;
float oldLatency;
float latency;
UInt_64 queueSlot;
public:
Endpoint();
Endpoint(const Socket hdl, const EndDisp disposition, const Architecture arch, const Str_8& id,
const AddrType& type, const Str_8& address, const UInt_16 port);
Endpoint(const Socket hdl, const AddrType& type, const Str_8& address, const UInt_16 port);
Endpoint(const Endpoint& end);
Endpoint& operator=(const Endpoint& end);
void Poll(const float delta);
EndDisp GetDisposition() const;
void SetStatus(const Status newStatus);
Status GetStatus() const;
Architecture GetArchitecture() const;
Str_8 GetId() const;
UInt_64 GetHashId() const;
UInt_64 GetNextSendId() const;
/// 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] 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(const bool deltaLocked, const bool encrypted, const bool ensure, const UInt_64 sys,
const UInt_64 op, const Serializer<>& 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] 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(const bool deltaLocked, const bool encrypted, const bool ensure, const Str_8& sys,
const Str_8& op, const Serializer<>& payload);
void RemoveInsurance(const UInt_64 msgId, const UInt_64 fragment);
UInt_64 GetNextRecvId() const;
void AddReceived(const Header& header, const Serializer<>& payload);
Vector<Fragments> GetReceived() const;
Vector<Fragments>* GetReceived();
Str_8 GetAddress() const;
UInt_16 GetPort() const;
void SetDeltaRate(const float newDeltaRate);
float GetDeltaRate() const;
float GetTimeout() const;
float GetLastPing() const;
void Ping(const float delta);
void Pong(const float delta);
void SendLatency();
void SetLatency(const float newLatency);
float GetLatency() const;
void SetQueueSlot(const UInt_64 slot);
UInt_64 GetQueueSlot() const;
private:
Fragments FragmentData(const Header& header, const Serializer<>& data);
void Send(const Header& header, const Serializer<>& payload);
bool SortingNeeded() const;
void SortReceived();
UInt_16 Send_v6(const Serializer<>& payload);
UInt_16 Send_v4(const Serializer<>& payload);
};
}