Reece Wilson
67905a4192
============================================================================= Network ]==================================================================== ============================================================================= [+] Added (very) early Aurora::IO::Net implementation [+] AuNet::EHostnameType [+] AuNet::EIPProtocol [+] AuNet::ENetworkError [+] AuNet::ETransportProtocol [+] AuNet::INetInterface [+] AuNet::INetSrvDatagram [+] AuNet::INetSrvResolve [+] AuNet::INetSrvSockets [+] AuNet::INetSrvWorkers [+] AuNet::INetWorker [+] AuNet::IPAddress [+] AuNet::IResolver [+] AuNet::ISocket [+] AuNet::IResolver [+] AuNet::ISocketBase [+] AuNet::ISocketChannel [+] AuNet::ISocketDriver [+] AuNet::ISocketDriverFactory [+] AuNet::ISocketServer [+] AuNet::ISocketServerDriver [+] AuNet::NetEndpoint [+] AuNet::NetError [+] AuNet::NetHostname (+implementation) ============================================================================= Protocol ]=================================================================== ============================================================================= [+] IProtocolInterceptor [+] IProtocolInterceptorEx [+] IProtocolStack (+implementation) ============================================================================= TLS ]======================================================================== ============================================================================= [+] ITLSContext [+] TLSProtocolRecv [+] TLSProtocolSend (+implementation) ============================================================================= IO Bug Fixes ]=============================================================== ============================================================================= [*] IOProcessor::SubmitIOWorkItem should signal the CvEvent, forcing at least once future tick (wont optimize with if in tick & not yet dispatched work items) [*] Split IOPipeWork in into IOPipeProcessor header [+] IOPipeWork::GetBuffer (internal reallocation) [*] Harden against IAsyncTransactions without a loop source [*] Missing null `if (processor->listener)` in IOProcessor [*] Solved some soft-lock conditions under Linux's LoopQueue (added deferred commits) [*] Quick hack: IOProcessor::HasItems() should OR the early can-tick check function. ============================================================================= Other ]====================================================================== ============================================================================= [+] Linux: LSSignalCatcher [+] `static void AuResetMember(Aurora::Memory::ByteBuffer &ref)` for AuROXTL [*] Attempt to enforce a normalization and don't overwrite-readptr-under-istreamwriters policy in ByteBuffer_ReadWrite (circular buffers) [*] Bad ECC ctors ============================================================================= Known issues ]=============================================================== ============================================================================= > Linux net is nowhere near done > UDP socket emulation layer isn't implemented > Ciphersuite API is a stub > Private key API is a stub > ...therefore no TLS servers > Missing thread safety precautions under net > Net implementation is still beri early
183 lines
4.4 KiB
C++
183 lines
4.4 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuNetResolver.NT.cpp
|
|
Date: 2022-8-17
|
|
Author: Reece
|
|
***/
|
|
#include "Networking.hpp"
|
|
#include "AuNetResolver.NT.hpp"
|
|
#include "AuNetEndpoint.hpp"
|
|
|
|
namespace Aurora::IO::Net
|
|
{
|
|
NetResolver::NetResolver(const AuSPtr<INetWorker> &pWorker) :
|
|
pWorker_(pWorker)
|
|
{
|
|
|
|
}
|
|
|
|
NetResolver::NetResolver(const AuSPtr<INetWorker> &pWorker,
|
|
const AuSPtr<AuAsync::PromiseCallback<AuList<IPAddress>, NetError>> &pCompletion) :
|
|
pCompletion_(pCompletion),
|
|
pWorker_(pWorker)
|
|
{
|
|
|
|
}
|
|
|
|
NetResolver::~NetResolver()
|
|
{
|
|
}
|
|
|
|
bool NetResolver::Start()
|
|
{
|
|
ADDRINFOEXW infoEx { 0 };
|
|
int iInfoEx { 0 };
|
|
|
|
if (this->bA && !this->bAAAA)
|
|
{
|
|
infoEx.ai_family = AF_INET;
|
|
}
|
|
else if (this->bAAAA)
|
|
{
|
|
infoEx.ai_family = AF_INET6;
|
|
//infoEx.ai_flags = AI_V4MAPPED; // beats returning nothing...
|
|
}
|
|
else if (this->bA && this->bAAAA)
|
|
{
|
|
infoEx.ai_family = AF_UNSPEC;
|
|
//infoEx.ai_flags = AI_ALL;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
HANDLE hHandle = NULL;
|
|
int iRet = GetAddrInfoExW(AuLocale::ConvertFromUTF8(this->hostname).data(),
|
|
nullptr,
|
|
NS_DNS,
|
|
nullptr,
|
|
&infoEx,
|
|
&this->resultHandle_,
|
|
nullptr,
|
|
&this->overlapped,
|
|
NULL,
|
|
&hHandle);
|
|
this->hName_ = hHandle;
|
|
return this->FinishOperationEx(AuSharedFromThis(),
|
|
this->pWorker_,
|
|
iRet == 0,
|
|
iRet);
|
|
}
|
|
|
|
void NetResolver::SetCompletion(const AuSPtr<AuAsync::PromiseCallback<AuList<IPAddress>, NetError>> &callback)
|
|
{
|
|
this->pCompletion_ = callback;
|
|
}
|
|
|
|
void NetResolver::OnOverlappedComplete()
|
|
{
|
|
if (AuExchange(this->bHasCompleted_, true))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (this->Unpack())
|
|
{
|
|
if (this->pCompletion_)
|
|
{
|
|
try
|
|
{
|
|
this->pCompletion_->OnSuccess((void *)&this->processedIps_);
|
|
}
|
|
catch (...)
|
|
{
|
|
SysPushErrorCatch();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (this->pCompletion_)
|
|
{
|
|
try
|
|
{
|
|
this->error_ = ENetworkError::eAsyncError;
|
|
this->pCompletion_->OnFailure((void *)&this->error_);
|
|
}
|
|
catch (...)
|
|
{
|
|
SysPushErrorCatch();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void NetResolver::OnOverlappedFailure(const NetError &error)
|
|
{
|
|
this->error_ = error;
|
|
if (this->pCompletion_)
|
|
{
|
|
try
|
|
{
|
|
this->pCompletion_->OnFailure((void *)&this->error_);
|
|
}
|
|
catch (...)
|
|
{
|
|
SysPushErrorCatch();
|
|
}
|
|
}
|
|
this->bHasCompleted_ = true;
|
|
}
|
|
|
|
bool NetResolver::HasFinished()
|
|
{
|
|
return this->bHasCompleted_;
|
|
}
|
|
|
|
void NetResolver::Cancel()
|
|
{
|
|
auto hHandle = AuExchange(this->hName_, (HANDLE)NULL);
|
|
if (hHandle != NULL)
|
|
{
|
|
::GetAddrInfoExCancel(&hHandle);
|
|
}
|
|
|
|
while (!this->HasComplete())
|
|
{
|
|
IOYield();
|
|
}
|
|
}
|
|
|
|
const NetError &NetResolver::GetError()
|
|
{
|
|
return this->error_;
|
|
}
|
|
|
|
bool NetResolver::Unpack()
|
|
{
|
|
auto pCurrent = this->resultHandle_;
|
|
|
|
while (pCurrent)
|
|
{
|
|
NetEndpoint endpoint;
|
|
AuMemcpy(endpoint.hint, pCurrent->ai_addr, pCurrent->ai_addrlen);
|
|
DeoptimizeEndpoint(endpoint);
|
|
|
|
if (!AuTryInsert(this->processedIps_, endpoint.ip))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
pCurrent = pCurrent->ai_next;
|
|
}
|
|
|
|
if (this->resultHandle_)
|
|
{
|
|
::FreeAddrInfoExW(this->resultHandle_);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
} |