[+] AuProtocol: PrependInterceptor[Ex]/AppendInterceptor[Ex] over now removed AddInterceptor[Ex]

(prepend makes sense for outbound stacks, where you might register the compression/crypto stages first, then return an object to the caller who may wish to prepend the input processors. http might need it.)
This commit is contained in:
Reece Wilson 2022-09-04 01:16:49 +01:00
parent af03c5cbf3
commit 2a3bd735ac
4 changed files with 90 additions and 17 deletions

View File

@ -17,15 +17,31 @@ namespace Aurora::IO::Protocol
* @param uOutputBufferSize When 0, a hopefully not stupid default is used.
* @return
*/
virtual bool AddInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) = 0;
virtual bool AppendInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) = 0;
/**
* @brief
* @brief Inserts the interceptor at the bottom of the protocol stack
* @param pInterceptor
* @param uOutputBufferSize When 0, a hopefully not stupid default is used.
* @return
*/
virtual bool AddInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize) = 0;
virtual bool PrependInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) = 0;
/**
* @brief
* @param pInterceptorEx
* @param uOutputBufferSize When 0, a hopefully not stupid default is used.
* @return
*/
virtual bool AppendInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) = 0;
/**
* @brief Inserts the interceptor at the bottom of the protocol stack
* @param pInterceptorEx
* @param uOutputBufferSize When 0, a hopefully not stupid default is used.
* @return
*/
virtual bool PrependInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) = 0;
/**
* @brief

View File

@ -17,7 +17,32 @@ namespace Aurora::IO::Protocol
{
}
bool ProtocolStack::AddInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor,
bool ProtocolStack::AppendInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor,
AuUInt uOutputBufferSize)
{
return this->AddInterceptorWhere(false, pInterceptor, uOutputBufferSize);
}
bool ProtocolStack::AppendInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize)
{
return this->AddInterceptorWhereEx(false, pInterceptorEx, uOutputBufferSize);
}
bool ProtocolStack::PrependInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor,
AuUInt uOutputBufferSize)
{
return this->AddInterceptorWhere(true, pInterceptor, uOutputBufferSize);
}
bool ProtocolStack::PrependInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize)
{
return this->AddInterceptorWhereEx(true, pInterceptorEx, uOutputBufferSize);
}
bool ProtocolStack::AddInterceptorWhere(bool prepend,
const AuSPtr<IProtocolInterceptor> &pInterceptor,
AuUInt uOutputBufferSize)
{
if (this->bWrittenEnd)
@ -100,17 +125,31 @@ namespace Aurora::IO::Protocol
pNew->pParent = this;
pNew->pInterceptor = pInterceptor;
if (prepend)
{
if (this->pBottomPiece)
{
pNew->pNext = this->pBottomPiece;
}
this->pBottomPiece = pNew;
}
else
{
this->pTopPiece = pNew;
if (!this->pBottomPiece)
{
this->pBottomPiece = pNew;
}
}
return true;
}
bool ProtocolStack::AddInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize)
bool ProtocolStack::AddInterceptorWhereEx(bool prepend,
const AuSPtr<IProtocolInterceptorEx> &pInterceptor,
AuUInt uOutputBufferSize)
{
if (this->bWrittenEnd)
{
@ -197,12 +236,24 @@ namespace Aurora::IO::Protocol
pNew->pInterceptorEx = pInterceptor;
pNew->pParent = this;
if (prepend)
{
if (this->pBottomPiece)
{
pNew->pNext = this->pBottomPiece;
}
this->pBottomPiece = pNew;
}
else
{
this->pTopPiece = pNew;
if (!this->pBottomPiece)
{
this->pBottomPiece = pNew;
}
}
return true;
}

View File

@ -18,12 +18,18 @@ namespace Aurora::IO::Protocol
void DoTick() override;
bool DoTick(const AuSPtr<AuByteBuffer> &read, const AuSPtr<ProtocolPiece> &pPiece);
bool AddInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) override;
bool AddInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize) override;
bool AppendInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) override;
bool AppendInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize) override;
bool PrependInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) override;
bool PrependInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize) override;
bool AddEndInterceptor(const AuSPtr<IProtocolInterceptorEx> &pInterceptor) override;
void Destroy() override;
bool AddInterceptorWhere(bool prepend, const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize);
bool AddInterceptorWhereEx(bool prepend, const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize);
AuSPtr<IStreamWriter> AsStreamWriter() override;
AuSPtr<Memory::ByteBuffer> AsWritableByteBuffer() override;

View File

@ -144,13 +144,13 @@ namespace Aurora::IO::TLS
return false;
}
if (!this->pSendStack_->AddInterceptorEx(this->GetSendInterceptor(), this->meta_.uOutPageSize))
if (!this->pSendStack_->AppendInterceptorEx(this->GetSendInterceptor(), this->meta_.uOutPageSize))
{
SysPushErrorNet("Couldn't add TLS interceptor");
return false;
}
if (!this->pRecvStack_->AddInterceptorEx(this->GetRecvInterceptor(), this->meta_.uOutPageSize))
if (!this->pRecvStack_->AppendInterceptorEx(this->GetRecvInterceptor(), this->meta_.uOutPageSize))
{
SysPushErrorNet("Couldn't add TLS interceptor");
return false;