Compare commits
5 Commits
main
...
NetChannel
Author | SHA1 | Date | |
---|---|---|---|
89925fe820 | |||
16b56a7084 | |||
62f8a662a0 | |||
39bbcd0d56 | |||
981b40d3b1 |
@ -134,7 +134,7 @@ set(EHS_SOURCES
|
|||||||
|
|
||||||
include/ehs/io/socket/ehc/NetUtils.h
|
include/ehs/io/socket/ehc/NetUtils.h
|
||||||
src/io/socket/EHC.cpp include/ehs/io/socket/EHC.h
|
src/io/socket/EHC.cpp include/ehs/io/socket/EHC.h
|
||||||
src/io/socket/ehc/NetFrags.cpp include/ehs/io/socket/ehc/NetFrags.h
|
src/io/socket/ehc/NetFrag.cpp include/ehs/io/socket/ehc/NetFrag.h
|
||||||
src/io/socket/ehc/NetEnd.cpp include/ehs/io/socket/ehc/NetEnd.h
|
src/io/socket/ehc/NetEnd.cpp include/ehs/io/socket/ehc/NetEnd.h
|
||||||
src/io/socket/ehc/NetSys.cpp include/ehs/io/socket/ehc/NetSys.h
|
src/io/socket/ehc/NetSys.cpp include/ehs/io/socket/ehc/NetSys.h
|
||||||
src/io/socket/ehc/NetOp.cpp include/ehs/io/socket/ehc/NetOp.h
|
src/io/socket/ehc/NetOp.cpp include/ehs/io/socket/ehc/NetOp.h
|
||||||
@ -185,8 +185,15 @@ set(EHS_SOURCES
|
|||||||
include/ehs/io/BaseDirectory.h
|
include/ehs/io/BaseDirectory.h
|
||||||
src/io/BaseDirectory.cpp
|
src/io/BaseDirectory.cpp
|
||||||
include/ehs/io/Directory.h
|
include/ehs/io/Directory.h
|
||||||
include/ehs/io/socket/ehc/NetEnc.h
|
include/ehs/io/socket/ehc/NetEnc.h
|
||||||
src/io/socket/ehc/NetEnc.cpp
|
src/io/socket/ehc/NetEnc.cpp
|
||||||
|
include/ehs/io/socket/ehc/NetChannel.h
|
||||||
|
src/io/socket/ehc/NetChannel.cpp
|
||||||
|
include/ehs/io/socket/ehc/NetServerCh.h
|
||||||
|
include/ehs/io/socket/ehc/NetClientCh.h
|
||||||
|
src/io/socket/ehc/NetClientCh.cpp
|
||||||
|
src/io/socket/ehc/NetServerCh.cpp
|
||||||
|
src/io/socket/ehc/NetUtils.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if (IS_OS_WINDOWS)
|
if (IS_OS_WINDOWS)
|
||||||
|
@ -8,7 +8,7 @@ namespace ehs
|
|||||||
class EHS_LIB_IO BaseDNS
|
class EHS_LIB_IO BaseDNS
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Str_8 Resolve(AddrType type, const Str_8 &hostname);
|
static Str_8 Resolve(IP type, const Str_8 &hostname);
|
||||||
|
|
||||||
/// Resolves a hostname to an ip address.
|
/// Resolves a hostname to an ip address.
|
||||||
/// @param [in] hostname The given hostname to resolve.
|
/// @param [in] hostname The given hostname to resolve.
|
||||||
|
@ -12,7 +12,7 @@ namespace ehs
|
|||||||
class EHS_LIB_IO BaseTCP
|
class EHS_LIB_IO BaseTCP
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
AddrType addrType;
|
IP ip;
|
||||||
Str_8 localAddr;
|
Str_8 localAddr;
|
||||||
UInt_16 localPort;
|
UInt_16 localPort;
|
||||||
Str_8 remoteHostName;
|
Str_8 remoteHostName;
|
||||||
@ -35,7 +35,7 @@ namespace ehs
|
|||||||
|
|
||||||
/// Properly initializes the socket.
|
/// Properly initializes the socket.
|
||||||
/// @param [in] type The ip version to initialize the socket with.
|
/// @param [in] type The ip version to initialize the socket with.
|
||||||
BaseTCP(AddrType addrType);
|
BaseTCP(IP ip);
|
||||||
|
|
||||||
BaseTCP(BaseTCP&& tcp) noexcept;
|
BaseTCP(BaseTCP&& tcp) noexcept;
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ namespace ehs
|
|||||||
|
|
||||||
/// Retrieves the sockets ip version.
|
/// Retrieves the sockets ip version.
|
||||||
/// @returns The ip version.
|
/// @returns The ip version.
|
||||||
AddrType GetAddressType() const;
|
IP GetAddressType() const;
|
||||||
|
|
||||||
/// Retrieves the bound ip address.
|
/// Retrieves the bound ip address.
|
||||||
/// @returns The ip address.
|
/// @returns The ip address.
|
||||||
|
@ -9,9 +9,7 @@ namespace ehs
|
|||||||
class EHS_LIB_IO BaseUDP
|
class EHS_LIB_IO BaseUDP
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
AddrType type;
|
Endpoint localEndpoint;
|
||||||
Str_8 address;
|
|
||||||
UInt_16 port;
|
|
||||||
bool bound;
|
bool bound;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -22,7 +20,7 @@ namespace ehs
|
|||||||
|
|
||||||
/// Properly initializes the socket.
|
/// Properly initializes the socket.
|
||||||
/// @param [in] type The ip version to initialize the socket with.
|
/// @param [in] type The ip version to initialize the socket with.
|
||||||
BaseUDP(AddrType type);
|
BaseUDP(IP version);
|
||||||
|
|
||||||
BaseUDP(BaseUDP&& udp) noexcept;
|
BaseUDP(BaseUDP&& udp) noexcept;
|
||||||
|
|
||||||
@ -40,13 +38,13 @@ namespace ehs
|
|||||||
/// @param [in] address The ip address to bind to.
|
/// @param [in] address The ip address to bind to.
|
||||||
/// @param [in] port The port to bind to.
|
/// @param [in] port The port to bind to.
|
||||||
/// @note Used for servers.
|
/// @note Used for servers.
|
||||||
virtual void Bind(AddrType type, const Str_8& address, UInt_16 port) = 0;
|
virtual void Bind(const Endpoint &endpoint) = 0;
|
||||||
|
|
||||||
/// Sends data to the endpoint.
|
/// Sends data to the endpoint.
|
||||||
/// @param [in] type The ip version of the endpoint.
|
/// @param [in] type The ip version of the endpoint.
|
||||||
/// @param [in] address The ip address of the endpoint.
|
/// @param [in] address The ip address of the endpoint.
|
||||||
/// @param [in] port The port of the endpoint is bound to.
|
/// @param [in] port The port of the endpoint is bound to.
|
||||||
virtual UInt_64 Send(AddrType type, const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size) = 0;
|
virtual UInt_64 Send(const Endpoint &endpoint, const Byte *data, UInt_64 size) = 0;
|
||||||
|
|
||||||
/// Receives data from the endpoint.
|
/// Receives data from the endpoint.
|
||||||
/// @param [out] type The ip version of the endpoint.
|
/// @param [out] type The ip version of the endpoint.
|
||||||
@ -55,7 +53,7 @@ namespace ehs
|
|||||||
/// @param [out] data The incoming data from the endpoint.
|
/// @param [out] data The incoming data from the endpoint.
|
||||||
/// @param [in] size The max size of the buffer in bytes to store the data.
|
/// @param [in] size The max size of the buffer in bytes to store the data.
|
||||||
/// @returns The size of the incoming data in bytes.
|
/// @returns The size of the incoming data in bytes.
|
||||||
virtual UInt_64 Receive(AddrType* type, Str_8* address, UInt_16* port, Byte* data, UInt_64 size) = 0;
|
virtual UInt_64 Receive(Endpoint *endpoint, Byte *data, UInt_64 size) = 0;
|
||||||
|
|
||||||
/// Retrieves whether or not this socket is bound to an ip address and port.
|
/// Retrieves whether or not this socket is bound to an ip address and port.
|
||||||
/// @returns The result.
|
/// @returns The result.
|
||||||
@ -73,17 +71,7 @@ namespace ehs
|
|||||||
|
|
||||||
virtual bool IsIPv6Only() const = 0;
|
virtual bool IsIPv6Only() const = 0;
|
||||||
|
|
||||||
/// Retrieves the bound ip version.
|
Endpoint GetLocalEndpoint() const;
|
||||||
/// @returns The result.
|
|
||||||
AddrType GetLocalAddressType() const;
|
|
||||||
|
|
||||||
/// Retrieves the bound ip address.
|
|
||||||
/// @returns The bound ip address.
|
|
||||||
Str_8 GetLocalAddress() const;
|
|
||||||
|
|
||||||
/// Retrieves the bound port.
|
|
||||||
/// @returns The bound port.
|
|
||||||
UInt_16 GetLocalPort() const;
|
|
||||||
|
|
||||||
/// Retrieves whether or not this socket was initialized.
|
/// Retrieves whether or not this socket was initialized.
|
||||||
/// @returns The result.
|
/// @returns The result.
|
||||||
|
@ -10,7 +10,7 @@ namespace ehs
|
|||||||
class EHS_LIB_IO DNS final : public BaseDNS
|
class EHS_LIB_IO DNS final : public BaseDNS
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Str_8 Resolve(AddrType type, const Str_8 &hostname);
|
static Str_8 Resolve(IP type, const Str_8 &hostname);
|
||||||
|
|
||||||
static Str_8 Resolve(const Str_8 &hostname);
|
static Str_8 Resolve(const Str_8 &hostname);
|
||||||
};
|
};
|
||||||
|
@ -7,7 +7,7 @@ namespace ehs
|
|||||||
class EHS_LIB_IO DNS final : public BaseDNS
|
class EHS_LIB_IO DNS final : public BaseDNS
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Str_8 Resolve(AddrType type, const Str_8 &hostname);
|
static Str_8 Resolve(IP type, const Str_8 &hostname);
|
||||||
|
|
||||||
static Str_8 Resolve(const Str_8 &hostname);
|
static Str_8 Resolve(const Str_8 &hostname);
|
||||||
};
|
};
|
||||||
|
@ -1,78 +1,41 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ehs/io/socket/ehc/NetUtils.h"
|
|
||||||
#include "ehs/io/socket/ehc/NetEnc.h"
|
#include "ehs/io/socket/ehc/NetEnc.h"
|
||||||
#include "ehs/Serializer.h"
|
|
||||||
#include "ehs/Vector.h"
|
|
||||||
#include "ehs/Array.h"
|
#include "ehs/Array.h"
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
#include "UDP.h"
|
#include "UDP.h"
|
||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
class NetSys;
|
class NetServerCh;
|
||||||
|
class NetClientCh;
|
||||||
class NetEnd;
|
class NetEnd;
|
||||||
class EHC;
|
class EHC;
|
||||||
|
|
||||||
typedef bool (*ConnectCb)(EHC *, NetEnd **, Serializer<UInt_64>);
|
|
||||||
typedef void (*ConnectedCb)(EHC *, NetEnd *);
|
|
||||||
typedef void (*ActiveCb)(EHC *, NetEnd *);
|
|
||||||
typedef void (*DisconnectCb)(EHC *, NetEnd *, Serializer<UInt_64>);
|
|
||||||
typedef void (*DisconnectedCb)(EHC *, NetEnd *);
|
|
||||||
typedef void (*TimeoutCb)(EHC *, NetEnd *);
|
|
||||||
|
|
||||||
class EHC
|
class EHC
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
friend class NetEnc;
|
friend class NetEnc;
|
||||||
|
friend class NetChannel;
|
||||||
|
friend class NetServerCh;
|
||||||
|
friend class NetClientCh;
|
||||||
friend class NetEnd;
|
friend class NetEnd;
|
||||||
|
|
||||||
static const Version version;
|
static const Version version;
|
||||||
static const UInt_64 internalSys;
|
|
||||||
static const UInt_64 connectOp;
|
|
||||||
static const UInt_64 connectedOp;
|
|
||||||
static const UInt_64 rejectedOp;
|
|
||||||
static const UInt_64 disconnectOp;
|
|
||||||
static const UInt_64 disconnectedOp;
|
|
||||||
static const UInt_64 statusUpdateOp;
|
|
||||||
static const UInt_64 pingOp;
|
|
||||||
static const UInt_64 pongOp;
|
|
||||||
static const UInt_64 latencyOp;
|
|
||||||
static const UInt_64 receivedOp;
|
|
||||||
|
|
||||||
UDP udp;
|
UDP udp;
|
||||||
Version appVer;
|
|
||||||
EndDisp disposition;
|
|
||||||
UInt_64 hashName;
|
|
||||||
Str_8 name;
|
|
||||||
bool dropPackets;
|
|
||||||
Byte* buffer;
|
Byte* buffer;
|
||||||
UInt_32 bufferSize;
|
UInt_32 bufferSize;
|
||||||
|
UInt_64 lastTSC;
|
||||||
|
float delta;
|
||||||
Array<NetEnc *> encryptions;
|
Array<NetEnc *> encryptions;
|
||||||
Array<NetSys *> systems;
|
Array<NetServerCh *> servers;
|
||||||
UInt_32 maxEndpoints;
|
Array<NetClientCh *> clients;
|
||||||
UInt_64 lastTSC;
|
|
||||||
float delta;
|
|
||||||
float maxTimeout;
|
|
||||||
float resendRate;
|
|
||||||
ConnectCb connectCb;
|
|
||||||
ConnectedCb connectedCb;
|
|
||||||
ActiveCb activeCb;
|
|
||||||
DisconnectCb disconnectCb;
|
|
||||||
DisconnectedCb disconnectedCb;
|
|
||||||
TimeoutCb timeoutCb;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Vector<NetEnd*> endpoints;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~EHC();
|
~EHC();
|
||||||
|
|
||||||
EHC();
|
EHC(IP version = IP::V6);
|
||||||
|
|
||||||
EHC(const Version &ver, Str_8 name, UInt_64 maxEndpoints);
|
|
||||||
|
|
||||||
EHC(const Version &ver, Str_8 name);
|
|
||||||
|
|
||||||
EHC(EHC &&sock) noexcept;
|
EHC(EHC &&sock) noexcept;
|
||||||
|
|
||||||
@ -86,143 +49,47 @@ namespace ehs
|
|||||||
|
|
||||||
void Release();
|
void Release();
|
||||||
|
|
||||||
void Bind(AddrType newType, const Str_8& newAddress, UInt_16 newPort);
|
void Bind(const Endpoint &endpoint);
|
||||||
|
|
||||||
void Connect(AddrType rType, const Str_8& rAddress, UInt_16 rPort, Serializer<UInt_64> data);
|
|
||||||
|
|
||||||
bool Disconnect(EndDisp endDisp, const Char_8 token[64], const Str_8& msg);
|
|
||||||
|
|
||||||
void Broadcast(EndDisp endDisp, Status endStatus, bool deltaLocked, UInt_64 encHashId,
|
|
||||||
bool ensure, UInt_64 sysHashId, UInt_64 opHashId,
|
|
||||||
const Serializer<UInt_64> &payload);
|
|
||||||
|
|
||||||
void Broadcast(EndDisp endDisp, Status endStatus, bool deltaLocked, const Str_8 &encId,
|
|
||||||
bool ensure, const Str_8 &sysId, const Str_8 &opId,
|
|
||||||
const Serializer<UInt_64> &payload);
|
|
||||||
|
|
||||||
void Poll();
|
void Poll();
|
||||||
|
|
||||||
bool IsInitialized() const;
|
bool IsInitialized() const;
|
||||||
|
|
||||||
AddrType GetLocalAddressType() const;
|
Endpoint GetLocalEndpoint() const;
|
||||||
|
|
||||||
Str_8 GetLocalAddress() const;
|
|
||||||
|
|
||||||
UInt_16 GetLocalPort() const;
|
|
||||||
|
|
||||||
bool IsBound() const;
|
bool IsBound() const;
|
||||||
|
|
||||||
static Version GetVersion();
|
static Version GetVersion();
|
||||||
|
|
||||||
Version GetAppVersion() const;
|
|
||||||
|
|
||||||
EndDisp GetDisposition() const;
|
|
||||||
|
|
||||||
UInt_64 GetHashName() const;
|
|
||||||
|
|
||||||
Str_8 GetName() const;
|
|
||||||
|
|
||||||
void EnableDropPackets(bool enable);
|
|
||||||
|
|
||||||
bool IsDropPacketsEnabled() const;
|
|
||||||
|
|
||||||
bool HasEncryption(UInt_64 encHashId) const;
|
|
||||||
|
|
||||||
bool HasEncryption(const Str_8& encId) const;
|
|
||||||
|
|
||||||
bool AddEncryption(NetEnc *enc);
|
bool AddEncryption(NetEnc *enc);
|
||||||
|
|
||||||
NetEnc* GetEncryption(UInt_64 encHashId) const;
|
bool HasServer(UInt_64 serverId) const;
|
||||||
|
|
||||||
NetEnc* GetEncryption(const Str_8& encId) const;
|
bool HasServer(const Str_8& serverName) const;
|
||||||
|
|
||||||
bool HasSystem(UInt_64 sysHashId) const;
|
bool AddServer(NetServerCh *server);
|
||||||
|
|
||||||
bool HasSystem(const Str_8& sysId) const;
|
NetServerCh *GetServer(UInt_64 serverId) const;
|
||||||
|
|
||||||
bool AddSystem(NetSys *sys);
|
NetServerCh *GetServer(const Str_8& serverName) const;
|
||||||
|
|
||||||
NetSys* GetSystem(UInt_64 sysHashId) const;
|
bool HasClient(UInt_64 clientId) const;
|
||||||
|
|
||||||
NetSys* GetSystem(const Str_8& sysId) const;
|
bool HasClient(const Str_8& clientName) const;
|
||||||
|
|
||||||
bool HasEndpoint(EndDisp endDisp, Status endStatus, const Char_8 token[64]) const;
|
bool AddClient(NetClientCh *channel);
|
||||||
|
|
||||||
bool HasEndpoint(EndDisp endDisp, Status endStatus, UInt_64 hashId) const;
|
NetClientCh *GetClient(UInt_64 clientId) const;
|
||||||
|
|
||||||
bool HasEndpoint(EndDisp endDisp, Status endStatus, const Str_8 &id) const;
|
NetClientCh *GetClient(const Str_8& clientName) const;
|
||||||
|
|
||||||
bool HasEndpoint(EndDisp endDisp, const Char_8 token[64]) const;
|
private:
|
||||||
|
bool HasEncryption(UInt_64 encId) const;
|
||||||
|
|
||||||
bool HasEndpoint(EndDisp endDisp, UInt_64 hashId) const;
|
bool HasEncryption(const Str_8& encName) const;
|
||||||
|
|
||||||
bool HasEndpoint(EndDisp endDisp, const Str_8 &id) const;
|
NetEnc* GetEncryption(UInt_64 encId) const;
|
||||||
|
|
||||||
bool HasEndpoint(const Char_8 token[64]) const;
|
NetEnc* GetEncryption(const Str_8& encName) const;
|
||||||
|
|
||||||
bool HasEndpoint(UInt_64 hashId) const;
|
|
||||||
|
|
||||||
bool HasEndpoint(const Str_8 &id) const;
|
|
||||||
|
|
||||||
bool HasEndpoint(const Str_8& rAddress, UInt_16 rPort) const;
|
|
||||||
|
|
||||||
NetEnd *GetEndpoint(EndDisp endDisp, Status endStatus, const Char_8 token[64]) const;
|
|
||||||
|
|
||||||
NetEnd *GetEndpoint(EndDisp endDisp, Status endStatus, UInt_64 hashId) const;
|
|
||||||
|
|
||||||
NetEnd *GetEndpoint(EndDisp endDisp, Status endStatus, const Str_8 &id) const;
|
|
||||||
|
|
||||||
NetEnd *GetEndpoint(EndDisp endDisp, const Char_8 token[64]) const;
|
|
||||||
|
|
||||||
NetEnd *GetEndpoint(EndDisp endDisp, UInt_64 hashId) const;
|
|
||||||
|
|
||||||
NetEnd *GetEndpoint(EndDisp endDisp, const Str_8 &id) const;
|
|
||||||
|
|
||||||
NetEnd *GetEndpoint(const Str_8& rAddress, UInt_16 rPort) const;
|
|
||||||
|
|
||||||
Array<NetEnd *> GetEndpoints(EndDisp endDisp, Status endStatus);
|
|
||||||
|
|
||||||
Array<NetEnd *> GetEndpoints(EndDisp endDisp);
|
|
||||||
|
|
||||||
UInt_64 GetEndpointsCount(EndDisp endDisp, Status endStatus);
|
|
||||||
|
|
||||||
UInt_64 GetEndpointsCount(EndDisp endDisp);
|
|
||||||
|
|
||||||
UInt_64 GetMaxEndpoints() const;
|
|
||||||
|
|
||||||
void SetMaxTimeout(float seconds);
|
|
||||||
|
|
||||||
float GetMaxTimeout() const;
|
|
||||||
|
|
||||||
void SetResendRate(float seconds);
|
|
||||||
|
|
||||||
float GetResendRate() const;
|
|
||||||
|
|
||||||
void SetConnectCb(ConnectCb cb);
|
|
||||||
|
|
||||||
void SetConnectedCb(ConnectedCb cb);
|
|
||||||
|
|
||||||
void SetActiveCb(ActiveCb cb);
|
|
||||||
|
|
||||||
void SetDisconnectCb(DisconnectCb cb);
|
|
||||||
|
|
||||||
void SetDisconnectedCb(DisconnectedCb cb);
|
|
||||||
|
|
||||||
void SetTimeoutCb(TimeoutCb cb);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void GenerateToken(Char_8 in[64]);
|
|
||||||
|
|
||||||
void UpdateQueue(UInt_64 active);
|
|
||||||
|
|
||||||
void UpdateQueue();
|
|
||||||
|
|
||||||
bool RemoveEndpoint(EndDisp disposition, const Char_8 token[64]);
|
|
||||||
|
|
||||||
bool RemoveEndpoint(const Str_8& address, UInt_16 port);
|
|
||||||
|
|
||||||
bool RemoveEndpoint(const NetEnd* end);
|
|
||||||
|
|
||||||
void PollEndpoints();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -23,7 +23,7 @@ namespace ehs
|
|||||||
|
|
||||||
SSL();
|
SSL();
|
||||||
|
|
||||||
SSL(const AddrType type);
|
SSL(const IP type);
|
||||||
|
|
||||||
SSL(TCP&& tcp) noexcept;
|
SSL(TCP&& tcp) noexcept;
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "ehs/Str.h"
|
||||||
|
|
||||||
#ifndef EHS_IPV4_HEADER
|
#ifndef EHS_IPV4_HEADER
|
||||||
#define EHS_IPV4_HEADER 60
|
#define EHS_IPV4_HEADER 60
|
||||||
|
#include <string>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef EHS_IPV6_HEADER
|
#ifndef EHS_IPV6_HEADER
|
||||||
@ -22,10 +25,10 @@
|
|||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
enum class AddrType
|
enum class IP
|
||||||
{
|
{
|
||||||
IPV6,
|
V4,
|
||||||
IPV4
|
V6
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class ContentType
|
enum class ContentType
|
||||||
@ -41,6 +44,13 @@ namespace ehs
|
|||||||
NONE
|
NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Endpoint
|
||||||
|
{
|
||||||
|
IP version = IP::V6;
|
||||||
|
Str_8 address;
|
||||||
|
UInt_16 port = 0;
|
||||||
|
};
|
||||||
|
|
||||||
#if defined(EHS_OS_WINDOWS)
|
#if defined(EHS_OS_WINDOWS)
|
||||||
typedef UInt_64 Socket;
|
typedef UInt_64 Socket;
|
||||||
#define EHS_INVALID_SOCKET EHS_UINT_64_MAX
|
#define EHS_INVALID_SOCKET EHS_UINT_64_MAX
|
||||||
|
@ -22,7 +22,7 @@ namespace ehs
|
|||||||
/// Default members initialization.
|
/// Default members initialization.
|
||||||
TCP();
|
TCP();
|
||||||
|
|
||||||
TCP(AddrType addrType);
|
TCP(IP IP);
|
||||||
|
|
||||||
TCP(TCP&& tcp) noexcept;
|
TCP(TCP&& tcp) noexcept;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ namespace ehs
|
|||||||
/// Default members initialization.
|
/// Default members initialization.
|
||||||
TCP();
|
TCP();
|
||||||
|
|
||||||
TCP(AddrType addrType);
|
TCP(IP IP);
|
||||||
|
|
||||||
TCP(TCP&& tcp) noexcept;
|
TCP(TCP&& tcp) noexcept;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ namespace ehs
|
|||||||
UDP();
|
UDP();
|
||||||
|
|
||||||
/// Default members initialization.
|
/// Default members initialization.
|
||||||
UDP(AddrType type);
|
UDP(IP version);
|
||||||
|
|
||||||
UDP(UDP&& udp) noexcept;
|
UDP(UDP&& udp) noexcept;
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ namespace ehs
|
|||||||
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||||
/// @param [in] port The port to bind to.
|
/// @param [in] port The port to bind to.
|
||||||
/// @note Requires the port given to be forwarded if this is called.
|
/// @note Requires the port given to be forwarded if this is called.
|
||||||
void Bind(AddrType type, const Str_8& address, UInt_16 port) override;
|
void Bind(const Endpoint &endpoint) override;
|
||||||
|
|
||||||
/// Sends data using a C-style byte array.
|
/// Sends data using a C-style byte array.
|
||||||
/// @param [in] addr The remote Ipv4 or Ipv6 address to send to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
/// @param [in] addr The remote Ipv4 or Ipv6 address to send to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||||
@ -49,7 +49,7 @@ namespace ehs
|
|||||||
/// @param [in] data The C-style byte array to send.
|
/// @param [in] data The C-style byte array to send.
|
||||||
/// @param [in] size The size of the C-style byte array.
|
/// @param [in] size The size of the C-style byte array.
|
||||||
/// @note The size of data to be sent cannot exceed "UDP::maxPayloadIpv4" or "UDP::maxPayloadIpv6".
|
/// @note The size of data to be sent cannot exceed "UDP::maxPayloadIpv4" or "UDP::maxPayloadIpv6".
|
||||||
UInt_64 Send(AddrType type, const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size) override;
|
UInt_64 Send(const Endpoint &endpoint, const Byte* data, UInt_64 size) override;
|
||||||
|
|
||||||
/// Receives data using the packet helper class.
|
/// Receives data using the packet helper class.
|
||||||
/// @param [out] addr The Ipv4 or Ipv6 address of the sender.
|
/// @param [out] addr The Ipv4 or Ipv6 address of the sender.
|
||||||
@ -58,7 +58,7 @@ namespace ehs
|
|||||||
/// @param [in] size The size of the pre-allocated C-style byte array.
|
/// @param [in] size The size of the pre-allocated C-style byte array.
|
||||||
/// @returns The size of the data received.
|
/// @returns The size of the data received.
|
||||||
/// @warning The provided C-style byte array must be freed when finished using.
|
/// @warning The provided C-style byte array must be freed when finished using.
|
||||||
UInt_64 Receive(AddrType* type, Str_8* address, UInt_16* port, Byte* data, UInt_64 size) override;
|
UInt_64 Receive(Endpoint *endpoint, Byte* data, UInt_64 size) override;
|
||||||
|
|
||||||
/// Sets whether or not receiving data blocks the next task.
|
/// Sets whether or not receiving data blocks the next task.
|
||||||
/// @param [in] blocking Whether or not to block.
|
/// @param [in] blocking Whether or not to block.
|
||||||
|
@ -19,7 +19,7 @@ namespace ehs
|
|||||||
UDP();
|
UDP();
|
||||||
|
|
||||||
/// Default members initialization.
|
/// Default members initialization.
|
||||||
UDP(const AddrType addrType);
|
UDP(const IP IP);
|
||||||
|
|
||||||
UDP(UDP&& udp) noexcept;
|
UDP(UDP&& udp) noexcept;
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ namespace ehs
|
|||||||
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||||
/// @param [in] port The port to bind to.
|
/// @param [in] port The port to bind to.
|
||||||
/// @note Requires the port given to be forwarded if this is called.
|
/// @note Requires the port given to be forwarded if this is called.
|
||||||
void Bind(AddrType type, const Str_8& address, UInt_16 port) override;
|
void Bind(const Endpoint &endpoint) override;
|
||||||
|
|
||||||
/// Sends data using a C-style byte array.
|
/// Sends data using a C-style byte array.
|
||||||
/// @param [in] addr The remote Ipv4 or Ipv6 address to send to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
/// @param [in] addr The remote Ipv4 or Ipv6 address to send to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||||
@ -49,7 +49,7 @@ namespace ehs
|
|||||||
/// @param [in] data The C-style byte array to send.
|
/// @param [in] data The C-style byte array to send.
|
||||||
/// @param [in] size The size of the C-style byte array.
|
/// @param [in] size The size of the C-style byte array.
|
||||||
/// @note The size of data to be sent cannot exceed "UDP::maxPayloadIpv4" or "UDP::maxPayloadIpv6".
|
/// @note The size of data to be sent cannot exceed "UDP::maxPayloadIpv4" or "UDP::maxPayloadIpv6".
|
||||||
UInt_64 Send(AddrType type, const Str_8& addr, UInt_16 port, const Byte* data, UInt_64 size) override;
|
UInt_64 Send(const Endpoint &endpoint, const Byte* data, UInt_64 size) override;
|
||||||
|
|
||||||
/// Receives data using the packet helper class.
|
/// Receives data using the packet helper class.
|
||||||
/// @param [out] addr The Ipv4 or Ipv6 address of the sender.
|
/// @param [out] addr The Ipv4 or Ipv6 address of the sender.
|
||||||
@ -58,7 +58,7 @@ namespace ehs
|
|||||||
/// @param [in] size The size of the pre-allocated C-style byte array.
|
/// @param [in] size The size of the pre-allocated C-style byte array.
|
||||||
/// @returns The size of the data received.
|
/// @returns The size of the data received.
|
||||||
/// @warning The provided C-style byte array must be freed when finished using.
|
/// @warning The provided C-style byte array must be freed when finished using.
|
||||||
UInt_64 Receive(AddrType* type, Str_8* addr, UInt_16* port, Byte* data, UInt_64 size) override;
|
UInt_64 Receive(Endpoint *endpoint, Byte* data, UInt_64 size) override;
|
||||||
|
|
||||||
/// Sets whether or not receiving data blocks the next task.
|
/// Sets whether or not receiving data blocks the next task.
|
||||||
/// @param [in] blocking Whether or not to block.
|
/// @param [in] blocking Whether or not to block.
|
||||||
|
94
include/ehs/io/socket/ehc/NetChannel.h
Normal file
94
include/ehs/io/socket/ehc/NetChannel.h
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ehs/Str.h"
|
||||||
|
#include "ehs/Array.h"
|
||||||
|
#include "ehs/io/socket/Socket.h"
|
||||||
|
#include "NetUtils.h"
|
||||||
|
|
||||||
|
namespace ehs
|
||||||
|
{
|
||||||
|
class EHC;
|
||||||
|
class NetEnd;
|
||||||
|
class NetSys;
|
||||||
|
|
||||||
|
class NetChannel
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
static const UInt_64 internalSys;
|
||||||
|
static const UInt_64 connectOp;
|
||||||
|
static const UInt_64 connectedOp;
|
||||||
|
static const UInt_64 rejectedOp;
|
||||||
|
static const UInt_64 disconnectOp;
|
||||||
|
static const UInt_64 disconnectedOp;
|
||||||
|
static const UInt_64 statusUpdateOp;
|
||||||
|
static const UInt_64 pingOp;
|
||||||
|
static const UInt_64 pongOp;
|
||||||
|
static const UInt_64 latencyOp;
|
||||||
|
static const UInt_64 receivedOp;
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class EHC;
|
||||||
|
|
||||||
|
EHC *owner;
|
||||||
|
UInt_64 id;
|
||||||
|
Str_8 name;
|
||||||
|
Version version;
|
||||||
|
float maxTimeout;
|
||||||
|
float resendRate;
|
||||||
|
bool dropPackets;
|
||||||
|
Array<NetSys *> systems;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~NetChannel();
|
||||||
|
|
||||||
|
NetChannel();
|
||||||
|
|
||||||
|
NetChannel(Str_8 name, const Version &version);
|
||||||
|
|
||||||
|
NetChannel(NetChannel &&channel) noexcept;
|
||||||
|
|
||||||
|
NetChannel(const NetChannel &channel);
|
||||||
|
|
||||||
|
NetChannel &operator=(NetChannel &&channel) noexcept;
|
||||||
|
|
||||||
|
NetChannel &operator=(const NetChannel &channel);
|
||||||
|
|
||||||
|
EHC *GetOwner() const;
|
||||||
|
|
||||||
|
UInt_64 GetId() const;
|
||||||
|
|
||||||
|
Str_8 GetName() const;
|
||||||
|
|
||||||
|
Version GetVersion() const;
|
||||||
|
|
||||||
|
void SetMaxTimeout(float seconds);
|
||||||
|
|
||||||
|
float GetMaxTimeout() const;
|
||||||
|
|
||||||
|
void SetResendRate(float seconds);
|
||||||
|
|
||||||
|
float GetResendRate() const;
|
||||||
|
|
||||||
|
void EnableDropPackets(bool enable);
|
||||||
|
|
||||||
|
bool IsDropPacketsEnabled() const;
|
||||||
|
|
||||||
|
bool AddSystem(NetSys *sys);
|
||||||
|
|
||||||
|
bool IsValid() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void Process(const float &delta, const Endpoint &endpoint, const Header &header, Serializer<UInt_64> &payload);
|
||||||
|
|
||||||
|
virtual void Poll(const float &delta);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool HasSystem(UInt_64 sysId) const;
|
||||||
|
|
||||||
|
bool HasSystem(const Str_8& sysName) const;
|
||||||
|
|
||||||
|
NetSys* GetSystem(UInt_64 sysId) const;
|
||||||
|
|
||||||
|
NetSys* GetSystem(const Str_8& sysName) const;
|
||||||
|
};
|
||||||
|
}
|
81
include/ehs/io/socket/ehc/NetClientCh.h
Normal file
81
include/ehs/io/socket/ehc/NetClientCh.h
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "NetChannel.h"
|
||||||
|
#include "ehs/io/socket/Socket.h"
|
||||||
|
#include "ehs/io/socket/ehc/NetEnc.h"
|
||||||
|
#include "ehs/io/socket/ehc/NetFrag.h"
|
||||||
|
|
||||||
|
namespace ehs
|
||||||
|
{
|
||||||
|
class NetClientCh : public NetChannel
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
friend class EHC;
|
||||||
|
|
||||||
|
Endpoint remoteEndpoint;
|
||||||
|
Char_8 token[64];
|
||||||
|
NetStatus status;
|
||||||
|
UInt_64 queueSlot;
|
||||||
|
float deltaDuration;
|
||||||
|
float deltaRate;
|
||||||
|
float lastPing;
|
||||||
|
float latency;
|
||||||
|
float timeout;
|
||||||
|
UInt_64 nextSendId;
|
||||||
|
Vector<Insurance> sent;
|
||||||
|
UInt_64 nextRecvId;
|
||||||
|
Vector<NetFrag> received;
|
||||||
|
|
||||||
|
public:
|
||||||
|
~NetClientCh();
|
||||||
|
|
||||||
|
NetClientCh();
|
||||||
|
|
||||||
|
NetClientCh(Str_8 name, const Version &version, Endpoint remoteEndpoint);
|
||||||
|
|
||||||
|
NetClientCh(NetClientCh &&client) noexcept;
|
||||||
|
|
||||||
|
NetClientCh(const NetClientCh &client);
|
||||||
|
|
||||||
|
NetClientCh &operator=(NetClientCh &&client) noexcept;
|
||||||
|
|
||||||
|
NetClientCh &operator=(const NetClientCh &client);
|
||||||
|
|
||||||
|
virtual void OnConnected(Serializer<UInt_64> data);
|
||||||
|
|
||||||
|
virtual void OnActive(Serializer<UInt_64> data);
|
||||||
|
|
||||||
|
virtual void OnQueueUpdate(Serializer<UInt_64> data);
|
||||||
|
|
||||||
|
virtual void OnDisconnected(Serializer<UInt_64> data);
|
||||||
|
|
||||||
|
virtual void OnRejected(Serializer<UInt_64> data);
|
||||||
|
|
||||||
|
virtual void OnTimeout(Serializer<UInt_64> data);
|
||||||
|
|
||||||
|
void Connect(const Endpoint &endpoint, const Serializer<UInt_64>& payload);
|
||||||
|
|
||||||
|
bool Disconnect(const Serializer<UInt_64>& payload);
|
||||||
|
|
||||||
|
void Send(bool deltaLocked, UInt_64 encId, bool ensure, UInt_64 sysId, UInt_64 opId, const Serializer<UInt_64>& payload);
|
||||||
|
|
||||||
|
void Send(bool deltaLocked, const Str_8 &encName, bool ensure, const Str_8& sysName, const Str_8& opName, const Serializer<UInt_64>& payload);
|
||||||
|
|
||||||
|
NetStatus GetStatus() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Process(const float &delta, const Endpoint &endpoint, const Header &header, Serializer<UInt_64> &payload) override;
|
||||||
|
|
||||||
|
void Poll(const float &delta) override;
|
||||||
|
|
||||||
|
NetFrag FragmentData(IP version, const Header& header, const Serializer<>& data);
|
||||||
|
|
||||||
|
void Send(NetEnc *enc, const Header& header, const Serializer<>& payload);
|
||||||
|
|
||||||
|
void Pong(float delta);
|
||||||
|
|
||||||
|
void RemoveInsurance(UInt_64 msgId, UInt_64 fragment);
|
||||||
|
|
||||||
|
void AddReceived(const Header& header, const Serializer<>& payload);
|
||||||
|
};
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ehs/Str.h"
|
#include "ehs/Str.h"
|
||||||
|
#include "ehs/Version.h"
|
||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
@ -11,16 +12,16 @@ namespace ehs
|
|||||||
private:
|
private:
|
||||||
friend class EHC;
|
friend class EHC;
|
||||||
|
|
||||||
EHC *owner;
|
UInt_64 id;
|
||||||
UInt_64 hashId;
|
Str_8 name;
|
||||||
Str_8 id;
|
Version version;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~NetEnc() = default;
|
virtual ~NetEnc() = default;
|
||||||
|
|
||||||
NetEnc();
|
NetEnc();
|
||||||
|
|
||||||
NetEnc(Str_8 id);
|
NetEnc(Str_8 name, const Version &version);
|
||||||
|
|
||||||
NetEnc(NetEnc &&enc) noexcept;
|
NetEnc(NetEnc &&enc) noexcept;
|
||||||
|
|
||||||
@ -30,14 +31,14 @@ namespace ehs
|
|||||||
|
|
||||||
NetEnc &operator=(const NetEnc &enc);
|
NetEnc &operator=(const NetEnc &enc);
|
||||||
|
|
||||||
EHC *GetOwner() const;
|
UInt_64 GetId() const;
|
||||||
|
|
||||||
UInt_64 GetHashId() const;
|
Str_8 GetName() const;
|
||||||
|
|
||||||
Str_8 GetId() const;
|
Version GetVersion() const;
|
||||||
|
|
||||||
virtual void Encrypt(Byte *data, UInt_64 size) const;
|
virtual void Encrypt(Byte *data, UInt_64 size) const;
|
||||||
|
|
||||||
virtual void Decrypt(Byte *data, UInt_64 size) const;
|
virtual void Decrypt(Byte *data, UInt_64 size) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "NetUtils.h"
|
#include "NetUtils.h"
|
||||||
#include "NetFrags.h"
|
#include "NetFrag.h"
|
||||||
|
|
||||||
#include "ehs/Str.h"
|
#include "ehs/Str.h"
|
||||||
#include "ehs/Vector.h"
|
#include "ehs/Vector.h"
|
||||||
@ -10,27 +10,23 @@
|
|||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
class EHC;
|
class NetServerCh;
|
||||||
|
|
||||||
class NetEnd
|
class NetEnd
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
friend class EHC;
|
friend class NetServerCh;
|
||||||
|
|
||||||
EHC* owner;
|
NetServerCh* owner;
|
||||||
EndDisp disposition;
|
UInt_64 id;
|
||||||
UInt_64 hashName;
|
|
||||||
Str_8 name;
|
Str_8 name;
|
||||||
Status status;
|
NetStatus status;
|
||||||
Architecture arch;
|
|
||||||
Char_8 token[64];
|
Char_8 token[64];
|
||||||
UInt_64 nextSendId;
|
UInt_64 nextSendId;
|
||||||
Vector<Insurance> sent;
|
Vector<Insurance> sent;
|
||||||
UInt_64 nextRecvId;
|
UInt_64 nextRecvId;
|
||||||
Vector<NetFrags> received;
|
Vector<NetFrag> received;
|
||||||
AddrType type;
|
Endpoint endpoint;
|
||||||
Str_8 address;
|
|
||||||
UInt_16 port;
|
|
||||||
float deltaDuration;
|
float deltaDuration;
|
||||||
float deltaRate;
|
float deltaRate;
|
||||||
float timeout;
|
float timeout;
|
||||||
@ -42,9 +38,9 @@ namespace ehs
|
|||||||
public:
|
public:
|
||||||
NetEnd();
|
NetEnd();
|
||||||
|
|
||||||
NetEnd(EndDisp disposition, Str_8 id, Architecture arch, AddrType type, Str_8 address, UInt_16 port);
|
NetEnd(Str_8 id, Endpoint endpoint);
|
||||||
|
|
||||||
NetEnd(AddrType type, Str_8 address, UInt_16 port);
|
NetEnd(Endpoint endpoint);
|
||||||
|
|
||||||
NetEnd(NetEnd &&end) noexcept;
|
NetEnd(NetEnd &&end) noexcept;
|
||||||
|
|
||||||
@ -54,15 +50,11 @@ namespace ehs
|
|||||||
|
|
||||||
NetEnd &operator=(const NetEnd &end);
|
NetEnd &operator=(const NetEnd &end);
|
||||||
|
|
||||||
EndDisp GetDisposition() const;
|
UInt_64 GetId() const;
|
||||||
|
|
||||||
UInt_64 GetHashName() const;
|
|
||||||
|
|
||||||
Str_8 GetName() const;
|
Str_8 GetName() const;
|
||||||
|
|
||||||
Status GetStatus() const;
|
NetStatus GetStatus() const;
|
||||||
|
|
||||||
Architecture GetArchitecture() const;
|
|
||||||
|
|
||||||
UInt_64 GetNextSendId() const;
|
UInt_64 GetNextSendId() const;
|
||||||
|
|
||||||
@ -73,7 +65,7 @@ namespace ehs
|
|||||||
/// @param [in] sys The system hash id to execute an operation from.
|
/// @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] op The operation hash id in the system to execute.
|
||||||
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
|
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
|
||||||
void Send(bool deltaLocked, UInt_64 encHashId, bool ensure, UInt_64 sys, UInt_64 op, const Serializer<UInt_64>& payload);
|
void Send(bool deltaLocked, UInt_64 encId, bool ensure, UInt_64 sysId, UInt_64 opId, const Serializer<UInt_64>& payload);
|
||||||
|
|
||||||
/// Sends data to the remote endpoint.
|
/// 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] 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.
|
||||||
@ -82,13 +74,11 @@ namespace ehs
|
|||||||
/// @param [in] sys The system string id to execute an operation from.
|
/// @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] op The operation string id in the system to execute.
|
||||||
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
|
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
|
||||||
void Send(bool deltaLocked, const Str_8 &encID, bool ensure, const Str_8& sys, const Str_8& op, const Serializer<UInt_64>& payload);
|
void Send(bool deltaLocked, const Str_8 &encName, bool ensure, const Str_8& sysName, const Str_8& opName, const Serializer<UInt_64>& payload);
|
||||||
|
|
||||||
UInt_64 GetNextRecvId() const;
|
UInt_64 GetNextRecvId() const;
|
||||||
|
|
||||||
Str_8 GetAddress() const;
|
Endpoint GetEndpoint() const;
|
||||||
|
|
||||||
UInt_16 GetPort() const;
|
|
||||||
|
|
||||||
void SetDeltaRate(float newDeltaRate);
|
void SetDeltaRate(float newDeltaRate);
|
||||||
|
|
||||||
@ -107,23 +97,21 @@ namespace ehs
|
|||||||
private:
|
private:
|
||||||
void Poll(float delta);
|
void Poll(float delta);
|
||||||
|
|
||||||
void SetStatus(Status newStatus);
|
void SetStatus(NetStatus newStatus);
|
||||||
|
|
||||||
void RemoveInsurance(UInt_64 msgId, UInt_64 fragment);
|
void RemoveInsurance(UInt_64 msgId, UInt_64 fragment);
|
||||||
|
|
||||||
void AddReceived(const Header& header, const Serializer<>& payload);
|
void AddReceived(const Header& header, const Serializer<>& payload);
|
||||||
|
|
||||||
Vector<NetFrags>* GetReceived();
|
Vector<NetFrag>* GetReceived();
|
||||||
|
|
||||||
void Ping(float delta);
|
void Ping(float delta);
|
||||||
|
|
||||||
void Pong(float delta);
|
|
||||||
|
|
||||||
void SetLatency(float newLatency);
|
void SetLatency(float newLatency);
|
||||||
|
|
||||||
void SetQueueSlot(UInt_64 slot);
|
void SetQueueSlot(UInt_64 slot);
|
||||||
|
|
||||||
NetFrags FragmentData(const Header& header, const Serializer<>& data);
|
NetFrag FragmentData(const Header& header, const Serializer<>& data);
|
||||||
|
|
||||||
void Send(const Header& header, const Serializer<>& payload);
|
void Send(const Header& header, const Serializer<>& payload);
|
||||||
|
|
||||||
|
43
include/ehs/io/socket/ehc/NetFrag.h
Normal file
43
include/ehs/io/socket/ehc/NetFrag.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "NetUtils.h"
|
||||||
|
|
||||||
|
#include <ehs/Serializer.h>
|
||||||
|
|
||||||
|
namespace ehs
|
||||||
|
{
|
||||||
|
class NetFrag
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Header header;
|
||||||
|
Serializer<UInt_64>* data;
|
||||||
|
UInt_64 size;
|
||||||
|
|
||||||
|
public:
|
||||||
|
~NetFrag();
|
||||||
|
|
||||||
|
NetFrag();
|
||||||
|
|
||||||
|
NetFrag(const Header &header, const Serializer<UInt_64> &payload);
|
||||||
|
|
||||||
|
NetFrag(const Header &header, UInt_64 size);
|
||||||
|
|
||||||
|
NetFrag(NetFrag &&frags) noexcept;
|
||||||
|
|
||||||
|
NetFrag(const NetFrag &frags);
|
||||||
|
|
||||||
|
NetFrag &operator=(NetFrag &&frags) noexcept;
|
||||||
|
|
||||||
|
NetFrag &operator=(const NetFrag &frags);
|
||||||
|
|
||||||
|
operator Serializer<UInt_64> *() const;
|
||||||
|
|
||||||
|
Header GetHeader() const;
|
||||||
|
|
||||||
|
UInt_64 Size() const;
|
||||||
|
|
||||||
|
bool IsComplete() const;
|
||||||
|
|
||||||
|
Packet Combine() const;
|
||||||
|
};
|
||||||
|
}
|
@ -1,43 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "NetUtils.h"
|
|
||||||
|
|
||||||
#include <ehs/Serializer.h>
|
|
||||||
|
|
||||||
namespace ehs
|
|
||||||
{
|
|
||||||
class NetFrags
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
Header header;
|
|
||||||
Serializer<UInt_64>* data;
|
|
||||||
UInt_64 size;
|
|
||||||
|
|
||||||
public:
|
|
||||||
~NetFrags();
|
|
||||||
|
|
||||||
NetFrags();
|
|
||||||
|
|
||||||
NetFrags(const Header &header, const Serializer<UInt_64> &payload);
|
|
||||||
|
|
||||||
NetFrags(const Header &header, UInt_64 size);
|
|
||||||
|
|
||||||
NetFrags(NetFrags &&frags) noexcept;
|
|
||||||
|
|
||||||
NetFrags(const NetFrags &frags);
|
|
||||||
|
|
||||||
NetFrags &operator=(NetFrags &&frags) noexcept;
|
|
||||||
|
|
||||||
NetFrags &operator=(const NetFrags &frags);
|
|
||||||
|
|
||||||
operator Serializer<UInt_64> *() const;
|
|
||||||
|
|
||||||
Header GetHeader() const;
|
|
||||||
|
|
||||||
UInt_64 Size() const;
|
|
||||||
|
|
||||||
bool IsComplete() const;
|
|
||||||
|
|
||||||
Packet Combine() const;
|
|
||||||
};
|
|
||||||
}
|
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
class EHC;
|
class NetChannel;
|
||||||
class NetSys;
|
class NetSys;
|
||||||
class NetEnd;
|
class NetEnd;
|
||||||
|
|
||||||
@ -14,15 +14,15 @@ namespace ehs
|
|||||||
private:
|
private:
|
||||||
friend class NetSys;
|
friend class NetSys;
|
||||||
|
|
||||||
UInt_64 hashId;
|
UInt_64 id;
|
||||||
Str_8 id;
|
Str_8 name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~NetOp() = default;
|
virtual ~NetOp() = default;
|
||||||
|
|
||||||
NetOp();
|
NetOp();
|
||||||
|
|
||||||
NetOp(Str_8 id);
|
NetOp(Str_8 name);
|
||||||
|
|
||||||
NetOp(NetOp &&op) noexcept;
|
NetOp(NetOp &&op) noexcept;
|
||||||
|
|
||||||
@ -32,11 +32,11 @@ namespace ehs
|
|||||||
|
|
||||||
NetOp &operator=(const NetOp &op);
|
NetOp &operator=(const NetOp &op);
|
||||||
|
|
||||||
Str_8 GetId() const;
|
UInt_64 GetId() const;
|
||||||
|
|
||||||
UInt_64 GetHashId() const;
|
Str_8 GetName() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void Process(EHC *ehc, NetEnd *endpoint, NetSys *sys, Serializer<UInt_64> &payload);
|
virtual void Execute(NetChannel *channel, NetEnd *issuer, NetSys *sys, Serializer<UInt_64> &payload);
|
||||||
};
|
};
|
||||||
}
|
}
|
105
include/ehs/io/socket/ehc/NetServerCh.h
Normal file
105
include/ehs/io/socket/ehc/NetServerCh.h
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "NetChannel.h"
|
||||||
|
|
||||||
|
namespace ehs
|
||||||
|
{
|
||||||
|
class NetEnd;
|
||||||
|
|
||||||
|
class NetServerCh : public NetChannel
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
friend class EHC;
|
||||||
|
|
||||||
|
Vector<NetEnd *> endpoints;
|
||||||
|
UInt_64 maxEndpoints;
|
||||||
|
|
||||||
|
public:
|
||||||
|
~NetServerCh() override;
|
||||||
|
|
||||||
|
NetServerCh();
|
||||||
|
|
||||||
|
NetServerCh(Str_8 name, const Version &version, UInt_64 maxEndpoints);
|
||||||
|
|
||||||
|
NetServerCh(NetServerCh &&server) noexcept;
|
||||||
|
|
||||||
|
NetServerCh(const NetServerCh &server);
|
||||||
|
|
||||||
|
NetServerCh &operator=(NetServerCh &&server) noexcept;
|
||||||
|
|
||||||
|
NetServerCh &operator=(const NetServerCh &server);
|
||||||
|
|
||||||
|
virtual bool OnEndpointConnect(NetEnd *endpoint, Serializer<UInt_64> payload);
|
||||||
|
|
||||||
|
virtual Serializer<UInt_64> OnEndpointAccepted(NetEnd *endpoint);
|
||||||
|
|
||||||
|
virtual void OnEndpointDisconnect(NetEnd *endpoint, Serializer<UInt_64> payload);
|
||||||
|
|
||||||
|
virtual void OnEndpointTimeout(NetEnd *endpoint);
|
||||||
|
|
||||||
|
virtual void OnEndpointActive(NetEnd *endpoint);
|
||||||
|
|
||||||
|
virtual Serializer<UInt_64> OnShutdown();
|
||||||
|
|
||||||
|
void Broadcast(NetStatus endStatus, bool deltaLocked, UInt_64 encHashId,
|
||||||
|
bool ensure, UInt_64 sysHashId, UInt_64 opHashId,
|
||||||
|
const Serializer<UInt_64> &payload);
|
||||||
|
|
||||||
|
void Broadcast(NetStatus endStatus, bool deltaLocked, const Str_8 &encId,
|
||||||
|
bool ensure, const Str_8 &sysId, const Str_8 &opId,
|
||||||
|
const Serializer<UInt_64> &payload);
|
||||||
|
|
||||||
|
bool HasEndpoint(NetStatus endStatus, const Char_8 token[64]) const;
|
||||||
|
|
||||||
|
bool HasEndpoint(NetStatus endStatus, UInt_64 hashId) const;
|
||||||
|
|
||||||
|
bool HasEndpoint(NetStatus endStatus, const Str_8 &id) const;
|
||||||
|
|
||||||
|
bool HasEndpoint(const Char_8 token[64]) const;
|
||||||
|
|
||||||
|
bool HasEndpoint(UInt_64 hashId) const;
|
||||||
|
|
||||||
|
bool HasEndpoint(const Str_8 &id) const;
|
||||||
|
|
||||||
|
bool HasEndpoint(const Endpoint &endpoint) const;
|
||||||
|
|
||||||
|
NetEnd *GetEndpoint(NetStatus endStatus, const Char_8 token[64]) const;
|
||||||
|
|
||||||
|
NetEnd *GetEndpoint(NetStatus endStatus, UInt_64 hashId) const;
|
||||||
|
|
||||||
|
NetEnd *GetEndpoint(NetStatus endStatus, const Str_8 &id) const;
|
||||||
|
|
||||||
|
NetEnd *GetEndpoint(const Char_8 token[64]) const;
|
||||||
|
|
||||||
|
NetEnd *GetEndpoint(UInt_64 hashId) const;
|
||||||
|
|
||||||
|
NetEnd *GetEndpoint(const Str_8 &id) const;
|
||||||
|
|
||||||
|
NetEnd *GetEndpoint(const Endpoint &endpoint) const;
|
||||||
|
|
||||||
|
Array<NetEnd *> GetEndpoints(NetStatus endStatus);
|
||||||
|
|
||||||
|
UInt_64 GetEndpointsCount(NetStatus endStatus);
|
||||||
|
|
||||||
|
UInt_64 GetMaxEndpoints() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Process(const float &delta, const Endpoint &endpoint, const Header &header, Serializer<UInt_64> &payload) override;
|
||||||
|
|
||||||
|
void GenerateToken(Char_8 in[64]);
|
||||||
|
|
||||||
|
void UpdateQueue(UInt_64 active);
|
||||||
|
|
||||||
|
void UpdateQueue();
|
||||||
|
|
||||||
|
bool RemoveEndpoint(const Char_8 token[64]);
|
||||||
|
|
||||||
|
bool RemoveEndpoint(const Endpoint &endpoint);
|
||||||
|
|
||||||
|
bool RemoveEndpoint(const NetEnd* end);
|
||||||
|
|
||||||
|
void Poll(const float &delta) override;
|
||||||
|
|
||||||
|
void Shutdown();
|
||||||
|
};
|
||||||
|
}
|
@ -6,17 +6,19 @@
|
|||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
class EHC;
|
class NetChannel;
|
||||||
class NetEnd;
|
class NetEnd;
|
||||||
class NetOp;
|
class NetOp;
|
||||||
|
|
||||||
class NetSys
|
class NetSys
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
friend class EHC;
|
friend class NetChannel;
|
||||||
|
friend class NetServerCh;
|
||||||
|
friend class NetClientCh;
|
||||||
|
|
||||||
UInt_64 hashId;
|
UInt_64 id;
|
||||||
Str_8 id;
|
Str_8 name;
|
||||||
Array<NetOp*> ops;
|
Array<NetOp*> ops;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -24,7 +26,7 @@ namespace ehs
|
|||||||
|
|
||||||
NetSys();
|
NetSys();
|
||||||
|
|
||||||
NetSys(Str_8 id);
|
NetSys(Str_8 name);
|
||||||
|
|
||||||
NetSys(NetSys &&sys) noexcept;
|
NetSys(NetSys &&sys) noexcept;
|
||||||
|
|
||||||
@ -34,15 +36,15 @@ namespace ehs
|
|||||||
|
|
||||||
NetSys &operator=(const NetSys &sys);
|
NetSys &operator=(const NetSys &sys);
|
||||||
|
|
||||||
Str_8 GetId() const;
|
UInt_64 GetId() const;
|
||||||
|
|
||||||
UInt_64 GetHashId() const;
|
Str_8 GetName() const;
|
||||||
|
|
||||||
bool HasOperation(UInt_64 hashId) const;
|
bool HasOperation(UInt_64 id) const;
|
||||||
|
|
||||||
bool AddOperation(NetOp *op);
|
bool AddOperation(NetOp *op);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Execute(EHC *ehc, NetEnd *endpoint, UInt_64 hashId, Serializer<UInt_64> &payload);
|
void Execute(NetChannel *channel, NetEnd *issuer, UInt_64 opId, Serializer<UInt_64> &payload);
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -4,33 +4,41 @@
|
|||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
enum class EndDisp : UInt_8
|
enum class NetStatus : UInt_8
|
||||||
{
|
|
||||||
ENDPOINT,
|
|
||||||
SERVICE
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class Status : UInt_8
|
|
||||||
{
|
{
|
||||||
|
DISCONNECTED,
|
||||||
ACTIVE,
|
ACTIVE,
|
||||||
PENDING,
|
PENDING,
|
||||||
IN_LOCAL_QUEUE,
|
QUEUED
|
||||||
IN_REMOTE_QUEUE,
|
};
|
||||||
|
|
||||||
|
enum class NetChannelType : UInt_8
|
||||||
|
{
|
||||||
|
SERVER,
|
||||||
|
CLIENT
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Header
|
struct Header
|
||||||
{
|
{
|
||||||
UInt_64 encHashId = 0;
|
Version version = {};
|
||||||
|
UInt_64 encId = 0;
|
||||||
|
Version encVer = {};
|
||||||
|
UInt_64 channelId = 0;
|
||||||
|
NetChannelType channelType = NetChannelType::SERVER;
|
||||||
|
Version channelVer = {};
|
||||||
UInt_64 id = 0;
|
UInt_64 id = 0;
|
||||||
UInt_64 fragments = 0;
|
UInt_64 fragmentCount = 0;
|
||||||
UInt_64 fragment = 0;
|
UInt_64 fragment = 0;
|
||||||
bool ensure = false;
|
bool ensure = false;
|
||||||
EndDisp disposition = EndDisp::ENDPOINT;
|
|
||||||
Char_8 token[64] = {};
|
Char_8 token[64] = {};
|
||||||
UInt_64 system = 0;
|
UInt_64 systemId = 0;
|
||||||
UInt_64 op = 0;
|
UInt_64 opId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void WriteHeader(const Header &header, Serializer<UInt_64> &data);
|
||||||
|
|
||||||
|
Header ReadHeader(Serializer<UInt_64> &data);
|
||||||
|
|
||||||
struct Packet
|
struct Packet
|
||||||
{
|
{
|
||||||
Header header;
|
Header header;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
Str_8 BaseDNS::Resolve(const AddrType type, const Str_8 &hostname)
|
Str_8 BaseDNS::Resolve(const IP type, const Str_8 &hostname)
|
||||||
{
|
{
|
||||||
EHS_LOG_INT(LogType::ERR, 0, "Unsupported Operating System.");
|
EHS_LOG_INT(LogType::ERR, 0, "Unsupported Operating System.");
|
||||||
return {};
|
return {};
|
||||||
|
@ -4,26 +4,26 @@
|
|||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
BaseTCP::BaseTCP()
|
BaseTCP::BaseTCP()
|
||||||
: addrType(AddrType::IPV6), localPort(0), remotePort(0), connection(false), bound(false), listening(false),
|
: ip(IP::V6), localPort(0), remotePort(0), connection(false), bound(false), listening(false),
|
||||||
connected(false)
|
connected(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseTCP::BaseTCP(const AddrType addrType)
|
BaseTCP::BaseTCP(const IP ip)
|
||||||
: addrType(addrType), localPort(0), remotePort(0), connection(false), bound(false), listening(false),
|
: ip(ip), localPort(0), remotePort(0), connection(false), bound(false), listening(false),
|
||||||
connected(false)
|
connected(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseTCP::BaseTCP(BaseTCP&& tcp) noexcept
|
BaseTCP::BaseTCP(BaseTCP&& tcp) noexcept
|
||||||
: addrType(tcp.addrType), localAddr(std::move(tcp.localAddr)), localPort(tcp.localPort),
|
: ip(tcp.ip), localAddr(std::move(tcp.localAddr)), localPort(tcp.localPort),
|
||||||
remoteHostName(std::move(tcp.remoteHostName)), remoteAddr(std::move(tcp.remoteAddr)), remotePort(tcp.remotePort),
|
remoteHostName(std::move(tcp.remoteHostName)), remoteAddr(std::move(tcp.remoteAddr)), remotePort(tcp.remotePort),
|
||||||
connection(tcp.connection), bound(tcp.bound), listening(tcp.listening), connected(tcp.connected)
|
connection(tcp.connection), bound(tcp.bound), listening(tcp.listening), connected(tcp.connected)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseTCP::BaseTCP(const BaseTCP& tcp)
|
BaseTCP::BaseTCP(const BaseTCP& tcp)
|
||||||
: addrType(tcp.addrType), localPort(0), remotePort(0), connection(false), bound(false), listening(false),
|
: ip(tcp.ip), localPort(0), remotePort(0), connection(false), bound(false), listening(false),
|
||||||
connected(false)
|
connected(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ namespace ehs
|
|||||||
if (this == &tcp)
|
if (this == &tcp)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
addrType = tcp.addrType;
|
ip = tcp.ip;
|
||||||
localAddr = std::move(tcp.localAddr);
|
localAddr = std::move(tcp.localAddr);
|
||||||
localPort = tcp.localPort;
|
localPort = tcp.localPort;
|
||||||
remoteHostName = std::move(tcp.remoteHostName);
|
remoteHostName = std::move(tcp.remoteHostName);
|
||||||
@ -44,7 +44,7 @@ namespace ehs
|
|||||||
listening = tcp.listening;
|
listening = tcp.listening;
|
||||||
connected = tcp.connected;
|
connected = tcp.connected;
|
||||||
|
|
||||||
tcp.addrType = AddrType::IPV6;
|
tcp.ip = IP::V6;
|
||||||
tcp.localPort = 0;
|
tcp.localPort = 0;
|
||||||
tcp.remotePort = 0;
|
tcp.remotePort = 0;
|
||||||
tcp.connection = false;
|
tcp.connection = false;
|
||||||
@ -60,7 +60,7 @@ namespace ehs
|
|||||||
if (this == &tcp)
|
if (this == &tcp)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
addrType = tcp.addrType;
|
ip = tcp.ip;
|
||||||
localAddr = Str_8();
|
localAddr = Str_8();
|
||||||
localPort = 0;
|
localPort = 0;
|
||||||
remoteHostName = Str_8();
|
remoteHostName = Str_8();
|
||||||
@ -188,9 +188,9 @@ namespace ehs
|
|||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddrType BaseTCP::GetAddressType() const
|
IP BaseTCP::GetAddressType() const
|
||||||
{
|
{
|
||||||
return addrType;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
Str_8 BaseTCP::GetLocalAddress() const
|
Str_8 BaseTCP::GetLocalAddress() const
|
||||||
|
@ -3,25 +3,23 @@
|
|||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
BaseUDP::BaseUDP()
|
BaseUDP::BaseUDP()
|
||||||
: type(AddrType::IPV6), port(0), bound(false)
|
: bound(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseUDP::BaseUDP(const AddrType type)
|
BaseUDP::BaseUDP(const IP version)
|
||||||
: type(type), port(0), bound(false)
|
: localEndpoint{version, "", 0}, bound(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseUDP::BaseUDP(BaseUDP&& udp) noexcept
|
BaseUDP::BaseUDP(BaseUDP&& udp) noexcept
|
||||||
: type(udp.type), address(std::move(udp.address)), port(udp.port), bound(true)
|
: localEndpoint((Endpoint &&)udp.localEndpoint), bound(true)
|
||||||
{
|
{
|
||||||
udp.type = AddrType::IPV6;
|
|
||||||
udp.port = 0;
|
|
||||||
udp.bound = false;
|
udp.bound = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseUDP::BaseUDP(const BaseUDP& udp)
|
BaseUDP::BaseUDP(const BaseUDP& udp)
|
||||||
: type(udp.type), address(udp.address), port(udp.port), bound(false)
|
: localEndpoint(udp.localEndpoint), bound(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,13 +28,9 @@ namespace ehs
|
|||||||
if (this == &udp)
|
if (this == &udp)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
type = udp.type;
|
localEndpoint = (Endpoint &&)udp.localEndpoint;
|
||||||
address = std::move(udp.address);
|
|
||||||
port = udp.port;
|
|
||||||
bound = udp.bound;
|
bound = udp.bound;
|
||||||
|
|
||||||
udp.type = AddrType::IPV6;
|
|
||||||
udp.port = 0;
|
|
||||||
udp.bound = false;
|
udp.bound = false;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -47,9 +41,7 @@ namespace ehs
|
|||||||
if (this == &udp)
|
if (this == &udp)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
type = udp.type;
|
localEndpoint = udp.localEndpoint;
|
||||||
address = udp.address;
|
|
||||||
port = udp.port;
|
|
||||||
bound = false;
|
bound = false;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -60,18 +52,8 @@ namespace ehs
|
|||||||
return bound;
|
return bound;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddrType BaseUDP::GetLocalAddressType() const
|
Endpoint BaseUDP::GetLocalEndpoint() const
|
||||||
{
|
{
|
||||||
return type;
|
return localEndpoint;
|
||||||
}
|
|
||||||
|
|
||||||
Str_8 BaseUDP::GetLocalAddress() const
|
|
||||||
{
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt_16 BaseUDP::GetLocalPort() const
|
|
||||||
{
|
|
||||||
return port;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,14 +7,14 @@
|
|||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
Str_8 DNS::Resolve(const AddrType type, const Str_8 &hostname)
|
Str_8 DNS::Resolve(const IP type, const Str_8 &hostname)
|
||||||
{
|
{
|
||||||
addrinfo* result = nullptr;
|
addrinfo* result = nullptr;
|
||||||
addrinfo req = {};
|
addrinfo req = {};
|
||||||
|
|
||||||
if (type == AddrType::IPV6)
|
if (type == IP::V6)
|
||||||
req.ai_family = AF_INET6;
|
req.ai_family = AF_INET6;
|
||||||
else if (type == AddrType::IPV4)
|
else if (type == IP::V4)
|
||||||
req.ai_family = AF_INET;
|
req.ai_family = AF_INET;
|
||||||
|
|
||||||
Int_32 code = getaddrinfo(hostname, nullptr, &req, &result);
|
Int_32 code = getaddrinfo(hostname, nullptr, &req, &result);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
Str_8 DNS::Resolve(const AddrType type, const Str_8 &hostname)
|
Str_8 DNS::Resolve(const IP type, const Str_8 &hostname)
|
||||||
{
|
{
|
||||||
WSADATA data = {};
|
WSADATA data = {};
|
||||||
|
|
||||||
@ -20,9 +20,9 @@ namespace ehs
|
|||||||
addrinfo* result = nullptr;
|
addrinfo* result = nullptr;
|
||||||
addrinfo req = {};
|
addrinfo req = {};
|
||||||
|
|
||||||
if (type == AddrType::IPV6)
|
if (type == IP::V6)
|
||||||
req.ai_family = AF_INET6;
|
req.ai_family = AF_INET6;
|
||||||
else if (type == AddrType::IPV4)
|
else if (type == IP::V4)
|
||||||
req.ai_family = AF_INET;
|
req.ai_family = AF_INET;
|
||||||
|
|
||||||
Int_32 code = getaddrinfo(hostname, nullptr, &req, &result);
|
Int_32 code = getaddrinfo(hostname, nullptr, &req, &result);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -29,7 +29,7 @@ namespace ehs
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL::SSL(const AddrType type)
|
SSL::SSL(const IP type)
|
||||||
: TCP(type), ctx(nullptr), sslHdl(nullptr)
|
: TCP(type), ctx(nullptr), sslHdl(nullptr)
|
||||||
{
|
{
|
||||||
SSL::Initialize();
|
SSL::Initialize();
|
||||||
|
@ -38,7 +38,7 @@ namespace ehc
|
|||||||
}
|
}
|
||||||
|
|
||||||
Socket::Socket()
|
Socket::Socket()
|
||||||
: hdl(EHS_INVALID_SOCKET), type(AddrType::IPV4), port(0), bound(false), appVer(0, 0, 0),
|
: hdl(EHS_INVALID_SOCKET), type(IP::V4), port(0), bound(false), appVer(0, 0, 0),
|
||||||
disposition(Disposition::UNKNOWN), dropPackets(false), hashId(0), buffer(nullptr), bufferSize(0),
|
disposition(Disposition::UNKNOWN), dropPackets(false), hashId(0), buffer(nullptr), bufferSize(0),
|
||||||
maxEndpoints(0), lastTSC(0), delta(0.0f), maxTimeout(5.0f), resendRate(0.5f), connectedCb(nullptr),
|
maxEndpoints(0), lastTSC(0), delta(0.0f), maxTimeout(5.0f), resendRate(0.5f), connectedCb(nullptr),
|
||||||
activeCb(nullptr), disconnectedCb(nullptr)
|
activeCb(nullptr), disconnectedCb(nullptr)
|
||||||
@ -47,7 +47,7 @@ namespace ehc
|
|||||||
}
|
}
|
||||||
|
|
||||||
Socket::Socket(const Version& ver, const Disposition disposition, const Str_8& id, const UInt_64 maxEndpoints)
|
Socket::Socket(const Version& ver, const Disposition disposition, const Str_8& id, const UInt_64 maxEndpoints)
|
||||||
: hdl(EHS_INVALID_SOCKET), type(AddrType::IPV4), port(0), bound(false), appVer(ver), disposition(disposition),
|
: hdl(EHS_INVALID_SOCKET), type(IP::V4), port(0), bound(false), appVer(ver), disposition(disposition),
|
||||||
dropPackets(false), id(id), hashId(id.Hash_32()), buffer(nullptr), bufferSize(0),
|
dropPackets(false), id(id), hashId(id.Hash_32()), buffer(nullptr), bufferSize(0),
|
||||||
maxEndpoints(maxEndpoints), lastTSC(CPU::GetTSC()), delta(0.0f), maxTimeout(5.0f), resendRate(0.5f),
|
maxEndpoints(maxEndpoints), lastTSC(CPU::GetTSC()), delta(0.0f), maxTimeout(5.0f), resendRate(0.5f),
|
||||||
connectedCb(nullptr), activeCb(nullptr), disconnectedCb(nullptr)
|
connectedCb(nullptr), activeCb(nullptr), disconnectedCb(nullptr)
|
||||||
@ -113,9 +113,9 @@ namespace ehc
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (type == AddrType::IPV6)
|
if (type == IP::V6)
|
||||||
hdl = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
hdl = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
else if (type == AddrType::IPV4)
|
else if (type == IP::V4)
|
||||||
hdl = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
hdl = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
@ -140,12 +140,12 @@ namespace ehc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == AddrType::IPV4)
|
if (type == IP::V4)
|
||||||
{
|
{
|
||||||
buffer = new Byte[EHS_IPV4_UDP_PAYLOAD];
|
buffer = new Byte[EHS_IPV4_UDP_PAYLOAD];
|
||||||
bufferSize = EHS_IPV4_UDP_PAYLOAD;
|
bufferSize = EHS_IPV4_UDP_PAYLOAD;
|
||||||
}
|
}
|
||||||
else if (type == AddrType::IPV6)
|
else if (type == IP::V6)
|
||||||
{
|
{
|
||||||
buffer = new Byte[EHS_IPV6_UDP_PAYLOAD];
|
buffer = new Byte[EHS_IPV6_UDP_PAYLOAD];
|
||||||
bufferSize = EHS_IPV6_UDP_PAYLOAD;
|
bufferSize = EHS_IPV6_UDP_PAYLOAD;
|
||||||
@ -204,9 +204,9 @@ namespace ehc
|
|||||||
if (hdl == EHS_INVALID_SOCKET || bound)
|
if (hdl == EHS_INVALID_SOCKET || bound)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (type == AddrType::IPV6)
|
if (type == IP::V6)
|
||||||
Bind_v6(newAddress, newPort);
|
Bind_v6(newAddress, newPort);
|
||||||
else if (type == AddrType::IPV4)
|
else if (type == IP::V4)
|
||||||
Bind_v4(newAddress, newPort);
|
Bind_v4(newAddress, newPort);
|
||||||
|
|
||||||
address = newAddress;
|
address = newAddress;
|
||||||
@ -580,7 +580,7 @@ namespace ehc
|
|||||||
return hdl != EHS_INVALID_SOCKET;
|
return hdl != EHS_INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::SetAddressType(const AddrType newType)
|
void Socket::SetAddressType(const IP newType)
|
||||||
{
|
{
|
||||||
if (hdl != EHS_INVALID_SOCKET)
|
if (hdl != EHS_INVALID_SOCKET)
|
||||||
return;
|
return;
|
||||||
@ -588,7 +588,7 @@ namespace ehc
|
|||||||
type = newType;
|
type = newType;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddrType Socket::GetAddressType() const
|
IP Socket::GetAddressType() const
|
||||||
{
|
{
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@ -1219,14 +1219,14 @@ namespace ehc
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == AddrType::IPV4 && size > EHS_IPV4_UDP_PAYLOAD)
|
if (type == IP::V4 && size > EHS_IPV4_UDP_PAYLOAD)
|
||||||
{
|
{
|
||||||
EHS_LOG_INT(LogType::ERR, 1, "Attempted to receive with a buffer size of, \"" + Str_8::FromNum(size)
|
EHS_LOG_INT(LogType::ERR, 1, "Attempted to receive with a buffer size of, \"" + Str_8::FromNum(size)
|
||||||
+ "\", that exceeds, \"" + Str_8::FromNum(EHS_IPV4_UDP_PAYLOAD) + ".");
|
+ "\", that exceeds, \"" + Str_8::FromNum(EHS_IPV4_UDP_PAYLOAD) + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
sockaddr_in6 remote = {};
|
sockaddr_in6 remote = {};
|
||||||
UInt_32 addrLen = type == AddrType::IPV6 ? sizeof(sockaddr_in6) : sizeof(sockaddr_in);
|
UInt_32 addrLen = type == IP::V6 ? sizeof(sockaddr_in6) : sizeof(sockaddr_in);
|
||||||
SInt_64 received = 0;
|
SInt_64 received = 0;
|
||||||
|
|
||||||
#if defined(EHS_OS_WINDOWS)
|
#if defined(EHS_OS_WINDOWS)
|
||||||
|
@ -30,8 +30,8 @@ namespace ehs
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
TCP::TCP(const AddrType addrType)
|
TCP::TCP(const IP IP)
|
||||||
: BaseTCP(addrType), hdl(EHS_INVALID_SOCKET)
|
: BaseTCP(IP), hdl(EHS_INVALID_SOCKET)
|
||||||
{
|
{
|
||||||
TCP::Initialize();
|
TCP::Initialize();
|
||||||
}
|
}
|
||||||
@ -78,9 +78,9 @@ namespace ehs
|
|||||||
if (IsValid())
|
if (IsValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (addrType == AddrType::IPV6)
|
if (ip == IP::V6)
|
||||||
hdl = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
hdl = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||||
else if (addrType == AddrType::IPV4)
|
else if (ip == IP::V4)
|
||||||
hdl = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
hdl = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
@ -119,9 +119,9 @@ namespace ehs
|
|||||||
if (!IsValid() || bound || connection)
|
if (!IsValid() || bound || connection)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (addrType == AddrType::IPV6)
|
if (ip == IP::V6)
|
||||||
Bind_v6(address, port);
|
Bind_v6(address, port);
|
||||||
else if (addrType == AddrType::IPV4)
|
else if (ip == IP::V4)
|
||||||
Bind_v4(address, port);
|
Bind_v4(address, port);
|
||||||
|
|
||||||
this->localAddr = address;
|
this->localAddr = address;
|
||||||
@ -155,7 +155,7 @@ namespace ehs
|
|||||||
UInt_32 addrLen = sizeof(sockaddr_in6);
|
UInt_32 addrLen = sizeof(sockaddr_in6);
|
||||||
|
|
||||||
TCP* client = new TCP();
|
TCP* client = new TCP();
|
||||||
client->addrType = addrType;
|
client->ip = ip;
|
||||||
client->localAddr = localAddr;
|
client->localAddr = localAddr;
|
||||||
client->localPort = localPort;
|
client->localPort = localPort;
|
||||||
client->connection = true;
|
client->connection = true;
|
||||||
@ -215,18 +215,18 @@ namespace ehs
|
|||||||
remoteHostName = address;
|
remoteHostName = address;
|
||||||
remotePort = port;
|
remotePort = port;
|
||||||
|
|
||||||
if (addrType == AddrType::IPV6)
|
if (ip == IP::V6)
|
||||||
{
|
{
|
||||||
if (IsIPv6Only())
|
if (IsIPv6Only())
|
||||||
remoteAddr = DNS::Resolve(AddrType::IPV6, address);
|
remoteAddr = DNS::Resolve(IP::V6, address);
|
||||||
else
|
else
|
||||||
remoteAddr = DNS::Resolve(address);
|
remoteAddr = DNS::Resolve(address);
|
||||||
|
|
||||||
Connect_v6(remoteAddr, port);
|
Connect_v6(remoteAddr, port);
|
||||||
}
|
}
|
||||||
else if (addrType == AddrType::IPV4)
|
else if (ip == IP::V4)
|
||||||
{
|
{
|
||||||
remoteAddr = DNS::Resolve(AddrType::IPV4, address);
|
remoteAddr = DNS::Resolve(IP::V4, address);
|
||||||
|
|
||||||
Connect_v4(remoteAddr, port);
|
Connect_v4(remoteAddr, port);
|
||||||
}
|
}
|
||||||
@ -338,7 +338,7 @@ namespace ehs
|
|||||||
|
|
||||||
void TCP::SetIPv6Only(const bool value)
|
void TCP::SetIPv6Only(const bool value)
|
||||||
{
|
{
|
||||||
if (addrType != AddrType::IPV6)
|
if (ip != IP::V6)
|
||||||
{
|
{
|
||||||
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
|
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
|
||||||
return;
|
return;
|
||||||
@ -362,7 +362,7 @@ namespace ehs
|
|||||||
|
|
||||||
bool TCP::IsIPv6Only() const
|
bool TCP::IsIPv6Only() const
|
||||||
{
|
{
|
||||||
if (addrType != AddrType::IPV6)
|
if (ip != IP::V6)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
|
@ -33,8 +33,8 @@ namespace ehs
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
TCP::TCP(const AddrType addrType)
|
TCP::TCP(const IP IP)
|
||||||
: BaseTCP(addrType), hdl(EHS_INVALID_SOCKET)
|
: BaseTCP(IP), hdl(EHS_INVALID_SOCKET)
|
||||||
{
|
{
|
||||||
TCP::Initialize();
|
TCP::Initialize();
|
||||||
}
|
}
|
||||||
@ -90,9 +90,9 @@ namespace ehs
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addrType == AddrType::IPV6)
|
if (ip == IP::V6)
|
||||||
hdl = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
hdl = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||||
else if (addrType == AddrType::IPV4)
|
else if (ip == IP::V4)
|
||||||
hdl = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
hdl = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
@ -142,9 +142,9 @@ namespace ehs
|
|||||||
if (!IsValid() || bound || connection)
|
if (!IsValid() || bound || connection)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (addrType == AddrType::IPV6)
|
if (ip == IP::V6)
|
||||||
Bind_v6(address, port);
|
Bind_v6(address, port);
|
||||||
else if (addrType == AddrType::IPV4)
|
else if (ip == IP::V4)
|
||||||
Bind_v4(address, port);
|
Bind_v4(address, port);
|
||||||
|
|
||||||
this->localAddr = address;
|
this->localAddr = address;
|
||||||
@ -178,7 +178,7 @@ namespace ehs
|
|||||||
UInt_32 addrLen = sizeof(sockaddr_in6);
|
UInt_32 addrLen = sizeof(sockaddr_in6);
|
||||||
|
|
||||||
TCP* client = new TCP();
|
TCP* client = new TCP();
|
||||||
client->addrType = addrType;
|
client->ip = ip;
|
||||||
client->localAddr = localAddr;
|
client->localAddr = localAddr;
|
||||||
client->localPort = localPort;
|
client->localPort = localPort;
|
||||||
client->connection = true;
|
client->connection = true;
|
||||||
@ -244,18 +244,18 @@ namespace ehs
|
|||||||
remoteHostName = address;
|
remoteHostName = address;
|
||||||
remotePort = port;
|
remotePort = port;
|
||||||
|
|
||||||
if (addrType == AddrType::IPV6)
|
if (ip == IP::V6)
|
||||||
{
|
{
|
||||||
if (IsIPv6Only())
|
if (IsIPv6Only())
|
||||||
remoteAddr = DNS::Resolve(AddrType::IPV6, address);
|
remoteAddr = DNS::Resolve(IP::V6, address);
|
||||||
else
|
else
|
||||||
remoteAddr = DNS::Resolve(address);
|
remoteAddr = DNS::Resolve(address);
|
||||||
|
|
||||||
Connect_v6(remoteAddr, port);
|
Connect_v6(remoteAddr, port);
|
||||||
}
|
}
|
||||||
else if (addrType == AddrType::IPV4)
|
else if (ip == IP::V4)
|
||||||
{
|
{
|
||||||
remoteAddr = DNS::Resolve(AddrType::IPV4, address);
|
remoteAddr = DNS::Resolve(IP::V4, address);
|
||||||
|
|
||||||
Connect_v4(remoteAddr, port);
|
Connect_v4(remoteAddr, port);
|
||||||
}
|
}
|
||||||
@ -359,7 +359,7 @@ namespace ehs
|
|||||||
|
|
||||||
void TCP::SetIPv6Only(const bool value)
|
void TCP::SetIPv6Only(const bool value)
|
||||||
{
|
{
|
||||||
if (addrType != AddrType::IPV6)
|
if (ip != IP::V6)
|
||||||
{
|
{
|
||||||
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
|
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
|
||||||
return;
|
return;
|
||||||
@ -383,7 +383,7 @@ namespace ehs
|
|||||||
|
|
||||||
bool TCP::IsIPv6Only() const
|
bool TCP::IsIPv6Only() const
|
||||||
{
|
{
|
||||||
if (addrType != AddrType::IPV6)
|
if (ip != IP::V6)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
|
@ -25,12 +25,12 @@ namespace ehs
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
UDP::UDP(const AddrType addrType)
|
UDP::UDP(const IP version)
|
||||||
: BaseUDP(addrType), hdl(EHS_INVALID_SOCKET)
|
: BaseUDP(version), hdl(EHS_INVALID_SOCKET)
|
||||||
{
|
{
|
||||||
if (addrType == AddrType::IPV6)
|
if (version == IP::V6)
|
||||||
hdl = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
hdl = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
else if (addrType == AddrType::IPV4)
|
else if (version == IP::V4)
|
||||||
hdl = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
hdl = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
@ -96,33 +96,32 @@ namespace ehs
|
|||||||
bound = false;
|
bound = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDP::Bind(const AddrType type, const Str_8& address, const UInt_16 port)
|
void UDP::Bind(const Endpoint &endpoint)
|
||||||
{
|
{
|
||||||
if (!IsValid() || bound)
|
if (!IsValid() || bound)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (type == AddrType::IPV6)
|
if (endpoint.version == IP::V6)
|
||||||
Bind_v6(address, port);
|
Bind_v6(endpoint.address, endpoint.port);
|
||||||
else if (type == AddrType::IPV4)
|
else if (endpoint.version == IP::V4)
|
||||||
Bind_v4(address, port);
|
Bind_v4(endpoint.address, endpoint.port);
|
||||||
|
|
||||||
this->address = address;
|
localEndpoint = endpoint;
|
||||||
this->port = port;
|
|
||||||
|
|
||||||
bound = true;
|
bound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt_64 UDP::Send(const AddrType type, const Str_8& address, const UInt_16 port, const Byte *const data, const UInt_64 size)
|
UInt_64 UDP::Send(const Endpoint &endpoint, const Byte *const data, const UInt_64 size)
|
||||||
{
|
{
|
||||||
if (type == AddrType::IPV6)
|
if (endpoint.version == IP::V6)
|
||||||
return Send_v6(address, port, data, size);
|
return Send_v6(endpoint.address, endpoint.port, data, size);
|
||||||
else if (type == AddrType::IPV4)
|
else if (endpoint.version == IP::V4)
|
||||||
return Send_v4(address, port, data, size);
|
return Send_v4(endpoint.address, endpoint.port, data, size);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt_64 UDP::Receive(AddrType* const type, Str_8* const address, UInt_16* const port, Byte* const data, const UInt_64 size)
|
UInt_64 UDP::Receive(Endpoint *endpoint, Byte* const data, const UInt_64 size)
|
||||||
{
|
{
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
{
|
{
|
||||||
@ -161,9 +160,7 @@ namespace ehs
|
|||||||
return received;
|
return received;
|
||||||
}
|
}
|
||||||
|
|
||||||
*type = AddrType::IPV6;
|
*endpoint = {IP::V6, tmpAddr, remote.sin6_port};
|
||||||
*address = tmpAddr;
|
|
||||||
*port = ntohs(remote.sin6_port);
|
|
||||||
}
|
}
|
||||||
else if (addrLen == sizeof(sockaddr_in))
|
else if (addrLen == sizeof(sockaddr_in))
|
||||||
{
|
{
|
||||||
@ -178,9 +175,7 @@ namespace ehs
|
|||||||
return received;
|
return received;
|
||||||
}
|
}
|
||||||
|
|
||||||
*type = AddrType::IPV4;
|
*endpoint = {IP::V4, tmpAddr, ntohs(((sockaddr_in*)&remote)->sin_port)};
|
||||||
*address = tmpAddr;
|
|
||||||
*port = ntohs(((sockaddr_in*)&remote)->sin_port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return received;
|
return received;
|
||||||
@ -205,7 +200,7 @@ namespace ehs
|
|||||||
|
|
||||||
void UDP::SetIPv6Only(const bool value)
|
void UDP::SetIPv6Only(const bool value)
|
||||||
{
|
{
|
||||||
if (type != AddrType::IPV6)
|
if (localEndpoint.version != IP::V6)
|
||||||
{
|
{
|
||||||
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
|
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
|
||||||
return;
|
return;
|
||||||
@ -229,7 +224,7 @@ namespace ehs
|
|||||||
|
|
||||||
bool UDP::IsIPv6Only() const
|
bool UDP::IsIPv6Only() const
|
||||||
{
|
{
|
||||||
if (type != AddrType::IPV6)
|
if (localEndpoint.version != IP::V6)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
|
@ -24,8 +24,8 @@ namespace ehs
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
UDP::UDP(const AddrType addrType)
|
UDP::UDP(const IP IP)
|
||||||
: BaseUDP(addrType), hdl(EHS_INVALID_SOCKET)
|
: BaseUDP(IP), hdl(EHS_INVALID_SOCKET)
|
||||||
{
|
{
|
||||||
WSADATA data = {};
|
WSADATA data = {};
|
||||||
|
|
||||||
@ -36,9 +36,9 @@ namespace ehs
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addrType == AddrType::IPV6)
|
if (IP == IP::V6)
|
||||||
hdl = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
hdl = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
else if (addrType == AddrType::IPV4)
|
else if (IP == IP::V4)
|
||||||
hdl = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
hdl = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
@ -110,33 +110,32 @@ namespace ehs
|
|||||||
bound = false;
|
bound = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDP::Bind(const AddrType type, const Str_8& address, const UInt_16 port)
|
void UDP::Bind(const Endpoint &endpoint)
|
||||||
{
|
{
|
||||||
if (!IsValid() || bound)
|
if (!IsValid() || bound)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (type == AddrType::IPV6)
|
if (endpoint.version == IP::V6)
|
||||||
Bind_v6(address, port);
|
Bind_v6(endpoint.address, endpoint.port);
|
||||||
else if (type == AddrType::IPV4)
|
else if (endpoint.version == IP::V4)
|
||||||
Bind_v4(address, port);
|
Bind_v4(endpoint.address, endpoint.port);
|
||||||
|
|
||||||
this->address = address;
|
localEndpoint = endpoint;
|
||||||
this->port = port;
|
|
||||||
|
|
||||||
bound = true;
|
bound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt_64 UDP::Send(const AddrType type, const Str_8& address, const UInt_16 port, const Byte *const data, const UInt_64 size)
|
UInt_64 UDP::Send(const Endpoint &endpoint, const Byte *const data, const UInt_64 size)
|
||||||
{
|
{
|
||||||
if (type == AddrType::IPV6)
|
if (endpoint.version == IP::V6)
|
||||||
return Send_v6(address, port, data, size);
|
return Send_v6(endpoint.address, endpoint.port, data, size);
|
||||||
else if (type == AddrType::IPV4)
|
else if (endpoint.version == IP::V4)
|
||||||
return Send_v4(address, port, data, size);
|
return Send_v4(endpoint.address, endpoint.port, data, size);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt_64 UDP::Receive(AddrType* type, Str_8* const address, UInt_16* const port, Byte* const data, const UInt_64 size)
|
UInt_64 UDP::Receive(Endpoint *endpoint, Byte* const data, const UInt_64 size)
|
||||||
{
|
{
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
{
|
{
|
||||||
@ -174,9 +173,11 @@ namespace ehs
|
|||||||
return received;
|
return received;
|
||||||
}
|
}
|
||||||
|
|
||||||
*type = AddrType::IPV6;
|
*endpoint = {
|
||||||
*address = tmpAddr;
|
IP::V6,
|
||||||
*port = ntohs(remote.sin6_port);
|
tmpAddr,
|
||||||
|
ntohs(remote.sin6_port)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
else if (addrLen == sizeof(sockaddr_in))
|
else if (addrLen == sizeof(sockaddr_in))
|
||||||
{
|
{
|
||||||
@ -191,9 +192,11 @@ namespace ehs
|
|||||||
return received;
|
return received;
|
||||||
}
|
}
|
||||||
|
|
||||||
*type = AddrType::IPV4;
|
*endpoint = {
|
||||||
*address = tmpAddr;
|
IP::V4,
|
||||||
*port = ntohs(((sockaddr_in*)&remote)->sin_port);
|
tmpAddr,
|
||||||
|
ntohs(((sockaddr_in*)&remote)->sin_port)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return received;
|
return received;
|
||||||
@ -225,7 +228,7 @@ namespace ehs
|
|||||||
|
|
||||||
void UDP::SetIPv6Only(const bool value)
|
void UDP::SetIPv6Only(const bool value)
|
||||||
{
|
{
|
||||||
if (type != AddrType::IPV6)
|
if (localEndpoint.version != IP::V6)
|
||||||
{
|
{
|
||||||
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
|
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
|
||||||
return;
|
return;
|
||||||
@ -249,7 +252,7 @@ namespace ehs
|
|||||||
|
|
||||||
bool UDP::IsIPv6Only() const
|
bool UDP::IsIPv6Only() const
|
||||||
{
|
{
|
||||||
if (type != AddrType::IPV6)
|
if (localEndpoint.version != IP::V6)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
@ -362,7 +365,7 @@ namespace ehs
|
|||||||
Int_32 code = inet_pton(AF_INET6, addr, &result.sin6_addr);
|
Int_32 code = inet_pton(AF_INET6, addr, &result.sin6_addr);
|
||||||
if (!code)
|
if (!code)
|
||||||
{
|
{
|
||||||
EHS_LOG_INT(LogType::ERR, 1, "The given address, \"" + address + "\" is not valid.");
|
EHS_LOG_INT(LogType::ERR, 1, "The given address, \"" + addr + "\" is not valid.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (code == -1)
|
else if (code == -1)
|
||||||
@ -403,7 +406,7 @@ namespace ehs
|
|||||||
int code = inet_pton(AF_INET, addr, &result.sin_addr);
|
int code = inet_pton(AF_INET, addr, &result.sin_addr);
|
||||||
if (!code)
|
if (!code)
|
||||||
{
|
{
|
||||||
EHS_LOG_INT(LogType::ERR, 1, "The given address, \"" + address + "\" is not valid.");
|
EHS_LOG_INT(LogType::ERR, 1, "The given address, \"" + addr + "\" is not valid.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (code == -1)
|
else if (code == -1)
|
||||||
|
193
src/io/socket/ehc/NetChannel.cpp
Normal file
193
src/io/socket/ehc/NetChannel.cpp
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
#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");
|
||||||
|
const UInt_64 NetChannel::connectOp = Str_8::Hash_64("Connect");
|
||||||
|
const UInt_64 NetChannel::connectedOp = Str_8::Hash_64("Connected");
|
||||||
|
const UInt_64 NetChannel::rejectedOp = Str_8::Hash_64("Rejected");
|
||||||
|
const UInt_64 NetChannel::disconnectOp = Str_8::Hash_64("Disconnect");
|
||||||
|
const UInt_64 NetChannel::disconnectedOp = Str_8::Hash_64("Disconnected");
|
||||||
|
const UInt_64 NetChannel::statusUpdateOp = Str_8::Hash_64("StatusUpdate");
|
||||||
|
const UInt_64 NetChannel::pingOp = Str_8::Hash_64("Ping");
|
||||||
|
const UInt_64 NetChannel::pongOp = Str_8::Hash_64("Pong");
|
||||||
|
const UInt_64 NetChannel::latencyOp = Str_8::Hash_64("Latency");
|
||||||
|
const UInt_64 NetChannel::receivedOp = Str_8::Hash_64("Received");
|
||||||
|
|
||||||
|
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->GetId() == internalSys)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (HasSystem(sys->GetId()))
|
||||||
|
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 sysId) const
|
||||||
|
{
|
||||||
|
for (UInt_64 i = 0; i < systems.Size(); ++i)
|
||||||
|
if (systems[i]->GetId() == sysId)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NetChannel::HasSystem(const Str_8& sysName) const
|
||||||
|
{
|
||||||
|
return HasSystem(sysName.Hash_64());
|
||||||
|
}
|
||||||
|
|
||||||
|
NetSys* NetChannel::GetSystem(const UInt_64 sysId) const
|
||||||
|
{
|
||||||
|
for (UInt_64 i = 0; i < systems.Size(); ++i)
|
||||||
|
if (systems[i]->GetId() == sysId)
|
||||||
|
return systems[i];
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
NetSys* NetChannel::GetSystem(const Str_8& sysName) const
|
||||||
|
{
|
||||||
|
return GetSystem(sysName.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
|
namespace ehs
|
||||||
{
|
{
|
||||||
NetEnc::NetEnc()
|
NetEnc::NetEnc()
|
||||||
: owner(nullptr), hashId(0)
|
: id(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NetEnc::NetEnc(Str_8 id)
|
NetEnc::NetEnc(Str_8 name, const Version &version)
|
||||||
: owner(nullptr), hashId(id.Hash_64()), id((Str_8 &&)id)
|
: id(name.Hash_64()), name((Str_8 &&)name), version(version)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NetEnc::NetEnc(NetEnc&& enc) noexcept
|
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.id = 0;
|
||||||
enc.hashId = 0;
|
enc.version = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
NetEnc::NetEnc(const NetEnc& enc)
|
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)
|
if (this == &enc)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
owner = enc.owner;
|
id = enc.id;
|
||||||
hashId = enc.hashId;
|
name = (Str_8 &&)enc.name;
|
||||||
id = (Str_8 &&)enc.id;
|
version = enc.version;
|
||||||
|
|
||||||
enc.owner = nullptr;
|
enc.id = 0;
|
||||||
enc.hashId = 0;
|
enc.version = {};
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -44,28 +44,28 @@ namespace ehs
|
|||||||
if (this == &enc)
|
if (this == &enc)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
owner = nullptr;
|
|
||||||
hashId = enc.hashId;
|
|
||||||
id = enc.id;
|
id = enc.id;
|
||||||
|
name = enc.name;
|
||||||
|
version = enc.version;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
EHC* NetEnc::GetOwner() const
|
UInt_64 NetEnc::GetId() const
|
||||||
{
|
|
||||||
return owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt_64 NetEnc::GetHashId() const
|
|
||||||
{
|
|
||||||
return hashId;
|
|
||||||
}
|
|
||||||
|
|
||||||
Str_8 NetEnc::GetId() const
|
|
||||||
{
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Str_8 NetEnc::GetName() const
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
Version NetEnc::GetVersion() const
|
||||||
|
{
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
void NetEnc::Encrypt(Byte *data, UInt_64 size) const
|
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/NetEnd.h"
|
||||||
#include "ehs/io/socket/EHC.h"
|
#include "ehs/io/socket/EHC.h"
|
||||||
#include "ehs/io/socket/ehc/NetEnc.h"
|
#include "ehs/io/socket/ehc/NetEnc.h"
|
||||||
|
#include "ehs/io/socket/ehc/NetServerCh.h"
|
||||||
#include "ehs/system/CPU.h"
|
#include "ehs/system/CPU.h"
|
||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
NetEnd::NetEnd()
|
NetEnd::NetEnd()
|
||||||
: owner(nullptr), disposition(EndDisp::ENDPOINT), hashName(0), status(Status::PENDING),
|
: owner(nullptr), id(0), status(NetStatus::PENDING), token{}, nextSendId(0), nextRecvId(0),
|
||||||
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),
|
||||||
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),
|
|
||||||
latency(0.0f), queueSlot(0)
|
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
|
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),
|
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),
|
deltaDuration(end.deltaDuration), deltaRate(end.deltaRate), timeout(end.timeout), lastPing(end.lastPing),
|
||||||
oldLatency(end.oldLatency), latency(end.latency), queueSlot(end.queueSlot)
|
oldLatency(end.oldLatency), latency(end.latency), queueSlot(end.queueSlot)
|
||||||
{
|
{
|
||||||
end.owner = nullptr;
|
end.owner = nullptr;
|
||||||
end.disposition = EndDisp::ENDPOINT;
|
end.id = 0;
|
||||||
end.hashName = 0;
|
end.status = NetStatus::PENDING;
|
||||||
end.status = Status::PENDING;
|
|
||||||
end.arch = Architecture::UNKNOWN;
|
|
||||||
Util::Copy(token, end.token, 64);
|
Util::Copy(token, end.token, 64);
|
||||||
Util::Zero(end.token, 64);
|
Util::Zero(end.token, 64);
|
||||||
end.nextSendId = 0;
|
end.nextSendId = 0;
|
||||||
end.nextRecvId = 0;
|
end.nextRecvId = 0;
|
||||||
end.type = AddrType::IPV6;
|
|
||||||
end.port = 0;
|
|
||||||
end.deltaDuration = 0.0f;
|
end.deltaDuration = 0.0f;
|
||||||
end.deltaRate = 1.0f / 60.0f;
|
end.deltaRate = 1.0f / 60.0f;
|
||||||
end.timeout = 0.0f;
|
end.timeout = 0.0f;
|
||||||
@ -58,9 +51,9 @@ namespace ehs
|
|||||||
}
|
}
|
||||||
|
|
||||||
NetEnd::NetEnd(const NetEnd& end)
|
NetEnd::NetEnd(const NetEnd& end)
|
||||||
: owner(nullptr), disposition(EndDisp::ENDPOINT), hashName(end.hashName), name(end.name), status(Status::PENDING), arch(Architecture::UNKNOWN),
|
: owner(nullptr), id(end.id), name(end.name), status(NetStatus::PENDING), token{}, nextSendId(0),
|
||||||
token{}, nextSendId(0), nextRecvId(0), type(end.type), port(0), deltaDuration(0.0f), deltaRate(1.0f / 60.0f),
|
nextRecvId(0), deltaDuration(0.0f), deltaRate(1.0f / 60.0f), timeout(0.0f), lastPing(0.0f), oldLatency(0.0f),
|
||||||
timeout(0.0f), lastPing(0.0f), oldLatency(0.0f), latency(0.0f), queueSlot(0)
|
latency(0.0f), queueSlot(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,19 +63,15 @@ namespace ehs
|
|||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
owner = end.owner;
|
owner = end.owner;
|
||||||
disposition = end.disposition;
|
id = end.id;
|
||||||
hashName = end.hashName;
|
|
||||||
name = (Str_8&&)end.name;
|
name = (Str_8&&)end.name;
|
||||||
status = end.status;
|
status = end.status;
|
||||||
arch = end.arch;
|
|
||||||
Util::Copy(token, end.token, 64);
|
Util::Copy(token, end.token, 64);
|
||||||
nextSendId = end.nextSendId;
|
nextSendId = end.nextSendId;
|
||||||
sent = (Vector<Insurance>&&)end.sent;
|
sent = (Vector<Insurance>&&)end.sent;
|
||||||
nextRecvId = end.nextRecvId;
|
nextRecvId = end.nextRecvId;
|
||||||
received = (Vector<NetFrags>&&)end.received;
|
received = (Vector<NetFrag>&&)end.received;
|
||||||
type = end.type;
|
endpoint = (Endpoint &&)end.endpoint;
|
||||||
address = (Str_8&&)end.address;
|
|
||||||
port = end.port;
|
|
||||||
deltaDuration = end.deltaDuration;
|
deltaDuration = end.deltaDuration;
|
||||||
deltaRate = end.deltaRate;
|
deltaRate = end.deltaRate;
|
||||||
timeout = end.timeout;
|
timeout = end.timeout;
|
||||||
@ -92,15 +81,11 @@ namespace ehs
|
|||||||
queueSlot = end.queueSlot;
|
queueSlot = end.queueSlot;
|
||||||
|
|
||||||
end.owner = nullptr;
|
end.owner = nullptr;
|
||||||
end.disposition = EndDisp::ENDPOINT;
|
end.id = 0;
|
||||||
end.hashName = 0;
|
end.status = NetStatus::PENDING;
|
||||||
end.status = Status::PENDING;
|
|
||||||
end.arch = Architecture::UNKNOWN;
|
|
||||||
Util::Zero(end.token, 64);
|
Util::Zero(end.token, 64);
|
||||||
end.nextSendId = 0;
|
end.nextSendId = 0;
|
||||||
end.nextRecvId = 0;
|
end.nextRecvId = 0;
|
||||||
end.type = AddrType::IPV6;
|
|
||||||
end.port = 0;
|
|
||||||
end.deltaDuration = 0.0f;
|
end.deltaDuration = 0.0f;
|
||||||
end.deltaRate = 1.0f / 60.0f;
|
end.deltaRate = 1.0f / 60.0f;
|
||||||
end.timeout = 0.0f;
|
end.timeout = 0.0f;
|
||||||
@ -118,19 +103,15 @@ namespace ehs
|
|||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
owner = nullptr;
|
owner = nullptr;
|
||||||
disposition = EndDisp::ENDPOINT;
|
id = end.id;
|
||||||
hashName = end.hashName;
|
|
||||||
name = end.name;
|
name = end.name;
|
||||||
status = Status::PENDING;
|
status = NetStatus::PENDING;
|
||||||
arch = Architecture::UNKNOWN;
|
|
||||||
Util::Zero(token, 64);
|
Util::Zero(token, 64);
|
||||||
nextSendId = 0;
|
nextSendId = 0;
|
||||||
sent = {};
|
sent = {};
|
||||||
nextRecvId = 0;
|
nextRecvId = 0;
|
||||||
received = {};
|
received = {};
|
||||||
type = AddrType::IPV6;
|
endpoint = {};
|
||||||
address = {};
|
|
||||||
port = 0;
|
|
||||||
deltaDuration = 0.0f;
|
deltaDuration = 0.0f;
|
||||||
deltaRate = 1.0f / 60.0f;
|
deltaRate = 1.0f / 60.0f;
|
||||||
timeout = 0.0f;
|
timeout = 0.0f;
|
||||||
@ -142,14 +123,9 @@ namespace ehs
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
EndDisp NetEnd::GetDisposition() const
|
UInt_64 NetEnd::GetId() const
|
||||||
{
|
{
|
||||||
return disposition;
|
return id;
|
||||||
}
|
|
||||||
|
|
||||||
UInt_64 NetEnd::GetHashName() const
|
|
||||||
{
|
|
||||||
return hashName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Str_8 NetEnd::GetName() const
|
Str_8 NetEnd::GetName() const
|
||||||
@ -157,44 +133,54 @@ namespace ehs
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status NetEnd::GetStatus() const
|
NetStatus NetEnd::GetStatus() const
|
||||||
{
|
{
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
Architecture NetEnd::GetArchitecture() const
|
|
||||||
{
|
|
||||||
return arch;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt_64 NetEnd::GetNextSendId() const
|
UInt_64 NetEnd::GetNextSendId() const
|
||||||
{
|
{
|
||||||
return nextSendId;
|
return nextSendId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetEnd::Send(const bool deltaLocked, const UInt_64 encHashId, const bool ensure, const UInt_64 sys,
|
void NetEnd::Send(const bool deltaLocked, const UInt_64 encId, const bool ensure, const UInt_64 sysId,
|
||||||
const UInt_64 op, const Serializer<UInt_64> &payload)
|
const UInt_64 opId, const Serializer<UInt_64> &payload)
|
||||||
{
|
{
|
||||||
if (deltaLocked && deltaDuration < deltaRate)
|
if (!owner || !owner->GetOwner() || (deltaLocked && deltaDuration < deltaRate))
|
||||||
return;
|
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 = {
|
Header header = {
|
||||||
encHashId,
|
EHC::GetVersion(),
|
||||||
nextSendId++,
|
encId,
|
||||||
1,
|
enc->GetVersion(),
|
||||||
0,
|
GetId(),
|
||||||
ensure,
|
NetChannelType::SERVER,
|
||||||
owner->GetDisposition(),
|
GetVersion(),
|
||||||
"",
|
nextSendId++,
|
||||||
sys,
|
1,
|
||||||
op
|
0,
|
||||||
|
ensure,
|
||||||
|
"",
|
||||||
|
sysId,
|
||||||
|
opId
|
||||||
};
|
};
|
||||||
|
|
||||||
Util::Copy(header.token, token, 64);
|
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)
|
for (UInt_64 i = 0; i < frags.Size(); ++i)
|
||||||
{
|
{
|
||||||
Header newHeader = frags.GetHeader();
|
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,
|
void NetEnd::Send(const bool deltaLocked, const Str_8 &encName, const bool ensure, const Str_8& sysName,
|
||||||
const Str_8& op, const Serializer<>& payload)
|
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
|
UInt_64 NetEnd::GetNextRecvId() const
|
||||||
@ -220,14 +206,9 @@ namespace ehs
|
|||||||
return nextRecvId;
|
return nextRecvId;
|
||||||
}
|
}
|
||||||
|
|
||||||
Str_8 NetEnd::GetAddress() const
|
Endpoint NetEnd::GetEndpoint() const
|
||||||
{
|
{
|
||||||
return address;
|
return endpoint;
|
||||||
}
|
|
||||||
|
|
||||||
UInt_16 NetEnd::GetPort() const
|
|
||||||
{
|
|
||||||
return port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float NetEnd::GetDeltaRate() const
|
float NetEnd::GetDeltaRate() const
|
||||||
@ -273,17 +254,21 @@ namespace ehs
|
|||||||
sent[i].lastResend += delta;
|
sent[i].lastResend += delta;
|
||||||
if (sent[i].lastResend >= owner->GetResendRate())
|
if (sent[i].lastResend >= owner->GetResendRate())
|
||||||
{
|
{
|
||||||
|
EHC *ehc = owner->GetOwner();
|
||||||
|
|
||||||
Serializer result(Endianness::LE);
|
Serializer result(Endianness::LE);
|
||||||
result.Write(sent[i].header);
|
result.Write(sent[i].header);
|
||||||
result.WriteSer(sent[i].payload);
|
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)
|
if (!enc)
|
||||||
{
|
{
|
||||||
EHS_LOG_INT(LogType::WARN, 0, "The network encryption with the hash id " +
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
@ -291,24 +276,21 @@ namespace ehs
|
|||||||
enc->Encrypt(&result[sizeof(bool)], result.Size() - sizeof(bool));
|
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());
|
sent[i].lastResend = Math::Mod(sent[i].lastResend, owner->GetResendRate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (owner->GetDisposition() == EndDisp::SERVICE)
|
lastPing += delta;
|
||||||
{
|
if (lastPing >= 1.0f)
|
||||||
lastPing += delta;
|
Ping(delta);
|
||||||
if (lastPing >= 1.0f)
|
|
||||||
Ping(delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
EHS_LOG_SUCCESS();
|
EHS_LOG_SUCCESS();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetEnd::SetStatus(const Status newStatus)
|
void NetEnd::SetStatus(const NetStatus newStatus)
|
||||||
{
|
{
|
||||||
status = newStatus;
|
status = newStatus;
|
||||||
}
|
}
|
||||||
@ -329,7 +311,7 @@ namespace ehs
|
|||||||
|
|
||||||
void NetEnd::AddReceived(const Header& header, const Serializer<>& payload)
|
void NetEnd::AddReceived(const Header& header, const Serializer<>& payload)
|
||||||
{
|
{
|
||||||
NetFrags* frags = nullptr;
|
NetFrag* frags = nullptr;
|
||||||
|
|
||||||
for (UInt_64 i = 0; i < received.Size(); ++i)
|
for (UInt_64 i = 0; i < received.Size(); ++i)
|
||||||
{
|
{
|
||||||
@ -354,7 +336,7 @@ namespace ehs
|
|||||||
timeout = 0.0f;
|
timeout = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<NetFrags>* NetEnd::GetReceived()
|
Vector<NetFrag>* NetEnd::GetReceived()
|
||||||
{
|
{
|
||||||
return &received;
|
return &received;
|
||||||
}
|
}
|
||||||
@ -374,16 +356,6 @@ namespace ehs
|
|||||||
latency = 0.0f;
|
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()
|
void NetEnd::SendLatency()
|
||||||
{
|
{
|
||||||
oldLatency = latency * 1000;
|
oldLatency = latency * 1000;
|
||||||
@ -407,17 +379,19 @@ namespace ehs
|
|||||||
queueSlot = slot;
|
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;
|
UInt_64 frags = data.Size() / EHC_IPV6_PAYLOAD;
|
||||||
if (data.Size() % EHC_IPV6_PAYLOAD)
|
if (data.Size() % EHC_IPV6_PAYLOAD)
|
||||||
++frags;
|
++frags;
|
||||||
|
|
||||||
result = NetFrags(header, frags);
|
result = NetFrag(header, frags);
|
||||||
|
|
||||||
UInt_64 size = EHC_IPV6_PAYLOAD;
|
UInt_64 size = EHC_IPV6_PAYLOAD;
|
||||||
|
|
||||||
@ -430,13 +404,13 @@ namespace ehs
|
|||||||
result[i] = {data.GetEndianness(), &data[i * EHC_IPV6_PAYLOAD], size};
|
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;
|
UInt_64 frags = data.Size() / EHC_IPV4_PAYLOAD;
|
||||||
if (data.Size() % EHC_IPV4_PAYLOAD)
|
if (data.Size() % EHC_IPV4_PAYLOAD)
|
||||||
++frags;
|
++frags;
|
||||||
|
|
||||||
result = NetFrags(header, frags);
|
result = NetFrag(header, frags);
|
||||||
|
|
||||||
UInt_64 size = EHC_IPV4_PAYLOAD;
|
UInt_64 size = EHC_IPV4_PAYLOAD;
|
||||||
|
|
||||||
@ -455,17 +429,19 @@ namespace ehs
|
|||||||
|
|
||||||
void NetEnd::Send(const Header& header, const Serializer<UInt_64>& payload)
|
void NetEnd::Send(const Header& header, const Serializer<UInt_64>& payload)
|
||||||
{
|
{
|
||||||
|
EHC *ehc = owner->GetOwner();
|
||||||
|
|
||||||
Serializer result(Endianness::LE);
|
Serializer result(Endianness::LE);
|
||||||
result.Write(header);
|
result.Write(header);
|
||||||
result.WriteSer(payload);
|
result.WriteSer(payload);
|
||||||
|
|
||||||
if (header.encHashId)
|
if (header.encId)
|
||||||
{
|
{
|
||||||
NetEnc *enc = owner->GetEncryption(header.encHashId);
|
NetEnc *enc = ehc->GetEncryption(header.encId);
|
||||||
if (!enc)
|
if (!enc)
|
||||||
{
|
{
|
||||||
EHS_LOG_INT(LogType::WARN, 0, "The network encryption with the hash id " +
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@ -476,7 +452,7 @@ namespace ehs
|
|||||||
if (header.ensure)
|
if (header.ensure)
|
||||||
sent.Push({header, payload});
|
sent.Push({header, payload});
|
||||||
|
|
||||||
owner->udp.Send(type, address, port, result, result.Size());
|
ehc->udp.Send(endpoint, result, result.Size());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetEnd::SortingNeeded() const
|
bool NetEnd::SortingNeeded() const
|
||||||
@ -499,7 +475,7 @@ namespace ehs
|
|||||||
if (!SortingNeeded())
|
if (!SortingNeeded())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Vector<NetFrags> sorted(0, received.Stride());
|
Vector<NetFrag> sorted(0, received.Stride());
|
||||||
|
|
||||||
for (UInt_64 a = 0; a < received.Size(); ++a)
|
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
|
namespace ehs
|
||||||
{
|
{
|
||||||
NetFrags::~NetFrags()
|
NetFrag::~NetFrag()
|
||||||
{
|
{
|
||||||
delete[] data;
|
delete[] data;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetFrags::NetFrags()
|
NetFrag::NetFrag()
|
||||||
: data(nullptr), size(0)
|
: data(nullptr), size(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NetFrags::NetFrags(const Header &header, const Serializer<UInt_64> &payload)
|
NetFrag::NetFrag(const Header &header, const Serializer<UInt_64> &payload)
|
||||||
: header(header), data(new Serializer<UInt_64>[header.fragments]), size(header.fragments)
|
: header(header), data(new Serializer<UInt_64>[header.fragmentCount]), size(header.fragmentCount)
|
||||||
{
|
{
|
||||||
this->header.fragment = 0;
|
this->header.fragment = 0;
|
||||||
data[header.fragment] = payload;
|
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)
|
: header(header), data(new Serializer<UInt_64>[size]), size(size)
|
||||||
{
|
{
|
||||||
this->header.fragments = size;
|
this->header.fragmentCount = size;
|
||||||
this->header.fragment = 0;
|
this->header.fragment = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetFrags::NetFrags(NetFrags &&frags) noexcept
|
NetFrag::NetFrag(NetFrag &&frags) noexcept
|
||||||
: header(frags.header), data(frags.data), size(frags.size)
|
: header(frags.header), data(frags.data), size(frags.size)
|
||||||
{
|
{
|
||||||
frags.header = {};
|
frags.header = {};
|
||||||
@ -34,14 +34,14 @@ namespace ehs
|
|||||||
frags.size = 0;
|
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)
|
: header(frags.header), data(new Serializer<UInt_64>[frags.size]), size(frags.size)
|
||||||
{
|
{
|
||||||
for (UInt_64 i = 0; i < size; ++i)
|
for (UInt_64 i = 0; i < size; ++i)
|
||||||
data[i] = frags.data[i];
|
data[i] = frags.data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
NetFrags &NetFrags::operator=(NetFrags &&frags) noexcept
|
NetFrag &NetFrag::operator=(NetFrag &&frags) noexcept
|
||||||
{
|
{
|
||||||
if (this == &frags)
|
if (this == &frags)
|
||||||
return *this;
|
return *this;
|
||||||
@ -60,7 +60,7 @@ namespace ehs
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetFrags &NetFrags::operator=(const NetFrags &frags)
|
NetFrag &NetFrag::operator=(const NetFrag &frags)
|
||||||
{
|
{
|
||||||
if (this == &frags)
|
if (this == &frags)
|
||||||
return *this;
|
return *this;
|
||||||
@ -75,22 +75,22 @@ namespace ehs
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetFrags::operator Serializer<UInt_64> *() const
|
NetFrag::operator Serializer<UInt_64> *() const
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Header NetFrags::GetHeader() const
|
Header NetFrag::GetHeader() const
|
||||||
{
|
{
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt_64 NetFrags::Size() const
|
UInt_64 NetFrag::Size() const
|
||||||
{
|
{
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetFrags::IsComplete() const
|
bool NetFrag::IsComplete() const
|
||||||
{
|
{
|
||||||
for (UInt_64 i = 0; i < size; ++i)
|
for (UInt_64 i = 0; i < size; ++i)
|
||||||
if (!data[i].Size())
|
if (!data[i].Size())
|
||||||
@ -99,7 +99,7 @@ namespace ehs
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Packet NetFrags::Combine() const
|
Packet NetFrag::Combine() const
|
||||||
{
|
{
|
||||||
UInt_64 rSize = 0;
|
UInt_64 rSize = 0;
|
||||||
for (UInt_64 i = 0; i < size; ++i)
|
for (UInt_64 i = 0; i < size; ++i)
|
||||||
@ -110,7 +110,7 @@ namespace ehs
|
|||||||
header,
|
header,
|
||||||
{Endianness::LE, rSize}
|
{Endianness::LE, rSize}
|
||||||
};
|
};
|
||||||
result.header.fragments = 0;
|
result.header.fragmentCount = 0;
|
||||||
|
|
||||||
for (UInt_64 i = 0; i < size; ++i)
|
for (UInt_64 i = 0; i < size; ++i)
|
||||||
result.payload.WriteSer(data[i]);
|
result.payload.WriteSer(data[i]);
|
@ -1,28 +1,27 @@
|
|||||||
#include "ehs/io/socket/ehc/NetOp.h"
|
#include "ehs/io/socket/ehc/NetOp.h"
|
||||||
#include "ehs/io/socket/EHC.h"
|
#include "ehs/io/socket/EHC.h"
|
||||||
#include "ehs/io/socket/ehc/NetEnd.h"
|
#include "ehs/io/socket/ehc/NetEnd.h"
|
||||||
#include "ehs/io/socket/ehc/NetSys.h"
|
|
||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
NetOp::NetOp()
|
NetOp::NetOp()
|
||||||
: hashId(0)
|
: id(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NetOp::NetOp(Str_8 id)
|
NetOp::NetOp(Str_8 name)
|
||||||
: hashId(id.Hash_64()), id((Str_8 &&)id)
|
: id(name.Hash_64()), name((Str_8 &&)name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NetOp::NetOp(NetOp&& op) noexcept
|
NetOp::NetOp(NetOp&& op) noexcept
|
||||||
: hashId(op.hashId), id((Str_8 &&)op.id)
|
: id(op.id), name((Str_8 &&)op.name)
|
||||||
{
|
{
|
||||||
op.hashId = 0;
|
op.id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetOp::NetOp(const NetOp &op)
|
NetOp::NetOp(const NetOp &op)
|
||||||
: hashId(op.hashId), id(op.id)
|
: id(op.id), name(op.name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,10 +30,10 @@ namespace ehs
|
|||||||
if (this == &op)
|
if (this == &op)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
hashId = op.hashId;
|
id = op.id;
|
||||||
id = (Str_8 &&)op.id;
|
name = (Str_8 &&)op.name;
|
||||||
|
|
||||||
op.hashId = 0;
|
op.id = 0;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -44,23 +43,23 @@ namespace ehs
|
|||||||
if (this == &op)
|
if (this == &op)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
hashId = op.hashId;
|
|
||||||
id = op.id;
|
id = op.id;
|
||||||
|
name = op.name;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Str_8 NetOp::GetId() const
|
UInt_64 NetOp::GetId() const
|
||||||
{
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt_64 NetOp::GetHashId() const
|
Str_8 NetOp::GetName() const
|
||||||
{
|
{
|
||||||
return hashId;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetOp::Process(EHC *ehc, NetEnd *endpoint, NetSys *sys, Serializer<UInt_64> &payload)
|
void NetOp::Execute(NetChannel *channel, NetEnd *endpoint, NetSys *sys, Serializer<UInt_64> &payload)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
602
src/io/socket/ehc/NetServerCh.cpp
Normal file
602
src/io/socket/ehc/NetServerCh.cpp
Normal file
@ -0,0 +1,602 @@
|
|||||||
|
#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()
|
||||||
|
: maxEndpoints(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NetServerCh::NetServerCh(Str_8 name, const Version &version, const UInt_64 maxEndpoints)
|
||||||
|
: NetChannel((Str_8 &&)name, version), maxEndpoints(maxEndpoints)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NetServerCh::NetServerCh(NetServerCh &&server) noexcept
|
||||||
|
: NetChannel((NetChannel &&)server), 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)
|
||||||
|
: NetChannel(server), maxEndpoints(server.maxEndpoints)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NetServerCh &NetServerCh::operator=(NetServerCh &&server) noexcept
|
||||||
|
{
|
||||||
|
if (this == &server)
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
NetChannel::operator=((NetChannel &&)server);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
NetChannel::operator=(server);
|
||||||
|
|
||||||
|
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> NetServerCh::OnShutdown()
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
#include "ehs/io/socket/EHC.h"
|
#include "ehs/io/socket/EHC.h"
|
||||||
#include "ehs/io/socket/ehc/NetEnd.h"
|
#include "ehs/io/socket/ehc/NetEnd.h"
|
||||||
#include "ehs/io/socket/ehc/NetOp.h"
|
#include "ehs/io/socket/ehc/NetOp.h"
|
||||||
|
#include "ehs/io/socket/ehc/NetChannel.h"
|
||||||
|
|
||||||
namespace ehs
|
namespace ehs
|
||||||
{
|
{
|
||||||
@ -14,23 +15,23 @@ namespace ehs
|
|||||||
}
|
}
|
||||||
|
|
||||||
NetSys::NetSys()
|
NetSys::NetSys()
|
||||||
: hashId(0)
|
: id(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NetSys::NetSys(Str_8 id)
|
NetSys::NetSys(Str_8 name)
|
||||||
: hashId(id.Hash_64()), id((Str_8&&)id)
|
: id(name.Hash_64()), name((Str_8&&)name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NetSys::NetSys(NetSys&& sys) noexcept
|
NetSys::NetSys(NetSys&& sys) noexcept
|
||||||
: hashId(sys.hashId), id((Str_8&&)sys.id), ops((Array<NetOp*>&&)sys.ops)
|
: id(sys.id), name((Str_8&&)sys.name), ops((Array<NetOp*>&&)sys.ops)
|
||||||
{
|
{
|
||||||
sys.hashId = 0;
|
sys.id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetSys::NetSys(const NetSys& sys)
|
NetSys::NetSys(const NetSys& sys)
|
||||||
: hashId(sys.hashId), id(sys.id)
|
: id(sys.id), name(sys.name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,11 +40,11 @@ namespace ehs
|
|||||||
if (this == &sys)
|
if (this == &sys)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
hashId = sys.hashId;
|
id = sys.id;
|
||||||
id = (Str_8&&)sys.id;
|
name = (Str_8&&)sys.name;
|
||||||
ops = (Array<NetOp*>&&)sys.ops;
|
ops = (Array<NetOp*>&&)sys.ops;
|
||||||
|
|
||||||
sys.hashId = 0;
|
sys.id = 0;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -53,27 +54,27 @@ namespace ehs
|
|||||||
if (this == &sys)
|
if (this == &sys)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
hashId = sys.hashId;
|
|
||||||
id = sys.id;
|
id = sys.id;
|
||||||
|
name = sys.name;
|
||||||
ops = Array<NetOp*>();
|
ops = Array<NetOp*>();
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Str_8 NetSys::GetId() const
|
UInt_64 NetSys::GetId() const
|
||||||
{
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt_64 NetSys::GetHashId() const
|
Str_8 NetSys::GetName() const
|
||||||
{
|
{
|
||||||
return hashId;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetSys::HasOperation(const UInt_64 hashId) const
|
bool NetSys::HasOperation(const UInt_64 id) const
|
||||||
{
|
{
|
||||||
for (UInt_64 i = 0; i < ops.Size(); ++i)
|
for (UInt_64 i = 0; i < ops.Size(); ++i)
|
||||||
if (ops[i]->GetHashId() == hashId)
|
if (ops[i]->GetId() == id)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -81,7 +82,7 @@ namespace ehs
|
|||||||
|
|
||||||
bool NetSys::AddOperation(NetOp* op)
|
bool NetSys::AddOperation(NetOp* op)
|
||||||
{
|
{
|
||||||
if (HasOperation(op->GetHashId()))
|
if (HasOperation(op->GetId()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ops.Push(op);
|
ops.Push(op);
|
||||||
@ -89,13 +90,13 @@ namespace ehs
|
|||||||
return true;
|
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)
|
for (UInt_64 i = 0; i < ops.Size(); ++i)
|
||||||
{
|
{
|
||||||
if (ops[i]->GetHashId() == hashId)
|
if (ops[i]->GetId() == hashId)
|
||||||
{
|
{
|
||||||
ops[i]->Process(ehc, endpoint, this, payload);
|
ops[i]->Execute(channel, endpoint, this, payload);
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -18,7 +18,7 @@ namespace ehs
|
|||||||
}
|
}
|
||||||
|
|
||||||
Spotify::Spotify(Str_8 clientId, Str_8 secret, Str_8 redURI, Array<Str_8> scopes, const bool forceVerify)
|
Spotify::Spotify(Str_8 clientId, Str_8 secret, Str_8 redURI, Array<Str_8> scopes, const bool forceVerify)
|
||||||
: client(AddrType::IPV4), clientId((Str_8 &&)clientId), secret((Str_8 &&)secret), redURI((Str_8 &&)redURI),
|
: client(IP::V4), clientId((Str_8 &&)clientId), secret((Str_8 &&)secret), redURI((Str_8 &&)redURI),
|
||||||
scopes((Array<Str_8> &&)scopes), forceVerify(forceVerify)
|
scopes((Array<Str_8> &&)scopes), forceVerify(forceVerify)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ namespace ehs
|
|||||||
"&response_type=code&show_dialog=" + (forceVerify ? "true" : "false") + "&scope=" +
|
"&response_type=code&show_dialog=" + (forceVerify ? "true" : "false") + "&scope=" +
|
||||||
scopesFinal;
|
scopesFinal;
|
||||||
|
|
||||||
TCP server(AddrType::IPV4);
|
TCP server(IP::V4);
|
||||||
server.Initialize();
|
server.Initialize();
|
||||||
server.Bind("", 65534);
|
server.Bind("", 65534);
|
||||||
server.Listen();
|
server.Listen();
|
||||||
@ -73,7 +73,7 @@ namespace ehs
|
|||||||
|
|
||||||
server.Release();
|
server.Release();
|
||||||
|
|
||||||
SSL accounts(AddrType::IPV4);
|
SSL accounts(IP::V4);
|
||||||
accounts.Initialize();
|
accounts.Initialize();
|
||||||
accounts.Connect("accounts.spotify.com", SSL::HTTPS_Port);
|
accounts.Connect("accounts.spotify.com", SSL::HTTPS_Port);
|
||||||
|
|
||||||
@ -588,7 +588,7 @@ namespace ehs
|
|||||||
|
|
||||||
bool Spotify::ReAuthorize()
|
bool Spotify::ReAuthorize()
|
||||||
{
|
{
|
||||||
SSL accounts(AddrType::IPV4);
|
SSL accounts(IP::V4);
|
||||||
accounts.Initialize();
|
accounts.Initialize();
|
||||||
accounts.Connect("accounts.spotify.com", SSL::HTTPS_Port);
|
accounts.Connect("accounts.spotify.com", SSL::HTTPS_Port);
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ namespace ehs
|
|||||||
}
|
}
|
||||||
|
|
||||||
Twitch::Twitch(const Str_8& clientId, const Str_8& secret, const Str_8& redURI, const Array<Str_8>& scopes, const bool forceVerify)
|
Twitch::Twitch(const Str_8& clientId, const Str_8& secret, const Str_8& redURI, const Array<Str_8>& scopes, const bool forceVerify)
|
||||||
: client(AddrType::IPV4), clientId(clientId), secret(secret), redURI(redURI), scopes(scopes), forceVerify(forceVerify)
|
: client(IP::V4), clientId(clientId), secret(secret), redURI(redURI), scopes(scopes), forceVerify(forceVerify)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ namespace ehs
|
|||||||
"&response_type=code&force_verify=" + (forceVerify ? "true" : "false") + "&scope=" +
|
"&response_type=code&force_verify=" + (forceVerify ? "true" : "false") + "&scope=" +
|
||||||
scopesFinal;
|
scopesFinal;
|
||||||
|
|
||||||
TCP server(AddrType::IPV4);
|
TCP server(IP::V4);
|
||||||
server.Bind("", 65535);
|
server.Bind("", 65535);
|
||||||
server.Listen();
|
server.Listen();
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ namespace ehs
|
|||||||
if (initialized)
|
if (initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
client = TCP(ehs::AddrType::IPV4);
|
client = TCP(ehs::IP::V4);
|
||||||
client.Connect(DNS::Resolve("irc.chat.twitch.tv"), 6667);
|
client.Connect(DNS::Resolve("irc.chat.twitch.tv"), 6667);
|
||||||
client.SetBlocking(false);
|
client.SetBlocking(false);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user