Finished implementing, now for the testing phase.
This commit is contained in:
@@ -8,7 +8,7 @@ namespace ehs
|
||||
class EHS_LIB_IO BaseDNS
|
||||
{
|
||||
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.
|
||||
/// @param [in] hostname The given hostname to resolve.
|
||||
|
@@ -12,7 +12,7 @@ namespace ehs
|
||||
class EHS_LIB_IO BaseTCP
|
||||
{
|
||||
protected:
|
||||
AddrType addrType;
|
||||
IP ip;
|
||||
Str_8 localAddr;
|
||||
UInt_16 localPort;
|
||||
Str_8 remoteHostName;
|
||||
@@ -35,7 +35,7 @@ namespace ehs
|
||||
|
||||
/// Properly initializes the socket.
|
||||
/// @param [in] type The ip version to initialize the socket with.
|
||||
BaseTCP(AddrType addrType);
|
||||
BaseTCP(IP ip);
|
||||
|
||||
BaseTCP(BaseTCP&& tcp) noexcept;
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace ehs
|
||||
|
||||
/// Retrieves the sockets ip version.
|
||||
/// @returns The ip version.
|
||||
AddrType GetAddressType() const;
|
||||
IP GetAddressType() const;
|
||||
|
||||
/// Retrieves the bound ip address.
|
||||
/// @returns The ip address.
|
||||
|
@@ -9,9 +9,7 @@ namespace ehs
|
||||
class EHS_LIB_IO BaseUDP
|
||||
{
|
||||
protected:
|
||||
AddrType type;
|
||||
Str_8 address;
|
||||
UInt_16 port;
|
||||
Endpoint localEndpoint;
|
||||
bool bound;
|
||||
|
||||
public:
|
||||
@@ -22,7 +20,7 @@ namespace ehs
|
||||
|
||||
/// Properly initializes the socket.
|
||||
/// @param [in] type The ip version to initialize the socket with.
|
||||
BaseUDP(AddrType type);
|
||||
BaseUDP(IP version);
|
||||
|
||||
BaseUDP(BaseUDP&& udp) noexcept;
|
||||
|
||||
@@ -40,13 +38,13 @@ namespace ehs
|
||||
/// @param [in] address The ip address to bind to.
|
||||
/// @param [in] port The port to bind to.
|
||||
/// @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.
|
||||
/// @param [in] type The ip version of the endpoint.
|
||||
/// @param [in] address The ip address of the endpoint.
|
||||
/// @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.
|
||||
/// @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 [in] size The max size of the buffer in bytes to store the data.
|
||||
/// @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.
|
||||
/// @returns The result.
|
||||
@@ -73,17 +71,7 @@ namespace ehs
|
||||
|
||||
virtual bool IsIPv6Only() const = 0;
|
||||
|
||||
/// Retrieves the bound ip version.
|
||||
/// @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;
|
||||
Endpoint GetLocalEndpoint() const;
|
||||
|
||||
/// Retrieves whether or not this socket was initialized.
|
||||
/// @returns The result.
|
||||
|
@@ -10,7 +10,7 @@ namespace ehs
|
||||
class EHS_LIB_IO DNS final : public BaseDNS
|
||||
{
|
||||
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);
|
||||
};
|
||||
|
@@ -7,7 +7,7 @@ namespace ehs
|
||||
class EHS_LIB_IO DNS final : public BaseDNS
|
||||
{
|
||||
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);
|
||||
};
|
||||
|
@@ -1,78 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/io/socket/ehc/NetUtils.h"
|
||||
#include "ehs/io/socket/ehc/NetEnc.h"
|
||||
#include "ehs/Serializer.h"
|
||||
#include "ehs/Vector.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "Socket.h"
|
||||
#include "UDP.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class NetSys;
|
||||
class NetServerCh;
|
||||
class NetClientCh;
|
||||
class NetEnd;
|
||||
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
|
||||
{
|
||||
private:
|
||||
friend class NetEnc;
|
||||
friend class NetChannel;
|
||||
friend class NetServerCh;
|
||||
friend class NetClientCh;
|
||||
friend class NetEnd;
|
||||
|
||||
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;
|
||||
Version appVer;
|
||||
EndDisp disposition;
|
||||
UInt_64 hashName;
|
||||
Str_8 name;
|
||||
bool dropPackets;
|
||||
Byte* buffer;
|
||||
UInt_32 bufferSize;
|
||||
UInt_64 lastTSC;
|
||||
float delta;
|
||||
Array<NetEnc *> encryptions;
|
||||
Array<NetSys *> systems;
|
||||
UInt_32 maxEndpoints;
|
||||
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;
|
||||
Array<NetServerCh *> servers;
|
||||
Array<NetClientCh *> clients;
|
||||
|
||||
public:
|
||||
~EHC();
|
||||
|
||||
EHC();
|
||||
|
||||
EHC(const Version &ver, Str_8 name, UInt_64 maxEndpoints);
|
||||
|
||||
EHC(const Version &ver, Str_8 name);
|
||||
EHC(IP version = IP::V6);
|
||||
|
||||
EHC(EHC &&sock) noexcept;
|
||||
|
||||
@@ -86,143 +49,47 @@ namespace ehs
|
||||
|
||||
void Release();
|
||||
|
||||
void Bind(AddrType newType, const Str_8& newAddress, UInt_16 newPort);
|
||||
|
||||
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 Bind(const Endpoint &endpoint);
|
||||
|
||||
void Poll();
|
||||
|
||||
bool IsInitialized() const;
|
||||
|
||||
AddrType GetLocalAddressType() const;
|
||||
|
||||
Str_8 GetLocalAddress() const;
|
||||
|
||||
UInt_16 GetLocalPort() const;
|
||||
Endpoint GetLocalEndpoint() const;
|
||||
|
||||
bool IsBound() const;
|
||||
|
||||
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);
|
||||
|
||||
NetEnc* GetEncryption(UInt_64 encHashId) const;
|
||||
bool AddServer(NetServerCh *server);
|
||||
|
||||
NetEnc* GetEncryption(const Str_8& encId) const;
|
||||
bool AddClient(NetClientCh *channel);
|
||||
|
||||
bool HasSystem(UInt_64 sysHashId) const;
|
||||
private:
|
||||
bool HasEncryption(UInt_64 encId) const;
|
||||
|
||||
bool HasSystem(const Str_8& sysId) const;
|
||||
bool HasEncryption(const Str_8& encName) const;
|
||||
|
||||
bool AddSystem(NetSys *sys);
|
||||
NetEnc* GetEncryption(UInt_64 encId) const;
|
||||
|
||||
NetSys* GetSystem(UInt_64 sysHashId) const;
|
||||
NetEnc* GetEncryption(const Str_8& encName) const;
|
||||
|
||||
NetSys* GetSystem(const Str_8& sysId) const;
|
||||
bool HasServer(UInt_64 serverId) const;
|
||||
|
||||
bool HasEndpoint(EndDisp endDisp, Status endStatus, const Char_8 token[64]) const;
|
||||
bool HasServer(const Str_8& serverName) const;
|
||||
|
||||
bool HasEndpoint(EndDisp endDisp, Status endStatus, UInt_64 hashId) const;
|
||||
NetServerCh *GetServer(UInt_64 serverId) const;
|
||||
|
||||
bool HasEndpoint(EndDisp endDisp, Status endStatus, const Str_8 &id) const;
|
||||
NetServerCh *GetServer(const Str_8& serverName) const;
|
||||
|
||||
bool HasEndpoint(EndDisp endDisp, const Char_8 token[64]) const;
|
||||
bool HasClient(UInt_64 clientId) const;
|
||||
|
||||
bool HasEndpoint(EndDisp endDisp, UInt_64 hashId) const;
|
||||
bool HasClient(const Str_8& clientName) const;
|
||||
|
||||
bool HasEndpoint(EndDisp endDisp, const Str_8 &id) const;
|
||||
NetClientCh *GetClient(UInt_64 clientId) 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 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();
|
||||
NetClientCh *GetClient(const Str_8& clientName) const;
|
||||
};
|
||||
}
|
@@ -23,7 +23,7 @@ namespace ehs
|
||||
|
||||
SSL();
|
||||
|
||||
SSL(const AddrType type);
|
||||
SSL(const IP type);
|
||||
|
||||
SSL(TCP&& tcp) noexcept;
|
||||
|
||||
|
@@ -1,7 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Str.h"
|
||||
|
||||
#ifndef EHS_IPV4_HEADER
|
||||
#define EHS_IPV4_HEADER 60
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
#ifndef EHS_IPV6_HEADER
|
||||
@@ -22,10 +25,10 @@
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class AddrType
|
||||
enum class IP
|
||||
{
|
||||
IPV6,
|
||||
IPV4
|
||||
V4,
|
||||
V6
|
||||
};
|
||||
|
||||
enum class ContentType
|
||||
@@ -41,6 +44,13 @@ namespace ehs
|
||||
NONE
|
||||
};
|
||||
|
||||
struct Endpoint
|
||||
{
|
||||
IP version = IP::V6;
|
||||
Str_8 address;
|
||||
UInt_16 port = 0;
|
||||
};
|
||||
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
typedef UInt_64 Socket;
|
||||
#define EHS_INVALID_SOCKET EHS_UINT_64_MAX
|
||||
|
@@ -22,7 +22,7 @@ namespace ehs
|
||||
/// Default members initialization.
|
||||
TCP();
|
||||
|
||||
TCP(AddrType addrType);
|
||||
TCP(IP IP);
|
||||
|
||||
TCP(TCP&& tcp) noexcept;
|
||||
|
||||
|
@@ -22,7 +22,7 @@ namespace ehs
|
||||
/// Default members initialization.
|
||||
TCP();
|
||||
|
||||
TCP(AddrType addrType);
|
||||
TCP(IP IP);
|
||||
|
||||
TCP(TCP&& tcp) noexcept;
|
||||
|
||||
|
@@ -19,7 +19,7 @@ namespace ehs
|
||||
UDP();
|
||||
|
||||
/// Default members initialization.
|
||||
UDP(AddrType type);
|
||||
UDP(IP version);
|
||||
|
||||
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] port The port to bind to.
|
||||
/// @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.
|
||||
/// @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] size The size of the C-style byte array.
|
||||
/// @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.
|
||||
/// @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.
|
||||
/// @returns The size of the data received.
|
||||
/// @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.
|
||||
/// @param [in] blocking Whether or not to block.
|
||||
|
@@ -19,7 +19,7 @@ namespace ehs
|
||||
UDP();
|
||||
|
||||
/// Default members initialization.
|
||||
UDP(const AddrType addrType);
|
||||
UDP(const IP IP);
|
||||
|
||||
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] port The port to bind to.
|
||||
/// @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(IP type, const Str_8& address, UInt_16 port) override;
|
||||
|
||||
/// 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.
|
||||
@@ -49,7 +49,7 @@ namespace ehs
|
||||
/// @param [in] data The C-style byte array to send.
|
||||
/// @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".
|
||||
UInt_64 Send(AddrType type, const Str_8& addr, UInt_16 port, const Byte* data, UInt_64 size) override;
|
||||
UInt_64 Send(IP type, const Str_8& addr, UInt_16 port, const Byte* data, UInt_64 size) override;
|
||||
|
||||
/// Receives data using the packet helper class.
|
||||
/// @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.
|
||||
/// @returns The size of the data received.
|
||||
/// @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(IP* type, Str_8* addr, UInt_16* port, Byte* data, UInt_64 size) override;
|
||||
|
||||
/// Sets whether or not receiving data blocks the next task.
|
||||
/// @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 sysHashId) const;
|
||||
|
||||
bool HasSystem(const Str_8& sysId) const;
|
||||
|
||||
NetSys* GetSystem(UInt_64 sysHashId) const;
|
||||
|
||||
NetSys* GetSystem(const Str_8& sysId) 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
|
||||
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Version.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
@@ -11,16 +12,16 @@ namespace ehs
|
||||
private:
|
||||
friend class EHC;
|
||||
|
||||
EHC *owner;
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
UInt_64 id;
|
||||
Str_8 name;
|
||||
Version version;
|
||||
|
||||
public:
|
||||
virtual ~NetEnc() = default;
|
||||
|
||||
NetEnc();
|
||||
|
||||
NetEnc(Str_8 id);
|
||||
NetEnc(Str_8 name, const Version &version);
|
||||
|
||||
NetEnc(NetEnc &&enc) noexcept;
|
||||
|
||||
@@ -30,14 +31,14 @@ namespace ehs
|
||||
|
||||
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 Decrypt(Byte *data, UInt_64 size) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "NetUtils.h"
|
||||
#include "NetFrags.h"
|
||||
#include "NetFrag.h"
|
||||
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Vector.h"
|
||||
@@ -10,27 +10,23 @@
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class EHC;
|
||||
class NetServerCh;
|
||||
|
||||
class NetEnd
|
||||
{
|
||||
private:
|
||||
friend class EHC;
|
||||
friend class NetServerCh;
|
||||
|
||||
EHC* owner;
|
||||
EndDisp disposition;
|
||||
UInt_64 hashName;
|
||||
NetServerCh* owner;
|
||||
UInt_64 id;
|
||||
Str_8 name;
|
||||
Status status;
|
||||
Architecture arch;
|
||||
NetStatus status;
|
||||
Char_8 token[64];
|
||||
UInt_64 nextSendId;
|
||||
Vector<Insurance> sent;
|
||||
UInt_64 nextRecvId;
|
||||
Vector<NetFrags> received;
|
||||
AddrType type;
|
||||
Str_8 address;
|
||||
UInt_16 port;
|
||||
Vector<NetFrag> received;
|
||||
Endpoint endpoint;
|
||||
float deltaDuration;
|
||||
float deltaRate;
|
||||
float timeout;
|
||||
@@ -42,9 +38,9 @@ namespace ehs
|
||||
public:
|
||||
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;
|
||||
|
||||
@@ -54,15 +50,11 @@ namespace ehs
|
||||
|
||||
NetEnd &operator=(const NetEnd &end);
|
||||
|
||||
EndDisp GetDisposition() const;
|
||||
|
||||
UInt_64 GetHashName() const;
|
||||
UInt_64 GetId() const;
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
Status GetStatus() const;
|
||||
|
||||
Architecture GetArchitecture() const;
|
||||
NetStatus GetStatus() 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] op The operation hash id in the system to execute.
|
||||
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
|
||||
void Send(bool deltaLocked, 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.
|
||||
/// @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] op The operation string id in the system to execute.
|
||||
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
|
||||
void Send(bool deltaLocked, 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;
|
||||
|
||||
Str_8 GetAddress() const;
|
||||
|
||||
UInt_16 GetPort() const;
|
||||
Endpoint GetEndpoint() const;
|
||||
|
||||
void SetDeltaRate(float newDeltaRate);
|
||||
|
||||
@@ -107,23 +97,21 @@ namespace ehs
|
||||
private:
|
||||
void Poll(float delta);
|
||||
|
||||
void SetStatus(Status newStatus);
|
||||
void SetStatus(NetStatus newStatus);
|
||||
|
||||
void RemoveInsurance(UInt_64 msgId, UInt_64 fragment);
|
||||
|
||||
void AddReceived(const Header& header, const Serializer<>& payload);
|
||||
|
||||
Vector<NetFrags>* GetReceived();
|
||||
Vector<NetFrag>* GetReceived();
|
||||
|
||||
void Ping(float delta);
|
||||
|
||||
void Pong(float delta);
|
||||
|
||||
void SetLatency(float newLatency);
|
||||
|
||||
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);
|
||||
|
||||
|
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
|
||||
{
|
||||
class EHC;
|
||||
class NetChannel;
|
||||
class NetSys;
|
||||
class NetEnd;
|
||||
|
||||
@@ -37,6 +37,6 @@ namespace ehs
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
private:
|
||||
virtual void Process(EHC *ehc, NetEnd *endpoint, NetSys *sys, Serializer<UInt_64> &payload);
|
||||
virtual void Process(NetChannel *channel, NetEnd *endpoint, NetSys *sys, Serializer<UInt_64> &payload);
|
||||
};
|
||||
}
|
103
include/ehs/io/socket/ehc/NetServerCh.h
Normal file
103
include/ehs/io/socket/ehc/NetServerCh.h
Normal file
@@ -0,0 +1,103 @@
|
||||
#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(UInt_64 maxEndpoints = 0);
|
||||
|
||||
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,14 +6,16 @@
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class EHC;
|
||||
class NetChannel;
|
||||
class NetEnd;
|
||||
class NetOp;
|
||||
|
||||
class NetSys
|
||||
{
|
||||
private:
|
||||
friend class EHC;
|
||||
friend class NetChannel;
|
||||
friend class NetServerCh;
|
||||
friend class NetClientCh;
|
||||
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
@@ -43,6 +45,6 @@ namespace ehs
|
||||
bool AddOperation(NetOp *op);
|
||||
|
||||
private:
|
||||
void Execute(EHC *ehc, NetEnd *endpoint, UInt_64 hashId, Serializer<UInt_64> &payload);
|
||||
void Execute(NetChannel *channel, NetEnd *endpoint, UInt_64 hashId, Serializer<UInt_64> &payload);
|
||||
};
|
||||
}
|
@@ -4,33 +4,41 @@
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class EndDisp : UInt_8
|
||||
{
|
||||
ENDPOINT,
|
||||
SERVICE
|
||||
};
|
||||
|
||||
enum class Status : UInt_8
|
||||
enum class NetStatus : UInt_8
|
||||
{
|
||||
DISCONNECTED,
|
||||
ACTIVE,
|
||||
PENDING,
|
||||
IN_LOCAL_QUEUE,
|
||||
IN_REMOTE_QUEUE,
|
||||
QUEUED
|
||||
};
|
||||
|
||||
enum class NetChannelType : UInt_8
|
||||
{
|
||||
SERVER,
|
||||
CLIENT
|
||||
};
|
||||
|
||||
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 fragments = 0;
|
||||
UInt_64 fragmentCount = 0;
|
||||
UInt_64 fragment = 0;
|
||||
bool ensure = false;
|
||||
EndDisp disposition = EndDisp::ENDPOINT;
|
||||
Char_8 token[64] = {};
|
||||
UInt_64 system = 0;
|
||||
UInt_64 op = 0;
|
||||
UInt_64 systemId = 0;
|
||||
UInt_64 opId = 0;
|
||||
};
|
||||
|
||||
void WriteHeader(const Header &header, Serializer<UInt_64> &data);
|
||||
|
||||
Header ReadHeader(Serializer<UInt_64> &data);
|
||||
|
||||
struct Packet
|
||||
{
|
||||
Header header;
|
||||
|
Reference in New Issue
Block a user