[+] (dummy!) ISocketServerLimits.hpp
[+] (dummy!) ISocketChannelLimits.hpp [+] ISocketChannel::GetChannelLimits [+] ISocketBase::GetLockedWorkerThread [+] ISocket::GetSocketServer
This commit is contained in:
parent
216aa01717
commit
dcf94a8b23
@ -11,6 +11,7 @@ namespace Aurora::IO::Net
|
||||
{
|
||||
struct ISocketChannel;
|
||||
struct ISocketDriver;
|
||||
struct ISocketServer;
|
||||
|
||||
struct ISocket : virtual ISocketBase
|
||||
{
|
||||
@ -19,5 +20,7 @@ namespace Aurora::IO::Net
|
||||
virtual const NetEndpoint &GetRemoteEndpoint() = 0;
|
||||
|
||||
virtual AuSPtr<ISocketDriver> GetUserDriver() = 0;
|
||||
|
||||
virtual AuSPtr<ISocketServer> GetSocketServer() = 0;
|
||||
};
|
||||
}
|
@ -9,6 +9,8 @@
|
||||
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
struct INetWorker;
|
||||
|
||||
struct ISocketBase
|
||||
{
|
||||
virtual const NetError &GetError() = 0;
|
||||
@ -19,6 +21,8 @@ namespace Aurora::IO::Net
|
||||
|
||||
virtual AuUInt ToPlatformHandle() = 0;
|
||||
|
||||
virtual AuSPtr<INetWorker> GetLockedWorkerThread() = 0;
|
||||
|
||||
AURT_ADD_USR_DATA;
|
||||
};
|
||||
}
|
@ -15,6 +15,7 @@ namespace Aurora::IO::Protocol
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
struct ISocket;
|
||||
struct ISocketChannelLimits;
|
||||
struct ISocketChannelEventListener;
|
||||
|
||||
struct ISocketChannel : Protocol::IProtocolBaseReader, Protocol::IProtocolBaseWriter
|
||||
@ -231,6 +232,8 @@ namespace Aurora::IO::Net
|
||||
*/
|
||||
virtual void RemoveEventListener(const AuSPtr<ISocketChannelEventListener> &pListener) = 0;
|
||||
|
||||
virtual AuSPtr<ISocketChannelLimits> GetChannelLimits() = 0;
|
||||
|
||||
AURT_ADD_USR_DATA;
|
||||
};
|
||||
}
|
26
Include/Aurora/IO/Net/ISocketChannelLimits.hpp
Normal file
26
Include/Aurora/IO/Net/ISocketChannelLimits.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
/***
|
||||
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: ISocketChannelLimits.hpp
|
||||
Date: 2023-11-29
|
||||
Author: Reece
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
struct ISocketChannelLimits
|
||||
{
|
||||
virtual AuOptional<AuUInt32> GetBeforeDDoSDCAverageThroughputLimit() = 0;
|
||||
virtual AuOptional<AuUInt32> SetBeforeDDoSDCAverageThroughputLimit(AuOptional<AuUInt32> uNextValue) = 0;
|
||||
|
||||
virtual AuOptional<AuUInt32> GetBeforeDDoSDCFrameTimeMS() = 0;
|
||||
virtual AuOptional<AuUInt32> SetBeforeDDoSDCFrameTimeMS(AuOptional<AuUInt32> uNextValue) = 0;
|
||||
|
||||
virtual AuOptional<AuUInt32> GetBeforeDDoSTickFrameLimitCount() = 0;
|
||||
virtual AuOptional<AuUInt32> SetBeforeDDoSTickFrameLimitCount(AuOptional<AuUInt32> uNextValue) = 0;
|
||||
|
||||
virtual AuOptional<AuUInt32> GetBeforeDDoSTickFrameTimeMS() = 0;
|
||||
virtual AuOptional<AuUInt32> SetBeforeDDoSTickFrameTimeMS(AuOptional<AuUInt32> uNextValue) = 0;
|
||||
};
|
||||
}
|
@ -11,6 +11,8 @@ namespace Aurora::IO::Net
|
||||
{
|
||||
struct ISocketServer : virtual ISocketBase
|
||||
{
|
||||
virtual AuList<AuSPtr<ISocket>> GetChildren() = 0;
|
||||
virtual AuSPtr<ISocketServerLimits> GetLimits() = 0;
|
||||
virtual AuSPtr<ISocketServerDriver> GetServerDriver() = 0;
|
||||
};
|
||||
}
|
44
Include/Aurora/IO/Net/ISocketServerLimits.hpp
Normal file
44
Include/Aurora/IO/Net/ISocketServerLimits.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
/***
|
||||
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: ISocketServerLimits.hpp
|
||||
Date: 2023-11-29
|
||||
Author: Reece
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
struct ISocketServerLimits
|
||||
{
|
||||
virtual AuOptional<AuUInt32> GetMaxConnectionsPerIp() = 0;
|
||||
virtual AuOptional<AuUInt32> SetMaxConnectionsPerIp(AuOptional<AuUInt32> optNextValue) = 0;
|
||||
|
||||
virtual AuOptional<AuUInt32> GetMaxConnections() = 0;
|
||||
virtual AuOptional<AuUInt32> SetMaxConnections(AuOptional<AuUInt32> optNextValue) = 0;
|
||||
|
||||
virtual AuList<IPAddress> GetWhitelist() = 0;
|
||||
virtual void SetWhitelist(AuList<IPAddress> whitelist) = 0;
|
||||
|
||||
virtual AuList<IPAddress> GetBlacklist() = 0;
|
||||
virtual void SetBlacklist(AuList<IPAddress> blacklist) = 0;
|
||||
|
||||
virtual AuOptional<AuUInt32> GetBeforeDDoSDCAverageThroughputLimit() = 0;
|
||||
virtual AuOptional<AuUInt32> SetBeforeDDoSDCAverageThroughputLimit(AuOptional<AuUInt32> optNextValue) = 0;
|
||||
|
||||
virtual AuOptional<AuUInt32> GetBeforeDDoSDCFrameTimeMS() = 0;
|
||||
virtual AuOptional<AuUInt32> SetBeforeDDoSDCFrameTimeMS(AuOptional<AuUInt32> optNextValue) = 0;
|
||||
|
||||
virtual AuOptional<AuUInt32> GetBeforeDDoSTickFrameLimitCount() = 0;
|
||||
virtual AuOptional<AuUInt32> SetBeforeDDoSTickFrameLimitCount(AuOptional<AuUInt32> optNextValue) = 0;
|
||||
|
||||
virtual AuOptional<AuUInt32> GetBeforeDDoSTickFrameTimeMS() = 0;
|
||||
virtual AuOptional<AuUInt32> SetBeforeDDoSTickFrameTimeMS(AuOptional<AuUInt32> optNextValue) = 0;
|
||||
|
||||
virtual AuOptional<bool> GetAutoBanOnDDoSDetectA() = 0;
|
||||
virtual AuOptional<bool> SetAutoBanOnDDoSDetectA(AuOptional<bool> optNextValue) = 0;
|
||||
|
||||
virtual AuOptional<AuUInt32> GetAutoBanTimeSecs() = 0;
|
||||
virtual AuOptional<AuUInt32> SetAutoBanTimeSecs(AuOptional<AuUInt32> optNextValue) = 0;
|
||||
};
|
||||
}
|
@ -28,6 +28,8 @@
|
||||
#include "ISocketChannel.hpp"
|
||||
#include "ISocketDriverFactory.hpp"
|
||||
#include "ISocketServerDriver.hpp"
|
||||
#include "ISocketServerLimits.hpp"
|
||||
#include "ISocketChannelLimits.hpp"
|
||||
#include "ISocketServer.hpp"
|
||||
|
||||
#include "IDatagramDriver.hpp"
|
||||
|
52
Source/IO/Net/AuNetChannelLimits.cpp
Normal file
52
Source/IO/Net/AuNetChannelLimits.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/***
|
||||
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: AuNetChannelLimits.cpp
|
||||
Date: 2023-11-29
|
||||
Author: Reece
|
||||
***/
|
||||
#include "Networking.hpp"
|
||||
#include "AuNetChannelLimits.hpp"
|
||||
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
AuOptional<AuUInt32> NetChannelLimits::GetBeforeDDoSDCAverageThroughputLimit()
|
||||
{
|
||||
return this->optBeforeDDoSDCAverageThroughputLimit;
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetChannelLimits::SetBeforeDDoSDCAverageThroughputLimit(AuOptional<AuUInt32> uNextValue)
|
||||
{
|
||||
return AuExchange(this->optBeforeDDoSDCAverageThroughputLimit, uNextValue);
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetChannelLimits::GetBeforeDDoSDCFrameTimeMS()
|
||||
{
|
||||
return this->optBeforeDDoSDCFrameTimeMS;
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetChannelLimits::SetBeforeDDoSDCFrameTimeMS(AuOptional<AuUInt32> uNextValue)
|
||||
{
|
||||
return AuExchange(this->optBeforeDDoSDCFrameTimeMS, uNextValue);
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetChannelLimits::GetBeforeDDoSTickFrameLimitCount()
|
||||
{
|
||||
return this->optBeforeDDoSTickFrameLimitCount;
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetChannelLimits::SetBeforeDDoSTickFrameLimitCount(AuOptional<AuUInt32> uNextValue)
|
||||
{
|
||||
return AuExchange(this->optBeforeDDoSTickFrameLimitCount, uNextValue);
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetChannelLimits::GetBeforeDDoSTickFrameTimeMS()
|
||||
{
|
||||
return this->optBeforeDDoSTickFrameTimeMS;
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetChannelLimits::SetBeforeDDoSTickFrameTimeMS(AuOptional<AuUInt32> uNextValue)
|
||||
{
|
||||
return AuExchange(this->optBeforeDDoSTickFrameTimeMS, uNextValue);
|
||||
}
|
||||
}
|
31
Source/IO/Net/AuNetChannelLimits.hpp
Normal file
31
Source/IO/Net/AuNetChannelLimits.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
/***
|
||||
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: AuNetChannelLimits.hpp
|
||||
Date: 2023-11-29
|
||||
Author: Reece
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
struct NetChannelLimits : ISocketChannelLimits
|
||||
{
|
||||
AuOptional<AuUInt32> GetBeforeDDoSDCAverageThroughputLimit() override;
|
||||
AuOptional<AuUInt32> SetBeforeDDoSDCAverageThroughputLimit(AuOptional<AuUInt32> uNextValue) override;
|
||||
|
||||
AuOptional<AuUInt32> GetBeforeDDoSDCFrameTimeMS() override;
|
||||
AuOptional<AuUInt32> SetBeforeDDoSDCFrameTimeMS(AuOptional<AuUInt32> uNextValue) override;
|
||||
|
||||
AuOptional<AuUInt32> GetBeforeDDoSTickFrameLimitCount() override;
|
||||
AuOptional<AuUInt32> SetBeforeDDoSTickFrameLimitCount(AuOptional<AuUInt32> uNextValue) override;
|
||||
|
||||
AuOptional<AuUInt32> GetBeforeDDoSTickFrameTimeMS() override;
|
||||
AuOptional<AuUInt32> SetBeforeDDoSTickFrameTimeMS(AuOptional<AuUInt32> uNextValue) override;
|
||||
|
||||
AuOptional<AuUInt32> optBeforeDDoSTickFrameTimeMS;
|
||||
AuOptional<AuUInt32> optBeforeDDoSTickFrameLimitCount;
|
||||
AuOptional<AuUInt32> optBeforeDDoSDCFrameTimeMS;
|
||||
AuOptional<AuUInt32> optBeforeDDoSDCAverageThroughputLimit;
|
||||
};
|
||||
}
|
@ -24,8 +24,10 @@ namespace Aurora::IO::Net
|
||||
Socket::Socket(struct NetInterface *pInterface,
|
||||
struct NetWorker *pWorker,
|
||||
const AuSPtr<ISocketDriver> &pSocketDriver,
|
||||
AuUInt osHandle) :
|
||||
SocketBase(pInterface, pWorker, pSocketDriver, osHandle)
|
||||
AuUInt osHandle,
|
||||
AuSPtr<ISocketServer> pParent,
|
||||
SocketServer *pParent2) :
|
||||
SocketBase(pInterface, pWorker, pSocketDriver, osHandle, pParent, pParent2)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ namespace Aurora::IO::Net
|
||||
Socket(struct NetInterface *pInterface,
|
||||
struct NetWorker *pWorker,
|
||||
const AuSPtr<ISocketDriver> &pSocketDriver,
|
||||
AuUInt osHandle);
|
||||
AuUInt osHandle,
|
||||
AuSPtr<ISocketServer> pParent = {},
|
||||
SocketServer *pParent2 = {});
|
||||
|
||||
Socket(struct NetInterface *pInterface,
|
||||
struct NetWorker *pWorker,
|
||||
|
@ -28,8 +28,9 @@ namespace Aurora::IO::Net
|
||||
Socket::Socket(struct NetInterface *pInterface,
|
||||
struct NetWorker *pWorker,
|
||||
const AuSPtr<ISocketDriver> &pSocketDriver,
|
||||
AuUInt osHandle) :
|
||||
SocketBase(pInterface, pWorker, pSocketDriver, osHandle)
|
||||
AuUInt osHandle,
|
||||
AuSPtr<ISocketServer> pParent) :
|
||||
SocketBase(pInterface, pWorker, pSocketDriver, osHandle, pParent)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ namespace Aurora::IO::Net
|
||||
Socket(struct NetInterface *pInterface,
|
||||
struct NetWorker *pWorker,
|
||||
const AuSPtr<ISocketDriver> &pSocketDriver,
|
||||
AuUInt osHandle);
|
||||
AuUInt osHandle,
|
||||
AuSPtr<ISocketServer> pParent = {},
|
||||
SocketServer *pParent2 = {});
|
||||
|
||||
Socket(struct NetInterface *pInterface,
|
||||
struct NetWorker *pWorker,
|
||||
|
@ -30,15 +30,18 @@ namespace Aurora::IO::Net
|
||||
}
|
||||
|
||||
SocketBase::SocketBase(struct NetInterface *pInterface,
|
||||
struct NetWorker *pWorker,
|
||||
const AuSPtr<ISocketDriver> &pSocketDriver,
|
||||
AuUInt osHandle) :
|
||||
struct NetWorker *pWorker,
|
||||
const AuSPtr<ISocketDriver> &pSocketDriver,
|
||||
AuUInt osHandle,
|
||||
AuSPtr<ISocketServer> pParent,
|
||||
SocketServer *pParent2) :
|
||||
connectOperation(this),
|
||||
socketChannel_(this),
|
||||
pInterface_(pInterface),
|
||||
pWorker_(pWorker),
|
||||
pSocketDriver_(pSocketDriver),
|
||||
osHandle_(osHandle)
|
||||
osHandle_(osHandle),
|
||||
wpParent2_(pParent2)
|
||||
{
|
||||
this->pWorker_->AddSocket(this);
|
||||
|
||||
@ -55,6 +58,10 @@ namespace Aurora::IO::Net
|
||||
this->osHandleOwner_->InitFromPairMove((int)this->osHandle_, (int)this->osHandle_);
|
||||
#endif
|
||||
|
||||
if (pParent)
|
||||
{
|
||||
pParent2->OnNotifyChildCreated(this);
|
||||
}
|
||||
}
|
||||
|
||||
SocketBase::SocketBase(struct NetInterface *pInterface,
|
||||
@ -262,6 +269,11 @@ namespace Aurora::IO::Net
|
||||
return this->pSocketDriver_;
|
||||
}
|
||||
|
||||
AuSPtr<INetWorker> SocketBase::GetLockedWorkerThread()
|
||||
{
|
||||
return this->pWorker_->SharedFromThis();
|
||||
}
|
||||
|
||||
const NetEndpoint &SocketBase::GetRemoteEndpoint()
|
||||
{
|
||||
return this->remoteEndpoint_;
|
||||
@ -272,6 +284,11 @@ namespace Aurora::IO::Net
|
||||
return this->localEndpoint_;
|
||||
}
|
||||
|
||||
AuSPtr<ISocketServer> SocketBase::GetSocketServer()
|
||||
{
|
||||
return AuTryLockMemoryType(this->wpParent_);
|
||||
}
|
||||
|
||||
void SocketBase::ConnectFinished()
|
||||
{
|
||||
this->UpdateLocalEndpoint();
|
||||
@ -523,6 +540,11 @@ namespace Aurora::IO::Net
|
||||
|
||||
void SocketBase::Destroy()
|
||||
{
|
||||
if (auto pParent = AuTryLockMemoryType(this->wpParent_))
|
||||
{
|
||||
this->wpParent2_->OnNotifyChildRemoved(this);
|
||||
}
|
||||
|
||||
this->SendFinalize();
|
||||
}
|
||||
|
||||
@ -626,7 +648,12 @@ namespace Aurora::IO::Net
|
||||
|
||||
this->pSocketDriver_.reset();
|
||||
}
|
||||
|
||||
|
||||
if (auto pParent = AuTryLockMemoryType(this->wpParent_))
|
||||
{
|
||||
this->wpParent2_->OnNotifyChildRemoved(this);
|
||||
}
|
||||
|
||||
auto pWriteTransaction = this->socketChannel_.outputChannel.ToWriteTransaction();
|
||||
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
|
@ -22,15 +22,18 @@ namespace Aurora::IO::Net
|
||||
struct SocketBase;
|
||||
struct SocketConnectOperation;
|
||||
struct SocketServerAcceptReadOperation;
|
||||
struct SocketServer;
|
||||
|
||||
struct SocketBase : virtual ISocket, AuEnableSharedFromThis<SocketBase>
|
||||
{
|
||||
friend struct SocketServerAcceptReadOperation;
|
||||
|
||||
SocketBase(struct NetInterface *pInterface,
|
||||
struct NetWorker *pWorker,
|
||||
const AuSPtr<ISocketDriver> &pSocketDriver,
|
||||
AuUInt osHandle);
|
||||
struct NetWorker *pWorker,
|
||||
const AuSPtr<ISocketDriver> &pSocketDriver,
|
||||
AuUInt osHandle,
|
||||
AuSPtr<ISocketServer> pParent,
|
||||
SocketServer *pParent2);
|
||||
|
||||
SocketBase(struct NetInterface *pInterface,
|
||||
struct NetWorker *pWorker,
|
||||
@ -59,10 +62,14 @@ namespace Aurora::IO::Net
|
||||
|
||||
AuSPtr<ISocketDriver> GetUserDriver() override;
|
||||
|
||||
AuSPtr<INetWorker> GetLockedWorkerThread();
|
||||
|
||||
const NetEndpoint &GetRemoteEndpoint() override;
|
||||
const NetEndpoint &GetLocalEndpoint() override;
|
||||
|
||||
const NetError &GetError() override;
|
||||
|
||||
AuSPtr<ISocketServer> GetSocketServer() override;
|
||||
|
||||
void ConnectFinished();
|
||||
void ConnectFailed(const NetError &error);
|
||||
@ -128,6 +135,8 @@ namespace Aurora::IO::Net
|
||||
|
||||
NetEndpoint remoteEndpoint_;
|
||||
NetEndpoint localEndpoint_;
|
||||
AuWPtr<ISocketServer> wpParent_ {};
|
||||
SocketServer *wpParent2_ {};
|
||||
|
||||
bool bForceFailConstruct_ {};
|
||||
|
||||
|
@ -349,6 +349,11 @@ namespace Aurora::IO::Net
|
||||
bool(this->inputChannel.IsValid());
|
||||
}
|
||||
|
||||
AuSPtr<ISocketChannelLimits> SocketChannel::GetChannelLimits()
|
||||
{
|
||||
return AuSPtr<ISocketChannelLimits>(this->pParent_->SharedFromThis(), &this->channelSecurity_);
|
||||
}
|
||||
|
||||
bool SocketChannel::SpecifyBufferSize(AuUInt uBytes,
|
||||
const AuSPtr<AuAsync::PromiseCallback<AuNullS, AuNullS>> &pCallbackOptional)
|
||||
{
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "AuNetSocketChannelInput.hpp"
|
||||
#include "AuNetSocketChannelOutput.hpp"
|
||||
#include "AuSocketStats.hpp"
|
||||
#include "AuNetChannelLimits.hpp"
|
||||
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
@ -81,6 +82,8 @@ namespace Aurora::IO::Net
|
||||
|
||||
void RemoveEventListener(const AuSPtr<ISocketChannelEventListener> &pListener) override;
|
||||
|
||||
AuSPtr<ISocketChannelLimits> GetChannelLimits() override;
|
||||
|
||||
SocketStats & GetSendStatsEx();
|
||||
SocketStats & GetRecvStatsEx();
|
||||
|
||||
@ -116,6 +119,7 @@ namespace Aurora::IO::Net
|
||||
AuSPtr<IO::IStreamReader> pCachedReader;
|
||||
AuSPtr<IO::IStreamWriter> pCachedWriter;
|
||||
|
||||
|
||||
AuThreadPrimitives::SpinLock spinLock;
|
||||
AuList<AuSPtr<ISocketChannelEventListener>> eventListeners;
|
||||
|
||||
@ -128,5 +132,6 @@ namespace Aurora::IO::Net
|
||||
SocketBase * pParent_;
|
||||
SocketStats sendStats_;
|
||||
SocketStats recvStats_;
|
||||
NetChannelLimits channelSecurity_;
|
||||
};
|
||||
}
|
@ -17,7 +17,7 @@ namespace Aurora::IO::Net
|
||||
const AuSPtr<ISocketServerDriver> &pDriver,
|
||||
const AuSPtr<ISocketDriverFactory> &pSocketDriverFactory,
|
||||
AuUInt32 uMaxConnections,
|
||||
AuUInt32 uDefaultInputStreamSize,
|
||||
AuUInt32 uDefaultInputStreamSize,
|
||||
bool bMultiThreaded) :
|
||||
SocketServer(pInterface,
|
||||
pWorker,
|
||||
@ -104,7 +104,7 @@ namespace Aurora::IO::Net
|
||||
|
||||
We need a sane number between the two. 512 seems reasonable
|
||||
*/
|
||||
if (::listen(this->osHandle_, 512) != 0)
|
||||
if (::listen(this->osHandle_, this->uBacklog) != 0)
|
||||
{
|
||||
NetError error;
|
||||
NetError_SetCurrent(error);
|
||||
|
@ -122,7 +122,7 @@ namespace Aurora::IO::Net
|
||||
|
||||
We need a sane number between the two. 512 seems reasonable
|
||||
*/
|
||||
if (::listen(this->osHandle_, 512) != 0)
|
||||
if (::listen(this->osHandle_, this->uBacklog) != 0)
|
||||
{
|
||||
NetError error;
|
||||
NetError_SetCurrent(error);
|
||||
|
@ -130,6 +130,47 @@ namespace Aurora::IO::Net
|
||||
return this->pFactory_;
|
||||
}
|
||||
|
||||
AuSPtr<ISocketServerLimits> SocketServer::GetLimits()
|
||||
{
|
||||
return AuSPtr<ISocketServerLimits>(this->SharedFromThis(), &this->serverLimits_);
|
||||
}
|
||||
|
||||
AuList<AuSPtr<ISocket>> SocketServer::GetChildren()
|
||||
{
|
||||
AuList<AuSPtr<ISocket>> ret;
|
||||
AU_LOCK_GUARD(this->childrenMutex);
|
||||
for (const auto &pChild : this->childrenSockets)
|
||||
{
|
||||
try
|
||||
{
|
||||
ret.push_back(pChild->SharedFromThis());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SocketServer::OnNotifyChildCreated(SocketBase *pSocket)
|
||||
{
|
||||
{
|
||||
AU_LOCK_GUARD(this->childrenMutex);
|
||||
this->childrenSockets.push_back(pSocket);
|
||||
}
|
||||
}
|
||||
|
||||
void SocketServer::OnNotifyChildRemoved(SocketBase *pSocket)
|
||||
{
|
||||
{
|
||||
AU_LOCK_GUARD(this->childrenMutex);
|
||||
AuTryRemove(this->childrenSockets, pSocket);
|
||||
}
|
||||
|
||||
this->serverLimits_.NotifyChildRemoved();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// ISocketDriver
|
||||
|
||||
|
@ -13,9 +13,12 @@
|
||||
#pragma warning(disable: 4250)
|
||||
#endif
|
||||
|
||||
#include "AuNetSocketServerLimits.hpp"
|
||||
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
struct SocketServer;
|
||||
struct SocketBase;
|
||||
|
||||
struct SocketServer : virtual Socket, virtual ISocketDriver, virtual ISocketServer
|
||||
{
|
||||
@ -33,6 +36,8 @@ namespace Aurora::IO::Net
|
||||
|
||||
AuSPtr<ISocketServerDriver> GetServerDriver() override;
|
||||
AuSPtr<ISocketDriverFactory> GetFactory();
|
||||
AuSPtr<ISocketServerLimits> GetLimits() override;
|
||||
AuList<AuSPtr<ISocket>> GetChildren() override;
|
||||
|
||||
virtual void FinishConstructAsync() override;
|
||||
|
||||
@ -51,6 +56,7 @@ namespace Aurora::IO::Net
|
||||
|
||||
const bool bMultiThreaded;
|
||||
const AuUInt32 uDefaultInputStreamSize;
|
||||
AuUInt32 uBacklog { 512 };
|
||||
protected:
|
||||
|
||||
// INTERFACE: base os socket
|
||||
@ -79,11 +85,19 @@ namespace Aurora::IO::Net
|
||||
|
||||
virtual void OnFinalize() override;
|
||||
|
||||
//
|
||||
void OnNotifyChildCreated(SocketBase *pSocket);
|
||||
void OnNotifyChildRemoved(SocketBase *pSocket);
|
||||
|
||||
private:
|
||||
friend struct SocketBase;
|
||||
|
||||
AuSPtr<ISocketServerDriver> pDriver_;
|
||||
AuUInt32 uMaxConnections_;
|
||||
AuSPtr<ISocketDriverFactory> pFactory_;
|
||||
|
||||
NetSocketServerLimits serverLimits_;
|
||||
AuMutex childrenMutex;
|
||||
AuList<SocketBase *> childrenSockets;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,9 @@ namespace Aurora::IO::Net
|
||||
nextSocketPtr = AuMakeShared<Socket>(this->pInterface_,
|
||||
pWorker,
|
||||
pNewDriver,
|
||||
(AuUInt)nextSocket);
|
||||
(AuUInt)nextSocket,
|
||||
AuSPtr<ISocketServer>(this->pParent_->SharedFromThis(), this->pParent_),
|
||||
this->pParent_);
|
||||
if (!bool(nextSocketPtr))
|
||||
{
|
||||
// TODO: schedule retry
|
||||
|
@ -97,7 +97,9 @@ namespace Aurora::IO::Net
|
||||
this->nextSocketPtr = AuMakeShared<Socket>(this->pInterface_,
|
||||
pWorker,
|
||||
pNewDriver,
|
||||
(AuUInt)this->nextSocket);
|
||||
(AuUInt)this->nextSocket,
|
||||
AuSPtr<ISocketServer>(this->pParent_->SharedFromThis(), this->pParent_),
|
||||
this->pParent_);
|
||||
if (!bool(this->nextSocketPtr))
|
||||
{
|
||||
// TODO: schedule retry
|
||||
|
115
Source/IO/Net/AuNetSocketServerLimits.cpp
Normal file
115
Source/IO/Net/AuNetSocketServerLimits.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
/***
|
||||
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: AuNetSocketServerLimits.cpp
|
||||
Date: 2023-11-29
|
||||
Author: Reece
|
||||
***/
|
||||
#include "Networking.hpp"
|
||||
#include "AuNetSocketServerLimits.hpp"
|
||||
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
void NetSocketServerLimits::NotifyChildRemoved()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::GetMaxConnectionsPerIp()
|
||||
{
|
||||
return this->optMaxConnectionsPerIp;
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::SetMaxConnectionsPerIp(AuOptional<AuUInt32> optNextValue)
|
||||
{
|
||||
return AuExchange(this->optMaxConnectionsPerIp, optNextValue);
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::GetMaxConnections()
|
||||
{
|
||||
return this->optMaxConnections;
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::SetMaxConnections(AuOptional<AuUInt32> optNextValue)
|
||||
{
|
||||
return AuExchange(this->optMaxConnections, optNextValue);
|
||||
}
|
||||
|
||||
AuList<IPAddress> NetSocketServerLimits::GetWhitelist()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void NetSocketServerLimits::SetWhitelist(AuList<IPAddress> whitelist)
|
||||
{ }
|
||||
|
||||
AuList<IPAddress> NetSocketServerLimits::GetBlacklist()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void NetSocketServerLimits::SetBlacklist(AuList<IPAddress> blacklist)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::GetBeforeDDoSDCAverageThroughputLimit()
|
||||
{
|
||||
return this->optBeforeDDoSDCAverageThroughputLimit;
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::SetBeforeDDoSDCAverageThroughputLimit(AuOptional<AuUInt32> optNextValue)
|
||||
{
|
||||
return AuExchange(this->optBeforeDDoSDCAverageThroughputLimit, optNextValue);
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::GetBeforeDDoSDCFrameTimeMS()
|
||||
{
|
||||
return this->optBeforeDDoSDCFrameTimeMS;
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::SetBeforeDDoSDCFrameTimeMS(AuOptional<AuUInt32> optNextValue)
|
||||
{
|
||||
return AuExchange(this->optBeforeDDoSDCFrameTimeMS, optNextValue);
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::GetBeforeDDoSTickFrameLimitCount()
|
||||
{
|
||||
return this->optBeforeDDoSTickFrameLimitCount;
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::SetBeforeDDoSTickFrameLimitCount(AuOptional<AuUInt32> optNextValue)
|
||||
{
|
||||
return AuExchange(this->optBeforeDDoSTickFrameLimitCount, optNextValue);
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::GetBeforeDDoSTickFrameTimeMS()
|
||||
{
|
||||
return this->optBeforeDDoSTickFrameTimeMS;
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::SetBeforeDDoSTickFrameTimeMS(AuOptional<AuUInt32> optNextValue)
|
||||
{
|
||||
return AuExchange(this->optBeforeDDoSTickFrameTimeMS, optNextValue);
|
||||
}
|
||||
|
||||
AuOptional<bool> NetSocketServerLimits::GetAutoBanOnDDoSDetectA()
|
||||
{
|
||||
return this->optAutoBanOnDDoSDetectA;
|
||||
}
|
||||
|
||||
AuOptional<bool> NetSocketServerLimits::SetAutoBanOnDDoSDetectA(AuOptional<bool> optNextValue)
|
||||
{
|
||||
return AuExchange(this->optAutoBanOnDDoSDetectA, optNextValue);
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::GetAutoBanTimeSecs()
|
||||
{
|
||||
return this->optAutoBanOnDDoSDetectA;
|
||||
}
|
||||
|
||||
AuOptional<AuUInt32> NetSocketServerLimits::SetAutoBanTimeSecs(AuOptional<AuUInt32> optNextValue)
|
||||
{
|
||||
return AuExchange(this->optAutoBanOnDDoSDetectA, optNextValue);
|
||||
}
|
||||
}
|
55
Source/IO/Net/AuNetSocketServerLimits.hpp
Normal file
55
Source/IO/Net/AuNetSocketServerLimits.hpp
Normal file
@ -0,0 +1,55 @@
|
||||
/***
|
||||
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: AuNetSocketServerLimits.hpp
|
||||
Date: 2023-11-29
|
||||
Author: Reece
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
namespace Aurora::IO::Net
|
||||
{
|
||||
struct NetSocketServerLimits : ISocketServerLimits
|
||||
{
|
||||
void NotifyChildRemoved();
|
||||
|
||||
AuOptional<AuUInt32> GetMaxConnectionsPerIp() override;
|
||||
AuOptional<AuUInt32> SetMaxConnectionsPerIp(AuOptional<AuUInt32> uNextValue) override;
|
||||
|
||||
AuOptional<AuUInt32> GetMaxConnections() override;
|
||||
AuOptional<AuUInt32> SetMaxConnections(AuOptional<AuUInt32> uNextValue) override;
|
||||
|
||||
AuList<IPAddress> GetWhitelist() override;
|
||||
void SetWhitelist(AuList<IPAddress> whitelist) override;
|
||||
|
||||
AuList<IPAddress> GetBlacklist() override;
|
||||
void SetBlacklist(AuList<IPAddress> blacklist) override;
|
||||
|
||||
AuOptional<AuUInt32> GetBeforeDDoSDCAverageThroughputLimit() override;
|
||||
AuOptional<AuUInt32> SetBeforeDDoSDCAverageThroughputLimit(AuOptional<AuUInt32> uNextValue) override;
|
||||
|
||||
AuOptional<AuUInt32> GetBeforeDDoSDCFrameTimeMS() override;
|
||||
AuOptional<AuUInt32> SetBeforeDDoSDCFrameTimeMS(AuOptional<AuUInt32> uNextValue) override;
|
||||
|
||||
AuOptional<AuUInt32> GetBeforeDDoSTickFrameLimitCount() override;
|
||||
AuOptional<AuUInt32> SetBeforeDDoSTickFrameLimitCount(AuOptional<AuUInt32> uNextValue) override;
|
||||
|
||||
AuOptional<AuUInt32> GetBeforeDDoSTickFrameTimeMS() override;
|
||||
AuOptional<AuUInt32> SetBeforeDDoSTickFrameTimeMS(AuOptional<AuUInt32> uNextValue) override;
|
||||
|
||||
AuOptional<bool> GetAutoBanOnDDoSDetectA() override;
|
||||
AuOptional<bool> SetAutoBanOnDDoSDetectA(AuOptional<bool> optNextValue) override;
|
||||
|
||||
AuOptional<AuUInt32> GetAutoBanTimeSecs() override;
|
||||
AuOptional<AuUInt32> SetAutoBanTimeSecs(AuOptional<AuUInt32> optNextValue) override;
|
||||
|
||||
AuOptional<AuUInt32> optBeforeDDoSTickFrameTimeMS;
|
||||
AuOptional<AuUInt32> optBeforeDDoSTickFrameLimitCount;
|
||||
AuOptional<AuUInt32> optBeforeDDoSDCFrameTimeMS;
|
||||
AuOptional<AuUInt32> optBeforeDDoSDCAverageThroughputLimit;
|
||||
AuOptional<AuUInt32> optMaxConnectionsPerIp;
|
||||
AuOptional<AuUInt32> optMaxConnections;
|
||||
AuOptional<bool> optAutoBanOnDDoSDetectA;
|
||||
AuOptional<AuUInt32> optAutoBanTimeSecs;
|
||||
};
|
||||
}
|
@ -209,6 +209,11 @@ namespace Aurora::IO::Net
|
||||
return {};
|
||||
}
|
||||
|
||||
if (netBind.uMaxAcceptBacklog)
|
||||
{
|
||||
pSocket->uBacklog = netBind.uMaxAcceptBacklog;
|
||||
}
|
||||
|
||||
if (!pWorker->TryScheduleInternalTemplate<AuNullS>([=](const AuSPtr<AuAsync::PromiseCallback<AuNullS>> &info)
|
||||
{
|
||||
pSocket->FinishConstructAsync();
|
||||
|
@ -4,7 +4,9 @@ namespace Aurora::IO::Net
|
||||
{
|
||||
struct NetSrvWorkers;
|
||||
|
||||
struct NetWorker : INetWorker
|
||||
struct NetWorker :
|
||||
INetWorker,
|
||||
AuEnableSharedFromThis<NetWorker>
|
||||
{
|
||||
NetWorker(NetSrvWorkers *pParent,
|
||||
AuUInt8 workerIndex,
|
||||
|
@ -39,7 +39,12 @@ namespace Aurora::IO::Net
|
||||
|
||||
AuSPtr<ISocketChannel> NetDatagramEmulatorISocket::ToChannel()
|
||||
{
|
||||
return this->pParent->ToChannel();
|
||||
if (auto pParent = this->pParent)
|
||||
{
|
||||
return pParent->ToChannel();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
const NetEndpoint &NetDatagramEmulatorISocket::GetRemoteEndpoint()
|
||||
@ -49,6 +54,34 @@ namespace Aurora::IO::Net
|
||||
|
||||
AuSPtr<ISocketDriver> NetDatagramEmulatorISocket::GetUserDriver()
|
||||
{
|
||||
return this->pParent->GetUserDriver();
|
||||
if (auto pParent = this->pParent)
|
||||
{
|
||||
return pParent->GetUserDriver();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
AuSPtr<INetWorker> NetDatagramEmulatorISocket::GetLockedWorkerThread()
|
||||
{
|
||||
if (auto pParent = this->pParent)
|
||||
{
|
||||
return pParent->pWorker;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
AuSPtr<ISocketServer> NetDatagramEmulatorISocket::GetSocketServer()
|
||||
{
|
||||
if (auto pParent = this->pParent)
|
||||
{
|
||||
if (auto pParent2 = AuTryLockMemoryType(pParent->pParentServer))
|
||||
{
|
||||
return pParent2->ToSocketServer();
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
@ -32,5 +32,9 @@ namespace Aurora::IO::Net
|
||||
const NetEndpoint &GetRemoteEndpoint() override;
|
||||
|
||||
AuSPtr<ISocketDriver> GetUserDriver() override;
|
||||
|
||||
AuSPtr<ISocketServer> GetSocketServer() override;
|
||||
|
||||
AuSPtr<INetWorker> GetLockedWorkerThread() override;
|
||||
};
|
||||
}
|
@ -22,21 +22,70 @@ namespace Aurora::IO::Net
|
||||
|
||||
void NetDatagramEmulatorISocketServer::Shutdown(bool bNow)
|
||||
{
|
||||
this->pParent->Shutdown(bNow);
|
||||
if (auto pParent = this->pParent)
|
||||
{
|
||||
return pParent->Shutdown(bNow);
|
||||
}
|
||||
}
|
||||
|
||||
void NetDatagramEmulatorISocketServer::Destroy()
|
||||
{
|
||||
this->pParent->Destroy();
|
||||
if (auto pParent = this->pParent)
|
||||
{
|
||||
return pParent->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
AuUInt NetDatagramEmulatorISocketServer::ToPlatformHandle()
|
||||
{
|
||||
return this->pParent->ToPlatformHandle();
|
||||
if (auto pParent = this->pParent)
|
||||
{
|
||||
return pParent->ToPlatformHandle();
|
||||
}
|
||||
else
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
AuSPtr<ISocketServerDriver> NetDatagramEmulatorISocketServer::GetServerDriver()
|
||||
{
|
||||
return this->pParent->GetUserServerDriver();
|
||||
if (auto pParent = this->pParent)
|
||||
{
|
||||
return pParent->GetUserServerDriver();
|
||||
}
|
||||
else
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
AuSPtr<ISocketServerLimits> NetDatagramEmulatorISocketServer::GetLimits()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
AuList<AuSPtr<ISocket>> NetDatagramEmulatorISocketServer::GetChildren()
|
||||
{
|
||||
if (auto pParent = this->pParent)
|
||||
{
|
||||
return pParent->GetAllChildren();
|
||||
}
|
||||
else
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
AuSPtr<INetWorker> NetDatagramEmulatorISocketServer::GetLockedWorkerThread()
|
||||
{
|
||||
if (auto pParent = this->pParent)
|
||||
{
|
||||
return pParent->GetLockedWorkerThread();
|
||||
}
|
||||
else
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
@ -28,5 +28,8 @@ namespace Aurora::IO::Net
|
||||
AuUInt ToPlatformHandle() override;
|
||||
|
||||
AuSPtr<ISocketServerDriver> GetServerDriver() override;
|
||||
AuSPtr<ISocketServerLimits> GetLimits() override;
|
||||
AuList<AuSPtr<ISocket>> GetChildren() override;
|
||||
AuSPtr<INetWorker> GetLockedWorkerThread() override;
|
||||
};
|
||||
}
|
@ -204,6 +204,40 @@ namespace Aurora::IO::Net
|
||||
return ret;
|
||||
}
|
||||
|
||||
AuList<AuSPtr<ISocket>> NetDatagramSocketServer::GetAllChildren()
|
||||
{
|
||||
AuList<AuSPtr<ISocket>> ret;
|
||||
|
||||
{
|
||||
AU_LOCK_GUARD(this->mutex_);
|
||||
|
||||
for (const auto &[a, list] : this->sessions)
|
||||
{
|
||||
for (const auto &pItem : list)
|
||||
{
|
||||
if (pItem)
|
||||
{
|
||||
ret.push_back(pItem->ToSocket());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
AuSPtr<INetWorker> NetDatagramSocketServer::GetLockedWorkerThread()
|
||||
{
|
||||
if (auto pWorker = this->pWorker_)
|
||||
{
|
||||
return pWorker->SharedFromThis();
|
||||
}
|
||||
else
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
void NetDatagramSocketServer::Shutdown(bool bNow)
|
||||
{
|
||||
this->eviction.EvictAll();
|
||||
|
@ -38,12 +38,14 @@ namespace Aurora::IO::Net
|
||||
AuSPtr<NetDatagramSocketServerSession> GetSession(const NetEndpoint &endpoint);
|
||||
void Cleanup(const AuSPtr<NetDatagramSocketServerSession> &pSession);
|
||||
AuList<AuSPtr<NetDatagramSocketServerSession>> GetAllSessions();
|
||||
AuList<AuSPtr<ISocket>> GetAllChildren();
|
||||
|
||||
AuSPtr<NetDatagramSocketServerDriver> ToDriver();
|
||||
AuSPtr<ISocketServer> ToSocketServer();
|
||||
|
||||
const NetError &GetError() override;
|
||||
const NetEndpoint &GetLocalEndpoint() override;
|
||||
AuSPtr<INetWorker> GetLockedWorkerThread() override;
|
||||
|
||||
void OnError(const NetError &error);
|
||||
void OnFatalErrorReported(const NetError &error);
|
||||
|
@ -425,6 +425,11 @@ namespace Aurora::IO::Net
|
||||
return this->pBuffer->RemainingBytes();
|
||||
}
|
||||
|
||||
AuSPtr<ISocketChannelLimits> NetDatagramSocketServerChannel::GetChannelLimits()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
SocketStats &NetDatagramSocketServerChannel::GetSendStatsEx()
|
||||
{
|
||||
return this->sendStats_;
|
||||
|
@ -74,6 +74,8 @@ namespace Aurora::IO::Net
|
||||
|
||||
AuUInt GetNextFrameTargetLength() override;
|
||||
|
||||
AuSPtr<ISocketChannelLimits> GetChannelLimits() override;
|
||||
|
||||
SocketStats &GetSendStatsEx();
|
||||
SocketStats &GetRecvStatsEx();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user