[*] Kill net. Branching...

This commit is contained in:
Reece Wilson 2022-04-01 04:38:10 +01:00
parent 51df2294b6
commit a4568be6fa
33 changed files with 193 additions and 1357 deletions

View File

@ -33,6 +33,36 @@ namespace Aurora::IO::Net
eIPProtocolV6
));
AUE_DEFINE(ESocketInfo, (
eByDns,
eByEndpoint
));
AUE_DEFINE(ENetworkError, (
eResourceConstraint,
eIllegalArgument,
ePermissionDenied,
eSocketBufferOverflow,
eAsyncError,
eNoNetwork,
eUnreachable,
eTimeout,
eSocketClosed,
eConnectionReset,
eEndpointRefused,
eServiceRefused,
eServiceTaken,
eUnknown
));
AUE_DEFINE(EHandleErrorClass, (
ePinError,
eUserDeny,
eBrokenPacket,
eInvalidCipher,
eBadCert
));
struct AUKN_SYM IPAddress
{
EIPProtocol ip;
@ -42,44 +72,39 @@ namespace Aurora::IO::Net
AuUInt16 v6[8];
};
IPAddress();
IPAddress(const AuString &parse);
AuString ToString() const;
bool IsValid() const;
inline operator bool() const
{
return IsValid();
}
inline bool operator ==(const IPAddress &cmp) const
{
if (cmp.ip != this->ip) return false;
if (cmp.ip == EIPProtocol::eIPProtocolV4)
{
return AuMemcmp(cmp.v4, this->v4, sizeof(this->v4)) == 0;
}
else
{
return AuMemcmp(cmp.v6, this->v6, sizeof(this->v6)) == 0;
}
}
//IPAddress();
//IPAddress(const AuString &parse);
//
//AuString ToString() const;
//bool IsValid() const;
//
//
//inline operator bool() const
//{
// return IsValid();
//}
//
//inline bool operator ==(const IPAddress &cmp) const
//{
// if (cmp.ip != this->ip) return false;
//
// if (cmp.ip == EIPProtocol::eIPProtocolV4)
// {
// return AuMemcmp(cmp.v4, this->v4, sizeof(this->v4)) == 0;
// }
// else
// {
// return AuMemcmp(cmp.v6, this->v6, sizeof(this->v6)) == 0;
// }
//}
};
AUE_DEFINE(ESocketInfo, (
eByDns,
eByEndpoint
));
struct SocketHostName
{
SocketHostName(const AuString &name) : info(ESocketInfo::eByDns), hostname(name), address()
inline SocketHostName(const AuString &name) : info(ESocketInfo::eByDns), hostname(name), address()
{}
SocketHostName(const IPAddress &endpoint) : info(ESocketInfo::eByEndpoint), address(endpoint), hostname()
inline SocketHostName(const IPAddress &endpoint) : info(ESocketInfo::eByEndpoint), address(endpoint), hostname()
{}
const ESocketInfo info;
@ -91,7 +116,7 @@ namespace Aurora::IO::Net
if (cmp.info != this->info) return false;
if (cmp.info == ESocketInfo::eByEndpoint)
{
return cmp.address == this->address;
return false;// cmp.address == this->address;
}
else
{
@ -103,7 +128,8 @@ namespace Aurora::IO::Net
struct IPEndpoint
{
IPAddress ip;
AuUInt16 port;
AuUInt16 port {0};
AuUInt32 ipv6Scope {0};
AuUInt8 hint[32] {0};
};
@ -123,13 +149,11 @@ namespace Aurora::IO::Net
virtual AuSPtr<Crypto::X509::DecodedCertificate> GetCertificate() = 0;
};
AUE_DEFINE(EHandleErrorClass, (
ePinError,
eUserDeny,
eBrokenPacket,
eInvalidCipher,
eBadCert
));
struct NetError
{
ENetworkError error { ENetworkError::kEnumInvalid };
AuUInt osError;
};
struct TLSHandshakeError
{
@ -138,6 +162,11 @@ namespace Aurora::IO::Net
AuString message;
};
AUKN_INTERFACE(INetTask,
AUI_METHOD(void, DoWork, ())
);
AUKN_INTERFACE(IClientSubscriber,
//
AUI_METHOD(void, OnServerConnectSuccess, (const AuSPtr<ISocket> &, socket)),
@ -175,7 +204,7 @@ namespace Aurora::IO::Net
// TODO: We should introduce another std:: customer overloadable type reproducing hardcoded ascii and an int, basically std::error_code
// Maybe AuErrorCode = [std::, my_fav_stl::]error_code
// AuError = something more flexable
using Error_t = std::error_code;
using Error_t = NetError;
struct IBasicSocketPrivateContext
{
@ -197,44 +226,85 @@ namespace Aurora::IO::Net
AuUInt32 uptimeMs;
AuUInt64 bandwidthCost;
AuUInt32 blamedConnectTimeMS;
AuUInt32 totalConnectTimeMS;
SocketStatStream rx;
SocketStatStream rt;
};
enum class EUnderlyingModel
{
eAsync,
eBlocking
};
struct IBasicSocket
{
/**
* @brief Is socket still established, listening, or otherwise capable of performing non-recv operations?
* @return
*/
virtual bool IsActive() = 0;
/**
* @brief Returns the last relevant error
* @return
*/
virtual Error_t GetLastError() = 0;
/**
* @brief Initiates the shutdown sequence on the socket
*/
virtual void Shutdown() = 0;
/**
* @brief Exchanges the user-provided private context
* @param newContext
* @return
*/
virtual AuSPtr<IBasicSocketPrivateContext> SetContext(const AuSPtr<IBasicSocketPrivateContext> &newContext) = 0;
/**
* @brief Returns a user-provided private context
* @return
*/
virtual AuSPtr<IBasicSocketPrivateContext> GetContext() = 0;
/**
* @brief Returns local endpoint of the socket once established/listening
* @param out
* @return
*/
virtual bool GetLocalEndpoint(ConnectionEndpoint &out) = 0;
/**
* @brief Returns performance stats of the socket
* @return
*/
virtual SocketStat GetStats() = 0;
virtual EUnderlyingModel GetThreadModel() = 0;
/**
* @brief Schedule work on the thread assigned to the socket
* @param task
* @return
*/
virtual bool DoWork(AuSPtr<INetTask> task) = 0;
};
AUKN_INTERFACE(ISocketSubmissionComplete,
AUI_METHOD(void, OnWriteFinished, (AuUInt, fence))
);
struct OverlappedOperation
{
AuUInt fence;
AuSPtr<ISocketSubmissionComplete> callback;
};
struct StreamConfig
{
bool enableBufferedInput {true};
bool enableBufferedOutput {false};
AuUInt32 recvRingBufferLength;
};
// 30000 * (4096 * 10) / 1024 / 1024 / 1024
// = 1.1GB per ~1/2 of 2^16
// Plenty of overhead for cpu blts to go brr without becoming
// cpu bound. If you're expecting 30k connections, you can
// lose 1GB to our extended seak interface by default
AuUInt32 bufferedReadSize {4096 * 10}; // see: enableBufferedInput
AuUInt32 bufferedWriteSize {4096 * 10}; // see: enableBufferedOutput
struct SocketConfig
{
StreamConfig stream;
};
struct ISocketChannel
@ -268,21 +338,12 @@ namespace Aurora::IO::Net
//
virtual bool SeekAsync(int signedDistanceFromCur = 0) = 0;
// When BufferInputStreamAdhoc is called with false / in the default condition, read sync will be constrained by the async buffer
// When BufferInputStreamAdhoc is called with true, you will block until you can get the requested data (all of it if, all = true; any of it, all = false)
virtual bool ReadSync(const Memory::MemoryViewStreamWrite &memory, bool all = true) = 0;
// Writes max(cumulative memory.length per frame, (enableBufferedInput ? bufferedWriteSize : os page allowance)) to the sockets asynchronous stream
// Returns false when no data whatsoever was written, generic error condition
// Returns true when some data was collected, regardless of any errors that may have arose (defer to IServerSubscriber::OnClientError, IClientSubscriber::OnSocketError for error handling)
virtual bool WriteAsync(const Memory::MemoryViewStreamRead &memory) = 0;
virtual bool WriteAsync(const AuSPtr<Memory::MemoryViewRead> &memory, const OverlappedOperation &fence) = 0;
virtual bool WriteAsync(const AuSPtr<Memory::MemoryViewRead> &memory) = 0;
// Alternative WriteAsync method that calls a submission notification callback on flush on the dispatching thread
virtual bool WriteAsync(const Memory::MemoryViewStreamRead &memory, AuUInt fence, const AuSPtr<ISocketSubmissionComplete> &input) = 0;
// When BufferInputStreamAdhoc is called with false / in the default condition, read sync will be constrained by the async buffer
// When BufferInputStreamAdhoc is called with true, you will block until you can get the requested data (all of it if, all = true; any of it, all = false)
virtual bool WriteSync(const Memory::MemoryViewStreamRead &memory) = 0;
/**
* Sets the internal application buffer size
@ -293,60 +354,23 @@ namespace Aurora::IO::Net
virtual bool SetInternalInputRingBuffer(AuUInt bytes) = 0;
#if 0
/**
* Defines the maximum amount of bytes each recieve frame can ingest
*/
virtual void SetRecvLength(AuUInt32 length) = 0;
virtual AuUInt32 GetRecvLength() = 0;
/**
* Enable ad-hoc input buffer ingestion into our internal buffer
* Only use when PumpRead will not suffice by design (ie: sync apps)
*
* When set to true, there is nothing preventing you from consuming a
* DoS-worthy amount of bytes from the stream per frame
*
* This does not disable enableBufferedInput, it merely allows you
* to read beyond enableBufferedInput/bufferedReadSize by accessing
* the os stream page or hitting the network device inline
*
* There may be a performance bottleneck and/or gain depending on your
* circumstances
*
* During high bandwidth transfers, you should set this to true
*
* Default: false (0)
*/
virtual void BufferInputStreamAdhoc(bool value) = 0;
virtual void ConfigureHasDataCallback(bool enabled) = 0;
virtual void ReconfigureStreams(const StreamConfig &config) = 0;
virtual void SetRecvPerFrameLength(AuUInt32 length) = 0;
virtual AuUInt32 GetRecvPerFrameLength() = 0;
#endif
};
struct IBasicSocketThreaded : public IBasicSocket
{
virtual bool PumpRead() = 0;
virtual bool PumpWrite() = 0;
virtual bool Pump() = 0;
virtual void Run(int idx, AuUInt32 timeout) = 0;
};
struct ISocket : public IBasicSocketThreaded, public ISocketChannel
struct ISocket : public IBasicSocket, public ISocketChannel
{
virtual bool GetRemoteEndpoint(ConnectionEndpoint &out) = 0;
};
struct ILocalClientSocket : public ISocket
{
// Connects to the endpoint defined in the ClientConfig
// Completion will be notified by the following callbacks;
// IClientSubscriber::OnServerConnectSuccess,
// IClientSubscriber::OnServerConnectFailed
// returns true on success
virtual bool Connect() = 0;
// Completion will be notified by the following callbacks;
// IClientSubscriber::OnServerConnectSuccess,
// IClientSubscriber::OnServerConnectFailed
@ -361,11 +385,6 @@ namespace Aurora::IO::Net
AuSPtr<IBasicSocket> socket;
};
struct SocketConfig
{
StreamConfig stream;
};
struct ServerInfo
{
ConnectionEndpoint listen;
@ -382,9 +401,7 @@ namespace Aurora::IO::Net
struct ClientConfig : SocketConfig
{
SocketHostName socket;
//AuString service;
AuUInt16 port;
IPEndpoint endpoint;
bool enableHasDataCallback {true};
AuSPtr<IClientSubscriber> clientSubscriber;
};
@ -394,23 +411,13 @@ namespace Aurora::IO::Net
AuSPtr<IClientSubscriberTls> clientSubscriber;
};
struct IServer : public IBasicSocketThreaded
struct IServer : public IBasicSocket
{
virtual bool GetLocalEndpoint(ConnectionEndpoint &out) = 0;
virtual void GetClients(AuList<AuSPtr<IBasicSocketThreaded>> &clients) = 0;
virtual void GetClients(AuList<AuSPtr<ISocket>> &clients) = 0;
virtual bool Listen() = 0;
virtual void ReconfigureDefaultStream(const StreamConfig &config) = 0;
};
struct ISocketFactory
{
virtual bool NewServer(const ServerInfo &listen, AuSPtr<IServer> &out) = 0;
virtual bool NewTlsServer(const TLSServerInfo &keys, AuSPtr<IServer> &out) = 0;
virtual bool NewClient(const ClientConfig &info, AuSPtr<ILocalClientSocket> &out) = 0;
virtual bool NewTlsClient(const TLSClientConfig &info, AuSPtr<ILocalClientSocket> &out) = 0;
};
struct ServiceEndpoint
{
ETransportProtocol protocol;
@ -418,16 +425,6 @@ namespace Aurora::IO::Net
AuString service;
};
struct INetworkInterface
{
virtual AuList<IPEndpoint> ResolveSocketSync(const SocketHostName &hostname, AuUInt16 port) = 0;
virtual AuList<IPEndpoint> ResolveServiceSync(const ServiceEndpoint &service) = 0;
virtual bool SendDatagramAsync(const ConnectionEndpoint &endpoint, const Memory::MemoryViewRead &memory) = 0;
virtual bool SendDatagramAsync(const AuSPtr<IServer> &datagramServer, const ConnectionEndpoint &endpoint, const Memory::MemoryViewRead &memory) = 0;
virtual AuSPtr<ISocketFactory> GetSocketFactory() = 0;
};
struct AUKN_SYM WorkRange
{
@ -449,30 +446,25 @@ namespace Aurora::IO::Net
struct INetworkingPool
{
// A:
virtual AuUInt32 Pump(AuUInt8 workerId) = 0;
// A: Manual poll
virtual AuUInt32 PollWorker(AuUInt8 workerId, bool clientBound, bool writeBound) = 0;
virtual bool RunWorkerFrame(AuUInt8 workerId, AuUInt32 timeout) = 0;
// B:
virtual AuUInt32 PumpRead(AuUInt8 workerId) = 0;
virtual AuUInt32 PumpWrite(AuUInt8 workerId) = 0;
// C:
virtual AuUInt32 PollWorker(AuUInt8 workerId) = 0;
virtual AuUInt32 RunWorker(AuUInt8 workerId, AuUInt32 timeout) = 0;
// D:
// B: Ad-hoc loop-source IO
virtual bool BeginReadPollingOnWorkQueues(const WorkPoolGroup &workGroup) = 0;
virtual bool BeginSubmissionsOnOnWorkQueues(const WorkPoolGroup &workGroup) = 0;
virtual void StopPollingOnWorkQueues() = 0;
// E:
// ..
// C: Fixed timestep IO
virtual bool BeginNetworkFrequency(AuUInt32 MSTimeStep, const WorkPoolGroup &workGroup) = 0;
virtual void StopNetworkFrequency() = 0;
// Submit to worker thread
virtual bool DoWork(AuUInt8 index, AuSPtr<INetTask> task) = 0;
virtual bool DoWork(AuSPtr<INetTask> task) = 0;
// Worker count
virtual AuUInt8 GetWorkers() = 0;
virtual AuSPtr<INetworkInterface> GetNetworkInterface() = 0;
virtual void Shutdown() = 0;
};
struct NetworkPool
@ -480,5 +472,38 @@ namespace Aurora::IO::Net
AuUInt8 workers {1};
};
AUKN_SHARED_API(CreateNetworkPool, INetworkingPool, const NetworkPool & meta);
struct INetworkDatagramService
{
virtual bool SendDatagramAsync(const ConnectionEndpoint &endpoint, const Memory::MemoryViewRead &memory) = 0;
virtual bool SendDatagramAsync(const AuSPtr<IServer> &datagramServer, const ConnectionEndpoint &endpoint, const Memory::MemoryViewRead &memory) = 0;
};
struct INetworkBasicResolve
{
virtual AuList<IPEndpoint> ResolveSocketSync(const SocketHostName &hostname, AuUInt16 port) = 0;
virtual AuList<IPEndpoint> ResolveServiceSync(const ServiceEndpoint &service) = 0;
};
struct ISocketService
{
virtual bool NewServer(const ServerInfo &listen, AuSPtr<IServer> &out) = 0;
virtual bool NewTlsServer(const TLSServerInfo &keys, AuSPtr<IServer> &out) = 0;
virtual bool NewClient(const ClientConfig &info, AuSPtr<ILocalClientSocket> &out) = 0;
virtual bool NewTlsClient(const TLSClientConfig &info, AuSPtr<ILocalClientSocket> &out) = 0;
};
struct INetworkInterface
{
virtual INetworkingPool *ToPool() = 0;
virtual INetworkDatagramService *ToDatagramService() = 0;
virtual INetworkBasicResolve * ToResolveService() = 0;
virtual ISocketService * ToSocketService() = 0;
virtual void Shutdown() = 0;
};
AUKN_SHARED_API(CreateNetworkPool, INetworkInterface, const NetworkPool & meta);
}

View File

@ -25,7 +25,7 @@
#if defined(AURORA_PLATFORM_WIN32)
#include "Extensions/Win32/DarkTheme.hpp"
#endif
#include "IO/Net/Net.hpp"
//#include "IO/Net/Net.hpp"
#include "Process/ProcessMap.hpp"
#include "Exit/Exit.hpp"
#include "CmdLine/CmdLine.hpp"
@ -48,7 +48,7 @@ static void Init()
Aurora::Console::Init2();
Aurora::HWInfo::Init();
Aurora::Telemetry::Init();
Aurora::IO::Net::InitNetworking();
//Aurora::IO::Net::InitNetworking();
Aurora::Grug::InitGrug();
Aurora::Debug::InitDebug();
Aurora::Locale::Init();
@ -71,7 +71,7 @@ static void Deinit()
Aurora::Async::ShutdownAsync();
Aurora::Grug::DeinitGrug();
Aurora::Console::Exit();
Aurora::IO::Net::DeinitNetworking();
//Aurora::IO::Net::DeinitNetworking();
Aurora::Processes::Deinit();
Aurora::Exit::DeinitExit();
}

View File

@ -1,84 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BaseChannel.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Net.hpp"
#include "BaseChannel.hpp"
namespace Aurora::IO::Net
{
bool BaseChannel::GetRemoteEndpoint(ConnectionEndpoint &out)
{
return {};
}
bool BaseChannel::ReadAsync(const Memory::MemoryViewStreamWrite &memory, bool all)
{
return {};
}
bool BaseChannel::PeekAsync(const Memory::MemoryViewStreamWrite &memory)
{
return {};
}
bool BaseChannel::SeekAsync(int signedDistanceFromCur)
{
return {};
}
bool BaseChannel::ReadSync(const Memory::MemoryViewStreamWrite &memory, bool all)
{
return {};
}
bool BaseChannel::WriteAsync(const Memory::MemoryViewStreamRead &memory)
{
return {};
}
bool BaseChannel::WriteAsync(const Memory::MemoryViewStreamRead &memory, AuUInt fence, const AuSPtr<ISocketSubmissionComplete> &input)
{
return {};
}
bool BaseChannel::WriteSync(const Memory::MemoryViewStreamRead &memory)
{
return {};
}
AuUInt BaseChannel::GetInternalInputRingBuffer()
{
return {};
}
bool BaseChannel::SetInternalInputRingBuffer(AuUInt bytes)
{
return {};
}
void BaseChannel::SetRecvLength(AuUInt32 length)
{
}
AuUInt32 BaseChannel::GetRecvLength()
{
return {};
}
void BaseChannel::BufferInputStreamAdhoc(bool value)
{
}
void BaseChannel::ConfigureHasDataCallback(bool enabled)
{
}
void BaseChannel::ReconfigureStreams(const StreamConfig &config)
{
}
}

View File

@ -1,119 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BaseChannel.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
#include "PlatformChannel.hpp"
namespace Aurora::IO::Net
{
struct BaseSocket;
struct BaseChannel : public ISocketChannel
{
BaseChannel(BaseSocket *base) : base_(base), platform_(base)
{}
bool GetRemoteEndpoint(ConnectionEndpoint &out);
bool ReadAsync(const Memory::MemoryViewStreamWrite &memory, bool all) override;
bool PeekAsync(const Memory::MemoryViewStreamWrite &memory) override;
bool SeekAsync(int signedDistanceFromCur) override;
bool ReadSync(const Memory::MemoryViewStreamWrite &memory, bool all) override;
bool WriteAsync(const Memory::MemoryViewStreamRead &memory) override;
bool WriteAsync(const Memory::MemoryViewStreamRead &memory, AuUInt fence, const AuSPtr<ISocketSubmissionComplete> &input) override;
bool WriteSync(const Memory::MemoryViewStreamRead &memory) override;
AuUInt GetInternalInputRingBuffer() override;
bool SetInternalInputRingBuffer(AuUInt bytes) override;
void SetRecvLength(AuUInt32 length) override;
AuUInt32 GetRecvLength() override;
void BufferInputStreamAdhoc(bool value) override;
void ConfigureHasDataCallback(bool enabled) override;
void ReconfigureStreams(const StreamConfig &config) override;
private:
PlatformChannel platform_;
BaseSocket *base_;
};
#define IMPLEMENT_PLATFORM_PROXY(access) \
\
bool ReadAsync(const Memory::MemoryViewStreamWrite &memory, bool all) override \
{ \
return access ReadAsync(memory, all); \
} \
\
bool PeekAsync(const Memory::MemoryViewStreamWrite &memory) override \
{ \
return access PeekAsync(memory); \
} \
\
bool SeekAsync(int signedDistanceFromCur) override \
{ \
return access SeekAsync(signedDistanceFromCur); \
} \
\
bool ReadSync(const Memory::MemoryViewStreamWrite &memory, bool all) override \
{ \
return access ReadSync(memory, all); \
} \
\
bool WriteAsync(const Memory::MemoryViewStreamRead &memory) override \
{ \
return access WriteAsync(memory); \
} \
\
bool WriteAsync(const Memory::MemoryViewStreamRead &memory, AuUInt fence, const AuSPtr<ISocketSubmissionComplete> &input) override \
{ \
return access WriteAsync(memory, fence, input); \
} \
\
bool WriteSync(const Memory::MemoryViewStreamRead &memory) override \
{ \
return access WriteAsync(memory); \
} \
\
AuUInt GetInternalInputRingBuffer() override \
{ \
return access GetInternalInputRingBuffer(); \
} \
\
bool SetInternalInputRingBuffer(AuUInt bytes) override \
{ \
return access SetInternalInputRingBuffer(bytes); \
} \
\
void SetRecvLength(AuUInt32 length) override \
{ \
access SetRecvLength(length); \
} \
\
AuUInt32 GetRecvLength() override \
{ \
return access GetRecvLength(); \
} \
\
void BufferInputStreamAdhoc(bool value) override \
{ \
access BufferInputStreamAdhoc(value); \
} \
\
void ConfigureHasDataCallback(bool enabled) override \
{ \
access ConfigureHasDataCallback(enabled); \
} \
\
void ReconfigureStreams(const StreamConfig &config) override \
{ \
access ReconfigureStreams(config); \
}
}

View File

@ -1,24 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BaseLocalClient.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Net.hpp"
#include "BaseSocket.hpp"
#include "BaseLocalClient.hpp"
namespace Aurora::IO::Net
{
bool BaseLocalClient::Connect()
{
return {};
}
void BaseLocalClient::ConnectAsync()
{
}
}

View File

@ -1,25 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BaseLocalClient.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
#include "BaseSocket.hpp"
namespace Aurora::IO::Net
{
struct BaseLocalClient : ILocalClientSocket
{
bool Connect() override;
void ConnectAsync() override;
IMPLEMENT_PLATFORM_PROXY(osSocket_.)
IMPLEMENT_IBASICSOCKETTHREADED(osSocket_.)
private:
BaseSocket osSocket_;
};
}

View File

@ -1,38 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BaseNetworkInterface.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Net.hpp"
#include "BaseNetworkInterface.hpp"
namespace Aurora::IO::Net
{
AuList<IPEndpoint> BaseNetworkInterface::ResolveSocketSync(const SocketHostName &hostname, AuUInt16 port)
{
return {};
}
AuList<IPEndpoint> BaseNetworkInterface::ResolveServiceSync(const ServiceEndpoint &service)
{
return {};
}
bool BaseNetworkInterface::SendDatagramAsync(const ConnectionEndpoint &endpoint, const Memory::MemoryViewRead &memory)
{
return {};
}
bool BaseNetworkInterface::SendDatagramAsync(const AuSPtr<IServer> &datagramServer, const ConnectionEndpoint &endpoint, const Memory::MemoryViewRead &memory)
{
return {};
}
AuSPtr<ISocketFactory> BaseNetworkInterface::GetSocketFactory()
{
return {};
}
}

View File

@ -1,22 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BaseNetworkInterface.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
struct BaseNetworkInterface : INetworkInterface
{
AuList<IPEndpoint> ResolveSocketSync(const SocketHostName &hostname, AuUInt16 port) override;
AuList<IPEndpoint> ResolveServiceSync(const ServiceEndpoint &service) override;
bool SendDatagramAsync(const ConnectionEndpoint &endpoint, const Memory::MemoryViewRead &memory) override;
bool SendDatagramAsync(const AuSPtr<IServer> &datagramServer, const ConnectionEndpoint &endpoint, const Memory::MemoryViewRead &memory) override;
AuSPtr<ISocketFactory> GetSocketFactory() override;
};
}

View File

@ -1,45 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BaseServer.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Net.hpp"
#include "BaseSocket.hpp"
#include "BaseServer.hpp"
namespace Aurora::IO::Net
{
BaseServer::BaseServer(BaseSocket &&socket) : osSocket_(socket)
{}
BaseServer::~BaseServer()
{}
bool BaseServer::GetLocalEndpoint(ConnectionEndpoint &out)
{
return {};
}
void BaseServer::GetClients(AuList<AuSPtr<IBasicSocketThreaded>> &clients)
{
}
bool BaseServer::Listen()
{
return {};
}
void BaseServer::ReconfigureDefaultStream(const StreamConfig &config)
{
}
BaseSocket &BaseServer::ToPlatformSocket()
{
return this->osSocket_;
}
}

View File

@ -1,60 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BaseServer.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
#define IMPLEMENT_BASE_SERVER_PROXY(access) \
Error_t GetLastError() override \
{ \
return access GetLastError(); \
} \
\
void Shutdown() override \
{ \
return access Shutdown(); \
} \
\
AuSPtr<IBasicSocketPrivateContext> SetContext(const AuSPtr<IBasicSocketPrivateContext> &newContext) \
{ \
return access SetContext(newContext); \
} \
\
AuSPtr<IBasicSocketPrivateContext> GetContext() override \
{ \
return access GetContext(); \
} \
\
SocketStat GetStats() override \
{ \
return access GetStats(); \
} \
\
EUnderlyingModel GetThreadModel() override \
{ \
return access GetThreadModel(); \
}
struct BaseServer : public IServer
{
BaseServer(BaseSocket &&socket);
~BaseServer();
bool GetLocalEndpoint(ConnectionEndpoint &out) override;
void GetClients(AuList<AuSPtr<IBasicSocketThreaded>> &clients) override;
bool Listen() override;
void ReconfigureDefaultStream(const StreamConfig &config) override;
BaseSocket &ToPlatformSocket();
IMPLEMENT_BASE_SERVER_PROXY(osSocket_.);
private:
BaseSocket osSocket_;
};
}

View File

@ -1,43 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BaseSocket.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Net.hpp"
#include "BaseSocket.hpp"
namespace Aurora::IO::Net
{
PlatformSocket_t &BaseSocket::ToPlatformSocket()
{
return this->osSocket_;
}
BaseChannel &BaseSocket::ToChannel()
{
return this->channel_;
}
bool BaseSocket::PumpRead()
{
return {};
}
bool BaseSocket::PumpWrite()
{
return {};
}
bool BaseSocket::Pump()
{
return {};
}
void BaseSocket::Run(int idx, AuUInt32 timeout)
{
}
}

View File

@ -1,95 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BaseSocket.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
#include "BaseChannel.hpp"
#include "PlatformSocket.hpp"
namespace Aurora::IO::Net
{
#define IMPLEMENT_IBASICSOCKET(access) \
bool GetLocalEndpoint(ConnectionEndpoint &out) override \
{ \
return access GetLocalEndpoint(out); \
} \
\
bool IsActive() override \
{ \
return access IsActive(); \
} \
Error_t GetLastError() override \
{ \
return access GetLastError(); \
} \
void Shutdown() override \
{ \
access Shutdown(); \
} \
AuSPtr<IBasicSocketPrivateContext> SetContext(const AuSPtr<IBasicSocketPrivateContext> &newContext) override \
{ \
return access SetContext(newContext); \
} \
AuSPtr<IBasicSocketPrivateContext> GetContext() override \
{ \
return access GetContext(); \
} \
SocketStat GetStats() override \
{ \
return access GetStats(); \
} \
EUnderlyingModel GetThreadModel() override \
{ \
return access GetThreadModel(); \
}
#define IMPLEMENT_IBASICSOCKETTHREADED(access) \
bool PumpRead() override \
{ \
return access PumpRead(); \
} \
bool PumpWrite() override \
{ \
return access PumpWrite(); \
} \
bool Pump() override \
{ \
return access Pump(); \
} \
void Run(int idx, AuUInt32 timeout) override \
{ \
access Run(idx, timeout); \
}
struct BaseSocket : public ISocket
{
BaseSocket() : channel_(this)
{}
PlatformSocket_t &ToPlatformSocket();
BaseChannel &ToChannel();
bool PumpRead() override;
bool PumpWrite() override;
bool Pump() override;
void Run(int idx, AuUInt32 timeout) override;
bool GetRemoteEndpoint(ConnectionEndpoint &out) override
{
return channel_.GetRemoteEndpoint(out);
}
IMPLEMENT_IBASICSOCKET(osSocket_.)
IMPLEMENT_PLATFORM_PROXY(channel_.)
private:
PlatformSocket_t osSocket_;
BaseChannel channel_;
};
}

View File

@ -1,22 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: HelloNet.Win32.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "HelloNet.Win32.hpp"
namespace Aurora::IO::Net
{
void InitNetworking()
{
}
void DeinitNetworking()
{
}
}

View File

@ -1,14 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: HelloNet.Win32.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
void InitNetworking();
void DeinitNetworking();
}

View File

@ -1,64 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPAddress.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Net.hpp"
#include "IPAddress.hpp"
namespace Aurora::IO::Net
{
IPAddress::IPAddress()
{
this->ip = EIPProtocol::eEnumInvalid;
}
IPAddress::IPAddress(const AuString &parse)
{
unsigned char buf[64];
static_assert(AuArraySize(buf) >= sizeof(struct in6_addr));
static_assert(AuArraySize(buf) >= sizeof(struct in_addr));
this->ip = EIPProtocol::eEnumInvalid;
bool isIPV4 {};
if (parse.size() > 4)
{
isIPV4 = parse[1] == '.' || parse[2] == '.';
}
if (inet_pton(isIPV4 ? AF_INET : AF_INET6, parse.c_str(), buf) != 1)
{
return;
}
if (isIPV4)
{
AuWriteU32BE(this->v4, 0, AuReadU32LE(buf, 0));
}
else
{
auto ipv6 = reinterpret_cast<AuUInt16 *>(buf);
AuWriteU16BE(&this->v6[0], 0, ipv6[0]);
AuWriteU16BE(&this->v6[1], 0, ipv6[1]);
AuWriteU16BE(&this->v6[2], 0, ipv6[2]);
AuWriteU16BE(&this->v6[3], 0, ipv6[3]);
AuWriteU16BE(&this->v6[4], 0, ipv6[4]);
AuWriteU16BE(&this->v6[5], 0, ipv6[5]);
AuWriteU16BE(&this->v6[6], 0, ipv6[6]);
}
}
AuString IPAddress::ToString() const
{
return {};
}
bool IPAddress::IsValid() const
{
return EIPProtocolIsValid(this->ip);
}
}

View File

@ -1,13 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPAddress.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
}

View File

@ -1,14 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Net.cpp
Date: 2021-7-2
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Net.hpp"
namespace Aurora::IO::Net
{
}

View File

@ -1,22 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Net.hpp
Date: 2021-7-2
Author: Reece
***/
#pragma once
#include "SocketStatChannel.hpp"
#if defined(AURORA_IS_POSIX_DERIVED)
#include <arpa/inet.h>
#elif defined(AURORA_IS_MODERNNT_DERIVED)
#include <WS2tcpip.h>
#endif
namespace Aurora::IO::Net
{
}

View File

@ -1,68 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: NetworkingPool.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Net.hpp"
#include "NetworkingPool.hpp"
namespace Aurora::IO::Net
{
AuUInt32 NetworkingPool::Pump(AuUInt8 workerId)
{
return {};
}
AuUInt32 NetworkingPool::PumpRead(AuUInt8 workerId)
{
return {};
}
AuUInt32 NetworkingPool::PumpWrite(AuUInt8 workerId)
{
return {};
}
AuUInt32 NetworkingPool::PollWorker(AuUInt8 workerId)
{
return {};
}
AuUInt32 NetworkingPool::RunWorker(AuUInt8 workerId, AuUInt32 timeout)
{
return {};
}
bool NetworkingPool::BeginReadPollingOnWorkQueues(const WorkPoolGroup &workGroup)
{
return {};
}
bool NetworkingPool::BeginSubmissionsOnOnWorkQueues(const WorkPoolGroup &workGroup)
{
return {};
}
void NetworkingPool::StopPollingOnWorkQueues()
{
}
AuUInt8 NetworkingPool::GetWorkers()
{
return {};
}
AuSPtr<INetworkInterface> NetworkingPool::GetNetworkInterface()
{
return {};
}
void NetworkingPool::Shutdown()
{
}
}

View File

@ -1,39 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: NetworkingPool.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
struct NetworkingPool : INetworkingPool
{
// A:
AuUInt32 Pump(AuUInt8 workerId) override;
// B:
AuUInt32 PumpRead(AuUInt8 workerId) override;
AuUInt32 PumpWrite(AuUInt8 workerId) override;
// C:
AuUInt32 PollWorker(AuUInt8 workerId) override;
AuUInt32 RunWorker(AuUInt8 workerId, AuUInt32 timeout) override;
// D:
bool BeginReadPollingOnWorkQueues(const WorkPoolGroup &workGroup) override;
bool BeginSubmissionsOnOnWorkQueues(const WorkPoolGroup &workGroup) override;
void StopPollingOnWorkQueues() override;
// E:
AuUInt8 GetWorkers() override;
AuSPtr<INetworkInterface> GetNetworkInterface() override;
void Shutdown() override;
};
}

View File

@ -1,15 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: PlatformChannel.Win32.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "PlatformChannel.hpp"
#include "PlatformChannel.Win32.hpp"
namespace Aurora::IO::Net
{
}

View File

@ -1,28 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: PlatformChannel.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
struct BaseSocket;
struct PlatformChannel
{
PlatformChannel(BaseSocket *base) : base_(base)
{}
EUnderlyingModel SocketThreadModel();
void WritePerModel(const void *pIn, AuUInt length);
void ReadPerModel(const void *pIn, AuUInt length);
bool GetLocalEndpoint(ConnectionEndpoint &out);
bool GetRemoteEndpoint(ConnectionEndpoint &out);
private:
BaseSocket *base_;
};
}

View File

@ -1,52 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: PlatformSocket.Win32.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "PlatformSocket.Win32.hpp"
namespace Aurora::IO::Net
{
bool Win32Socket::IsActive()
{
return {};
}
Error_t Win32Socket::GetLastError()
{
return {};
}
void Win32Socket::Shutdown()
{
}
AuSPtr<IBasicSocketPrivateContext> Win32Socket::SetContext(const AuSPtr<IBasicSocketPrivateContext> &newContext)
{
return {};
}
AuSPtr<IBasicSocketPrivateContext> Win32Socket::GetContext()
{
return {};
}
bool Win32Socket::GetLocalEndpoint(ConnectionEndpoint &out)
{
return {};
}
SocketStat Win32Socket::GetStats()
{
return {};
}
EUnderlyingModel Win32Socket::GetThreadModel()
{
return EUnderlyingModel::eAsync;
}
}

View File

@ -1,25 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: PlatformSocket.Win32.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
struct Win32Socket : IBasicSocket
{
virtual bool IsActive() override;
virtual Error_t GetLastError() override;
virtual void Shutdown() override;
virtual AuSPtr<IBasicSocketPrivateContext> SetContext(const AuSPtr<IBasicSocketPrivateContext> &newContext) override;
virtual AuSPtr<IBasicSocketPrivateContext> GetContext() override;
virtual bool GetLocalEndpoint(ConnectionEndpoint &out) override;
virtual SocketStat GetStats() override;
virtual EUnderlyingModel GetThreadModel() override;
};
using PlatformSocket_t = Win32Socket;
}

View File

@ -1,17 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: PlatformSocket.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
#if defined(AURORA_PLATFORM_WIN32)
#include "PlatformSocket.Win32.hpp"
#endif
namespace Aurora::IO::Net
{
}

View File

@ -1,33 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: SocketFactory.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Net.hpp"
#include "SocketFactory.hpp"
namespace Aurora::IO::Net
{
bool BasePlatformSocketFactory::NewServer(const ServerInfo &listen, AuSPtr<IServer> &out)
{
return {};
}
bool BasePlatformSocketFactory::NewTlsServer(const TLSServerInfo &keys, AuSPtr<IServer> &out)
{
return {};
}
bool BasePlatformSocketFactory::NewClient(const ClientConfig &info, AuSPtr<ILocalClientSocket> &out)
{
return {};
}
bool BasePlatformSocketFactory::NewTlsClient(const TLSClientConfig &info, AuSPtr<ILocalClientSocket> &out)
{
return {};
}
}

View File

@ -1,20 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: SocketFactory.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
struct BasePlatformSocketFactory : public ISocketFactory
{
bool NewServer(const ServerInfo &listen, AuSPtr<IServer> &out) override;
bool NewTlsServer(const TLSServerInfo &keys, AuSPtr<IServer> &out) override;
bool NewClient(const ClientConfig &info, AuSPtr<ILocalClientSocket> &out) override;
bool NewTlsClient(const TLSClientConfig &info, AuSPtr<ILocalClientSocket> &out) override;
};
}

View File

@ -1,88 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: SocketStatAverageBps.hpp
Date: 2021-10-31
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
struct SocketStatAverageBps
{
inline AuUInt32 GetBytesPerMS(AuUInt32 timeNow)
{
if (!frameLastEnd) return bytesTransferred;
return (double(bytesTransferred) / (double(timeNow - frameLastEnd) + AuNumericLimits<double>::epsilon()));
}
inline AuUInt32 GetBytesPerSecondNormalized(AuUInt32 timeNow)
{
AU_LOCK_GUARD(lock);
// If timeNow isn't at least that of one socket frame, then we just have to return some old data
if (frameZero) return GetLastBytesPerSecond();
// Cool we can extrapolate usage using a time weight at least that of one server frame
// Some useful variables...
auto frameAtPoint = GetBytesPerMS(timeNow);
auto timeElapsed = timeNow - frameLastEnd; // time elapsed since last packet dispatch finish. makes sense to use this is the packet delta of a high bandwidth stream
// Edge case: we aren't receiving much data. if we have more than 1 second of data, we should use the stream average
if (timeElapsed > 1000) return frameAtPoint / 1000; // from ms
// else assume constant usage will continue to trend for at least another second
// the actual extrapolation
auto weight = double(1000) / double(timeElapsed);
return double(frameAtPoint) * weight;
}
inline AuUInt32 GetLastBytesPerSecond()
{
AU_LOCK_GUARD(lock);
return double(lastBytesTransferred) / (double(frameLastEnd - frameLastStart) + AuNumericLimits<double>::epsilon()) * 1000.f;
}
inline void Reset()
{
bytesTransferred = 0;
frameStart = 0;
frameLastEnd = 0;
frameLastStart = 0;
frameZero = true;
lastBytesTransferred = 0;
}
inline void Add(AuUInt32 timeNow, AuUInt32 bytes)
{
AU_LOCK_GUARD(lock);
auto nextTick = frameLastEnd + 1000;
if (nextTick < timeNow)
{
frameLastEnd = timeNow;
frameLastStart = AuExchange(frameStart, timeNow);
lastBytesTransferred = AuExchange(bytesTransferred, bytes);
frameZero = true;
}
else
{
frameZero = false;
bytesTransferred += bytes;
}
}
AuThreadPrimitives::SpinLock lock;
AuUInt32 frameStart {};
AuUInt32 bytesTransferred {};
AuUInt32 frameLastStart {};
AuUInt32 frameLastEnd {};
AuUInt32 lastBytesTransferred {};
bool frameZero {true};
};
}

View File

@ -1,36 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: SocketStatChannel.hpp
Date: 2021-10-31
Author: Reece
***/
#pragma once
#include "SocketStatAverageBps.hpp"
namespace Aurora::IO::Net
{
struct SocketStatChannel
{
SocketStatAverageBps bandwidth;
AuUInt64 total;
// Interpolated bytes per second, may be less than expected (returning frame -1)
inline AuUInt32 GetAverageBytesPerSecond()
{
return bandwidth.GetLastBytesPerSecond();
}
inline AuUInt32 GetBytesPerSecond()
{
return bandwidth.GetBytesPerSecondNormalized(Time::CurrentClockMS());
}
inline void Add(AuUInt32 bytes)
{
total += bytes;
bandwidth.Add(Time::CurrentClockMS(), bytes);
}
};
}

View File

@ -1,19 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: WorkPoolGroup.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Net.hpp"
#include "WorkPoolGroup.hpp"
namespace Aurora::IO::Net
{
WorkPoolGroup::WorkPoolGroup()
{
asyncWorkGroup = AuAsync::kThreadIdAny;
asyncWorkPoolOffsetOrAny = AuAsync::kThreadIdAny;
}
}

View File

@ -1,13 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: WorkPoolGroup.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
}

View File

@ -1,19 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: WorkRange.cpp
Date: 2022-2-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Net.hpp"
#include "WorkRange.hpp"
namespace Aurora::IO::Net
{
WorkRange::WorkRange()
{
workerOffsetOrAny = AuAsync::kThreadIdAny;
workerCountOrAny = AuAsync::kThreadIdAny;
}
}

View File

@ -1,13 +0,0 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: WorkRange.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
namespace Aurora::IO::Net
{
}