EHS/include/io/socket/Endpoint.h

133 lines
3.5 KiB
C++

#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 ehs
{
class Comms;
class Endpoint : public BaseObj
{
private:
Comms* owner;
EndDisp disposition;
Status status;
Architecture arch;
Str_8 id;
UInt_64 hashId;
UInt_64 nextSendId;
Vector<Insurance> sent;
UInt_64 nextRecvId;
Vector<Fragments> received;
AddrType type;
Str_8 address;
UInt_16 port;
float deltaDuration;
float deltaRate;
float timeout;
float lastPing;
float oldLatency;
float latency;
UInt_64 queueSlot;
public:
Endpoint();
Endpoint(Comms* owner, EndDisp disposition, Architecture arch, Str_8 id,
AddrType type, Str_8 address, UInt_16 port);
Endpoint(Comms* owner, AddrType type, Str_8 address, UInt_16 port);
Endpoint(const Endpoint& end);
Endpoint& operator=(const Endpoint& end);
void Poll(float delta);
EndDisp GetDisposition() const;
void SetStatus(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(bool deltaLocked, bool encrypted, 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] 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 RemoveInsurance(UInt_64 msgId, 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(float newDeltaRate);
float GetDeltaRate() const;
float GetTimeout() const;
float GetLastPing() const;
void Ping(float delta);
void Pong(float delta);
void SendLatency();
void SetLatency(float newLatency);
float GetLatency() const;
void SetQueueSlot(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();
};
}