2024-10-06 20:08:22 -07:00
# pragma once
2024-10-06 22:54:29 -07:00
# include "NetUtils.h"
# include "NetFrags.h"
2024-10-06 20:08:22 -07:00
2024-10-06 22:54:29 -07:00
# include "ehs/Str.h"
# include "ehs/Vector.h"
# include "ehs/Serializer.h"
# include "ehs/io/socket/Socket.h"
2024-10-06 20:08:22 -07:00
namespace ehs
{
class EHC ;
class NetEnd
{
private :
friend class EHC ;
EHC * owner ;
EndDisp disposition ;
UInt_64 hashName ;
Str_8 name ;
Status status ;
Architecture arch ;
Char_8 token [ 64 ] ;
UInt_64 nextSendId ;
Vector < Insurance > sent ;
UInt_64 nextRecvId ;
2024-10-06 22:54:29 -07:00
Vector < NetFrags > received ;
2024-10-06 20:08:22 -07:00
AddrType type ;
Str_8 address ;
UInt_16 port ;
float deltaDuration ;
float deltaRate ;
float timeout ;
float lastPing ;
float oldLatency ;
float latency ;
UInt_64 queueSlot ;
public :
NetEnd ( ) ;
NetEnd ( EndDisp disposition , Str_8 id , Architecture arch , AddrType type , Str_8 address , UInt_16 port ) ;
NetEnd ( AddrType type , Str_8 address , UInt_16 port ) ;
NetEnd ( NetEnd & & end ) noexcept ;
NetEnd ( const NetEnd & end ) ;
NetEnd & operator = ( NetEnd & & end ) noexcept ;
NetEnd & operator = ( const NetEnd & end ) ;
EndDisp GetDisposition ( ) const ;
UInt_64 GetHashName ( ) const ;
Str_8 GetName ( ) const ;
Status GetStatus ( ) const ;
Architecture GetArchitecture ( ) 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.
2024-10-06 22:54:29 -07:00
/// @param [in] encHashId The hash id of the encryption to use. Can be zero for none.
2024-10-06 20:08:22 -07:00
/// @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.
2024-10-06 22:54:29 -07:00
void Send ( bool deltaLocked , UInt_64 encHashId , bool ensure , UInt_64 sys , UInt_64 op , const Serializer < UInt_64 > & payload ) ;
2024-10-06 20:08:22 -07:00
/// 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.
2024-10-06 22:54:29 -07:00
/// @param [in] encId The id of the encryption to use. Can be empty for none.
2024-10-06 20:08:22 -07:00
/// @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.
2024-10-06 22:54:29 -07:00
void Send ( bool deltaLocked , const Str_8 & encID , bool ensure , const Str_8 & sys , const Str_8 & op , const Serializer < UInt_64 > & payload ) ;
2024-10-06 20:08:22 -07:00
UInt_64 GetNextRecvId ( ) const ;
Str_8 GetAddress ( ) const ;
UInt_16 GetPort ( ) const ;
void SetDeltaRate ( float newDeltaRate ) ;
float GetDeltaRate ( ) const ;
float GetTimeout ( ) const ;
float GetLastPing ( ) const ;
void SendLatency ( ) ;
float GetLatency ( ) const ;
UInt_64 GetQueueSlot ( ) const ;
private :
void Poll ( float delta ) ;
void SetStatus ( Status newStatus ) ;
void RemoveInsurance ( UInt_64 msgId , UInt_64 fragment ) ;
void AddReceived ( const Header & header , const Serializer < > & payload ) ;
2024-10-06 22:54:29 -07:00
Vector < NetFrags > * GetReceived ( ) ;
2024-10-06 20:08:22 -07:00
void Ping ( float delta ) ;
void Pong ( float delta ) ;
void SetLatency ( float newLatency ) ;
void SetQueueSlot ( UInt_64 slot ) ;
2024-10-06 22:54:29 -07:00
NetFrags FragmentData ( const Header & header , const Serializer < > & data ) ;
2024-10-06 20:08:22 -07:00
void Send ( const Header & header , const Serializer < > & payload ) ;
bool SortingNeeded ( ) const ;
void SortReceived ( ) ;
} ;
}