[+] Early network tests (Linux wont pass)

This commit is contained in:
Reece Wilson 2022-08-29 17:34:57 +01:00
parent 7cffaafbcf
commit 1f5c51f2ab
11 changed files with 903 additions and 25 deletions

@ -1 +1 @@
Subproject commit 85c85d1a1beec3ff0a7d40b3524201b02f1e3d63
Subproject commit af438c8c172478c9f6f9c71e2ede533898def63b

@ -1 +1 @@
Subproject commit 7df6614839b2f1c02c34d928964d7d56e9d78dfd
Subproject commit 401cf0996267da87b7d4d98c46a7a15ceeb11013

View File

@ -3,5 +3,9 @@
"type": "generic",
"sourcePaths": "library/",
"include": "include/",
"depends": ["AuroraRuntime"]
"depends": ["AuroraRuntime"],
"defines": [
"MBEDTLS_SSL_EXPORT_KEYS",
"MBEDTLS_X509_CHECK_KEY_USAGE"
]
}

View File

@ -0,0 +1,309 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Main.cpp
Date: 2022-2-18
Author: Reece
***/
#include <AuroraRuntime.hpp>
#include <Aurora/IO/IOExperimental.hpp>
#include <Aurora/IO/Net/NetExperimental.hpp>
#include <gtest/gtest.h>
static const auto kHTTP11Address = "172.217.169.14"; // google.com
TEST(IPAddresses, Parse4)
{
AuNet::IPAddress one("1.2.3.4");
ASSERT_EQ(one.ip, AuNet::EIPProtocol::eIPProtocolV4);
ASSERT_EQ(one.v4[0], 1);
ASSERT_EQ(one.v4[1], 2);
ASSERT_EQ(one.v4[2], 3);
ASSERT_EQ(one.v4[3], 4);
ASSERT_EQ(one.ToString(), "1.2.3.4");
}
TEST(IPAddresses, Parse6)
{
AuNet::IPAddress one("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
ASSERT_EQ(one.ip, AuNet::EIPProtocol::eIPProtocolV6);
ASSERT_EQ(one.v6[0], 0x2001);
ASSERT_EQ(one.v6[1], 0x0db8);
ASSERT_EQ(one.v6[6], 0x0370);
ASSERT_EQ(one.v6[7], 0x7334);
ASSERT_EQ(one.ToString(), "2001:0db8:85a3:0000:0000:8a2e:0370:7334");
}
TEST(Endpoint, Build)
{
{
AuNet::NetEndpoint one(AuNet::ETransportProtocol::eProtocolTCP, "2001:0db8:85a3:0000:0000:8a2e:0370:7334", 21);
AuNet::NetEndpoint one2(AuNet::ETransportProtocol::eProtocolTCP, AuNet::IPAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), 32);
ASSERT_EQ(one.ip.ip, AuNet::EIPProtocol::eIPProtocolV6);
ASSERT_EQ(one.ip.v6[0], 0x2001);
ASSERT_EQ(one.ip.v6[1], 0x0db8);
ASSERT_EQ(one.ip.v6[6], 0x0370);
ASSERT_EQ(one.ip.v6[7], 0x7334);
ASSERT_EQ(one.ip.ToString(), "2001:0db8:85a3:0000:0000:8a2e:0370:7334");
ASSERT_EQ(one.uPort, 21);
ASSERT_EQ(one.transportProtocol, AuNet::ETransportProtocol::eProtocolTCP);
}
{
AuNet::NetEndpoint two("2001:0db8:85a3:0000:0000:8a2e:0370:7334", 21);
AuNet::NetEndpoint two2(AuNet::IPAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), 32);
}
{
AuNet::NetEndpoint three("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
AuNet::NetEndpoint three2(AuNet::IPAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334"));
}
}
TEST(Net, CanCreateProcessors)
{
auto pIoProcessor = AuIO::NewIOProcessorNoQueue(false);
ASSERT_TRUE(bool(pIoProcessor));
auto pNetProcessor = AuNet::NewNetworkInterface();
ASSERT_TRUE(bool(pNetProcessor));
}
TEST(Net, CanRegisterProcessors)
{
auto pIoProcessor = AuIO::NewIOProcessorNoQueue(false);
ASSERT_TRUE(bool(pIoProcessor));
auto pNetProcessor = AuNet::NewNetworkInterface();
ASSERT_TRUE(bool(pNetProcessor));
auto pNetWorker = pNetProcessor->GetWorkersService()->Attach(pIoProcessor);
ASSERT_TRUE(bool(pNetWorker));
}
struct DriverStat
{
AuUInt uPreestablish {};
AuUInt uEstablish {};
AuUInt uStreamUpdate{};
AuUInt uError {};
AuUInt uEnd {};
AuUInt uFinalize {};
};
struct TestSocketDriver : AuNet::ISocketDriver
{
AuSPtr<DriverStat> pStats;
AuSPtr<AuNet::ISocketDriver> pProxy;
bool OnPreestablish(const AuSPtr<AuNet::ISocket> &pInforming) override;
void OnEstablish() override;
void OnStreamUpdated() override;
void OnFatalErrorReported(const AuNet::NetError &error) override;
void OnEnd() override;
void OnFinalize() override;
};
bool TestSocketDriver::OnPreestablish(const AuSPtr<AuNet::ISocket> &pInforming)
{
this->pStats->uPreestablish++;
if (this->pProxy)
{
this->pProxy->OnPreestablish(pInforming);
}
return true;
}
void TestSocketDriver::OnEstablish()
{
this->pStats->uEstablish++;
if (this->pProxy)
{
this->pProxy->OnEstablish();
}
}
void TestSocketDriver::OnStreamUpdated()
{
this->pStats->uStreamUpdate++;
if (this->pProxy)
{
this->pProxy->OnStreamUpdated();
}
}
void TestSocketDriver::OnFatalErrorReported(const AuNet::NetError &error)
{
this->pStats->uError++;
if (this->pProxy)
{
this->pProxy->OnFatalErrorReported(error);
}
}
void TestSocketDriver::OnEnd()
{
this->pStats->uEnd++;
if (this->pProxy)
{
this->pProxy->OnEnd();
}
}
void TestSocketDriver::OnFinalize()
{
this->pStats->uFinalize++;
if (this->pProxy)
{
this->pProxy->OnFinalize();
}
}
static AuSPtr<TestSocketDriver> NewTestSocketDriver(const AuSPtr<DriverStat> &pStats)
{
auto pDriver = AuMakeShared<TestSocketDriver>();
SysAssert(pDriver);
pDriver->pStats = pStats;
return pDriver;
}
TEST(Net, ConnectGoogleIP2022)
{
auto pIoProcessor = AuIO::NewIOProcessorNoQueue(false);
ASSERT_TRUE(bool(pIoProcessor));
auto pNetProcessor = AuNet::NewNetworkInterface();
ASSERT_TRUE(bool(pNetProcessor));
auto pNetWorker = pNetProcessor->GetWorkersService()->Attach(pIoProcessor);
ASSERT_TRUE(bool(pNetWorker));
auto pStats = AuMakeShared<DriverStat>();
ASSERT_TRUE(bool(pStats));
auto pDriver = NewTestSocketDriver(pStats);
ASSERT_TRUE(bool(pDriver));
auto pRealDriver = AuMakeShared<AuNet::ISocketDriverFunctional>();
static AuSPtr<AuNet::ISocket> gDriverSocket;
pRealDriver->OnPreestablishFunctional = [&](const AuSPtr<AuNet::ISocket> &socket) -> bool
{
gDriverSocket = socket;
return true;
};
pRealDriver->OnEstablishFunctional = [&]()
{
auto pChannel = gDriverSocket->ToChannel();
pChannel->AsStreamWriter()->Write(AuMemoryViewRead("GET / HTTP/1.1\r\nConnection: close\r\n\r\n", 37));
};
pRealDriver->OnFatalErrorReportedFunctional = [&](const AuNet::NetError &error)
{
AuLogDbg("[3] On error: {}", NetErrorToExtendedString(error));
};
pRealDriver->OnStreamUpdatedFunctional = [&]()
{
auto pChannel = gDriverSocket->ToChannel();
auto pReader = pChannel->AsReadableByteBuffer();
AuString message;
message.resize(pReader->RemainingBytes());
pReader->Read(message.data(), message.size());
AuLogDbg("Stream updated: {}", message);
};
pDriver->pProxy = pRealDriver;
AuNet::NetSocketConnect nsConnect;
nsConnect.pDriver = pDriver;
nsConnect.endpoint = AuNet::NetEndpoint(AuNet::ETransportProtocol::eProtocolTCP, kHTTP11Address, 80);
auto pSocket = pNetProcessor->GetSocketService()->Connect(nsConnect);
ASSERT_TRUE(bool(pSocket));
while (pIoProcessor->HasItems())
{
pIoProcessor->RunTick();
}
}
TEST(Resolve, GoogleA)
{
auto pIoProcessor = AuIO::NewIOProcessorNoQueue(false);
ASSERT_TRUE(bool(pIoProcessor));
auto pNetProcessor = AuNet::NewNetworkInterface();
ASSERT_TRUE(bool(pNetProcessor));
auto pNetWorker = pNetProcessor->GetWorkersService()->Attach(pIoProcessor);
ASSERT_TRUE(bool(pNetWorker));
auto pResolveService = pNetProcessor->GetResolveService();
pResolveService->SimpleAResolve("www.google.com",
AuMakeShared<AuAsync::PromiseCallbackFunctional<AuList<AuNet::IPAddress>,
AuNet::NetError>>(
[](const AuSPtr<AuList<AuNet::IPAddress>> &ips)
{
AuLogDbg("Found IPV4: {}", ips->size());
const auto &ip2s = *ips;
for (const auto &ip : ip2s)
{
AuLogDbg("\t{}", ip.ToString());
}
}));
while (pIoProcessor->HasItems())
{
pIoProcessor->RunTick();
}
}
TEST(Resolve, GoogleAAAA)
{
auto pIoProcessor = AuIO::NewIOProcessorNoQueue(false);
ASSERT_TRUE(bool(pIoProcessor));
auto pNetProcessor = AuNet::NewNetworkInterface();
ASSERT_TRUE(bool(pNetProcessor));
auto pNetWorker = pNetProcessor->GetWorkersService()->Attach(pIoProcessor);
ASSERT_TRUE(bool(pNetWorker));
auto pResolveService = pNetProcessor->GetResolveService();
pResolveService->SimpleAAAAResolve("www.google.com",
AuMakeShared<AuAsync::PromiseCallbackFunctional<AuList<AuNet::IPAddress>,
AuNet::NetError>>(
[](const AuSPtr<AuList<AuNet::IPAddress>> &ips)
{
AuLogDbg("Found IPv6: {}", ips->size());
const auto &ip2s = *ips;
for (const auto &ip : ip2s)
{
AuLogDbg("\t{}", ip.ToString());
}
}));
while (pIoProcessor->HasItems())
{
pIoProcessor->RunTick();
}
}
void RunTests()
{
Aurora::RuntimeStartInfo info;
info.console.fio.enableLogging = false;
Aurora::RuntimeStart(info);
}

View File

@ -199,12 +199,12 @@ TEST(IO, ReadFileThroughPipeProcessor2MBReadsEQ)
// Setup the IOPipeRequest
AuIO::IOPipeRequestAIO aio;
aio.asyncTransaction = transaction;
aio.listener = listener;
aio.isStream = false;
aio.pAsyncTransaction = transaction;
aio.pListener = listener;
aio.bIsStream = false;
aio.output.type = AuIO::EPipeCallbackType::eTryHandleBufferedPart;
aio.pageLengthOrZero = 1024 * 1024 * 2; // read in 2MB chunks
aio.bufferLengthOrZero = 1024 * 1024 * 2; // read in 2MB chunks
aio.uPageLengthOrZero = 1024 * 1024 * 2; // read in 2MB chunks
aio.uBufferLengthOrZero = 1024 * 1024 * 2; // read in 2MB chunks
static auto localCount = 0;
localCount = 0;
@ -218,7 +218,7 @@ TEST(IO, ReadFileThroughPipeProcessor2MBReadsEQ)
view.Skip(view.RemainingBytes());
return true;
};
aio.output.handleBufferedStream.onData = onData;
aio.output.handleBufferedStream.pOnData = onData;
// Finally create the damn pipe
@ -311,9 +311,9 @@ TEST(IO, ReadFileThroughPipeProcessorDefaultConfigEQ)
// Setup the IOPipeRequest
AuIO::IOPipeRequestAIO aio;
aio.asyncTransaction = transaction;
aio.listener = listener;
aio.isStream = false;
aio.pAsyncTransaction = transaction;
aio.pListener = listener;
aio.bIsStream = false;
aio.output.type = AuIO::EPipeCallbackType::eTryHandleBufferedPart;
static auto localCount = 0;
@ -328,7 +328,7 @@ TEST(IO, ReadFileThroughPipeProcessorDefaultConfigEQ)
view.Skip(view.RemainingBytes());
return true;
};
aio.output.handleBufferedStream.onData = onData;
aio.output.handleBufferedStream.pOnData = onData;
// Finally create the damn pipe
@ -416,12 +416,12 @@ static void ReadFileThroughPipeProcessorCongested(int i)
// Setup the IOPipeRequest
AuIO::IOPipeRequestAIO aio;
aio.asyncTransaction = transaction;
aio.listener = listener;
aio.isStream = false;
aio.pAsyncTransaction = transaction;
aio.pListener = listener;
aio.bIsStream = false;
aio.output.type = AuIO::EPipeCallbackType::eTryHandleBufferedPart;
aio.pageLengthOrZero = 1024 * 1024 * 2; // read in 2MB chunks
aio.bufferLengthOrZero = 1024 * 1024 * 2 * i; // read in 2MB chunks
aio.uPageLengthOrZero = 1024 * 1024 * 2; // read in 2MB chunks
aio.uBufferLengthOrZero = 1024 * 1024 * 2 * i; // read in 2MB chunks
static auto localCount = 0;
localCount = 0;
@ -434,7 +434,7 @@ static void ReadFileThroughPipeProcessorCongested(int i)
view.Skip(view.RemainingBytes());
return true;
};
aio.output.handleBufferedStream.onData = onData;
aio.output.handleBufferedStream.pOnData = onData;
// Finally create the damn pipe
@ -454,7 +454,7 @@ static void ReadFileThroughPipeProcessorCongested(int i)
ioDrivenQueue->RunTick(); // also: TryTick and ManualTick
}
SysAssert(localCount == ((512 * 1024 * 40) / aio.pageLengthOrZero));
SysAssert(localCount == ((512 * 1024 * 40) / aio.uPageLengthOrZero));
}
}

View File

@ -38,9 +38,9 @@ static void doAcceptTick(const AuSPtr<AuIOIPC::IPCPipe> &pipe, const AuSPtr<AuI
// Setup the IOPipeRequest
AuIO::IOPipeRequestAIO aio;
aio.asyncTransaction = transaction;
aio.listener = listener;
aio.isStream = true;
aio.pAsyncTransaction = transaction;
aio.pListener = listener;
aio.bIsStream = true;
aio.output.type = AuIO::EPipeCallbackType::eTryHandleBufferedPart;
auto onData = AuMakeShared<AuIO::IIOBufferedStreamAvailableFunctional>();
@ -51,7 +51,7 @@ static void doAcceptTick(const AuSPtr<AuIOIPC::IPCPipe> &pipe, const AuSPtr<AuI
view.Skip(view.RemainingBytes());
return true;
};
aio.output.handleBufferedStream.onData = onData;
aio.output.handleBufferedStream.pOnData = onData;
auto filePipe = ioDrivenQueue->ToPipeProcessor()->NewAIOPipe(aio);
SysAssert(bool(filePipe));

View File

@ -0,0 +1,190 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Main.cpp
Date: 2022-2-18
Author: Reece
***/
#include <AuroraRuntime.hpp>
#include <Aurora/IO/IOExperimental.hpp>
#include <Aurora/IO/Net/NetExperimental.hpp>
#include <Aurora/IO/TLS/TLS.hpp>
#include <gtest/gtest.h>
static const auto kHTTP11Address = "204.79.197.200"; // bing.com
struct DriverStat
{
AuUInt uPreestablish {};
AuUInt uEstablish {};
AuUInt uStreamUpdate {};
AuUInt uError {};
AuUInt uEnd {};
AuUInt uFinalize {};
};
struct TestSocketDriver : AuNet::ISocketDriver
{
AuSPtr<DriverStat> pStats;
AuSPtr<AuNet::ISocketDriver> pProxy;
bool OnPreestablish(const AuSPtr<AuNet::ISocket> &pInforming) override;
void OnEstablish() override;
void OnStreamUpdated() override;
void OnFatalErrorReported(const AuNet::NetError &error) override;
void OnEnd() override;
void OnFinalize() override;
};
bool TestSocketDriver::OnPreestablish(const AuSPtr<AuNet::ISocket> &pInforming)
{
this->pStats->uPreestablish++;
if (this->pProxy)
{
this->pProxy->OnPreestablish(pInforming);
}
return true;
}
void TestSocketDriver::OnEstablish()
{
this->pStats->uEstablish++;
if (this->pProxy)
{
this->pProxy->OnEstablish();
}
}
void TestSocketDriver::OnStreamUpdated()
{
this->pStats->uStreamUpdate++;
if (this->pProxy)
{
this->pProxy->OnStreamUpdated();
}
}
void TestSocketDriver::OnFatalErrorReported(const AuNet::NetError &error)
{
this->pStats->uError++;
if (this->pProxy)
{
this->pProxy->OnFatalErrorReported(error);
}
}
void TestSocketDriver::OnEnd()
{
this->pStats->uEnd++;
if (this->pProxy)
{
this->pProxy->OnEnd();
}
}
void TestSocketDriver::OnFinalize()
{
this->pStats->uFinalize++;
if (this->pProxy)
{
this->pProxy->OnFinalize();
}
}
static AuSPtr<TestSocketDriver> NewTestSocketDriver(const AuSPtr<DriverStat> &pStats)
{
auto pDriver = AuMakeShared<TestSocketDriver>();
SysAssert(pDriver);
pDriver->pStats = pStats;
return pDriver;
}
TEST(Net, TLSGoogle)
{
auto pIoProcessor = AuIO::NewIOProcessorNoQueue(false);
ASSERT_TRUE(bool(pIoProcessor));
auto pNetProcessor = AuNet::NewNetworkInterface();
ASSERT_TRUE(bool(pNetProcessor));
auto pNetWorker = pNetProcessor->GetWorkersService()->Attach(pIoProcessor);
ASSERT_TRUE(bool(pNetWorker));
auto pStats = AuMakeShared<DriverStat>();
ASSERT_TRUE(bool(pStats));
auto pDriver = NewTestSocketDriver(pStats);
ASSERT_TRUE(bool(pDriver));
auto pRealDriver = AuMakeShared<AuNet::ISocketDriverFunctional>();
static AuSPtr<AuNet::ISocket> gDriverSocket;
pRealDriver->OnPreestablishFunctional = [&](const AuSPtr<AuNet::ISocket> &socket) -> bool
{
#define ENABLE_TLS
#if defined(ENABLE_TLS)
Aurora::IO::TLS::TLSMeta tlsMeta;
//tlsMeta.sSNIServerName = "google.com";
auto pContext = Aurora::IO::TLS::NewTLSContextEx(socket->ToChannel()->NewProtocolSendStack(),
socket->ToChannel()->NewProtocolRecvStack(),
tlsMeta);
pContext->Attach(socket);
pContext->StartHandshake();
#endif
gDriverSocket = socket;
return true;
};
pRealDriver->OnEstablishFunctional = [&]()
{
auto pChannel = gDriverSocket->ToChannel();
pChannel->AsStreamWriter()->Write(AuMemoryViewRead("GET / HTTP/1.1\r\nConnection: close\r\nHost: www.bing.com\r\n\r\n", 57));
};
pRealDriver->OnFatalErrorReportedFunctional = [&](const AuNet::NetError &error)
{
AuLogDbg("[3] On error: {}", NetErrorToExtendedString(error));
};
pRealDriver->OnStreamUpdatedFunctional = [&]()
{
auto pChannel = gDriverSocket->ToChannel();
auto pReader = pChannel->AsReadableByteBuffer();
AuString message;
message.resize(pReader->RemainingBytes());
pReader->Read(message.data(), message.size());
AuLogDbg("Stream updated: {}", message);
};
pRealDriver->OnFinalizeFunctional = [&]()
{
AuLogDbg("[3] On finalize");
};
pDriver->pProxy = pRealDriver;
AuNet::NetSocketConnect nsConnect;
nsConnect.pDriver = pDriver;
nsConnect.endpoint = AuNet::NetEndpoint(AuNet::ETransportProtocol::eProtocolTCP, kHTTP11Address, 443);
auto pSocket = pNetProcessor->GetSocketService()->Connect(nsConnect);
ASSERT_TRUE(bool(pSocket));
while (pIoProcessor->HasItems())
{
pIoProcessor->RunTick();
}
}
void RunTests()
{
Aurora::RuntimeStartInfo info;
info.console.fio.enableLogging = false;
Aurora::RuntimeStart(info);
}

View File

@ -0,0 +1,190 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Main.cpp
Date: 2022-2-18
Author: Reece
***/
#include <AuroraRuntime.hpp>
#include <Aurora/IO/IOExperimental.hpp>
#include <Aurora/IO/Net/NetExperimental.hpp>
#include <Aurora/IO/TLS/TLS.hpp>
#include <gtest/gtest.h>
static const auto kHTTP11Address = "172.217.169.14";
struct DriverStat
{
AuUInt uPreestablish {};
AuUInt uEstablish {};
AuUInt uStreamUpdate {};
AuUInt uError {};
AuUInt uEnd {};
AuUInt uFinalize {};
};
struct TestSocketDriver : AuNet::ISocketDriver
{
AuSPtr<DriverStat> pStats;
AuSPtr<AuNet::ISocketDriver> pProxy;
bool OnPreestablish(const AuSPtr<AuNet::ISocket> &pInforming) override;
void OnEstablish() override;
void OnStreamUpdated() override;
void OnFatalErrorReported(const AuNet::NetError &error) override;
void OnEnd() override;
void OnFinalize() override;
};
bool TestSocketDriver::OnPreestablish(const AuSPtr<AuNet::ISocket> &pInforming)
{
this->pStats->uPreestablish++;
if (this->pProxy)
{
this->pProxy->OnPreestablish(pInforming);
}
return true;
}
void TestSocketDriver::OnEstablish()
{
this->pStats->uEstablish++;
if (this->pProxy)
{
this->pProxy->OnEstablish();
}
}
void TestSocketDriver::OnStreamUpdated()
{
this->pStats->uStreamUpdate++;
if (this->pProxy)
{
this->pProxy->OnStreamUpdated();
}
}
void TestSocketDriver::OnFatalErrorReported(const AuNet::NetError &error)
{
this->pStats->uError++;
if (this->pProxy)
{
this->pProxy->OnFatalErrorReported(error);
}
}
void TestSocketDriver::OnEnd()
{
this->pStats->uEnd++;
if (this->pProxy)
{
this->pProxy->OnEnd();
}
}
void TestSocketDriver::OnFinalize()
{
this->pStats->uFinalize++;
if (this->pProxy)
{
this->pProxy->OnFinalize();
}
}
static AuSPtr<TestSocketDriver> NewTestSocketDriver(const AuSPtr<DriverStat> &pStats)
{
auto pDriver = AuMakeShared<TestSocketDriver>();
SysAssert(pDriver);
pDriver->pStats = pStats;
return pDriver;
}
TEST(Net, TLSGoogle)
{
auto pIoProcessor = AuIO::NewIOProcessorNoQueue(false);
ASSERT_TRUE(bool(pIoProcessor));
auto pNetProcessor = AuNet::NewNetworkInterface();
ASSERT_TRUE(bool(pNetProcessor));
auto pNetWorker = pNetProcessor->GetWorkersService()->Attach(pIoProcessor);
ASSERT_TRUE(bool(pNetWorker));
auto pStats = AuMakeShared<DriverStat>();
ASSERT_TRUE(bool(pStats));
auto pDriver = NewTestSocketDriver(pStats);
ASSERT_TRUE(bool(pDriver));
auto pRealDriver = AuMakeShared<AuNet::ISocketDriverFunctional>();
static AuSPtr<AuNet::ISocket> gDriverSocket;
pRealDriver->OnPreestablishFunctional = [&](const AuSPtr<AuNet::ISocket> &socket) -> bool
{
#define ENABLE_TLS
#if defined(ENABLE_TLS)
Aurora::IO::TLS::TLSMeta tlsMeta;
//tlsMeta.sSNIServerName = "google.com";
auto pContext = Aurora::IO::TLS::NewTLSContextEx(socket->ToChannel()->NewProtocolSendStack(),
socket->ToChannel()->NewProtocolRecvStack(),
tlsMeta);
pContext->Attach(socket);
pContext->StartHandshake();
#endif
gDriverSocket = socket;
return true;
};
pRealDriver->OnEstablishFunctional = [&]()
{
auto pChannel = gDriverSocket->ToChannel();
pChannel->AsStreamWriter()->Write(AuMemoryViewRead("GET / HTTP/1.1\r\nConnection: close\r\n\r\n", 37));
};
pRealDriver->OnFatalErrorReportedFunctional = [&](const AuNet::NetError &error)
{
AuLogDbg("[3] On error: {}", NetErrorToExtendedString(error));
};
pRealDriver->OnStreamUpdatedFunctional = [&]()
{
auto pChannel = gDriverSocket->ToChannel();
auto pReader = pChannel->AsReadableByteBuffer();
AuString message;
message.resize(pReader->RemainingBytes());
pReader->Read(message.data(), message.size());
AuLogDbg("Stream updated: {}", message);
};
pRealDriver->OnFinalizeFunctional = [&]()
{
AuLogDbg("[3] On finalize");
};
pDriver->pProxy = pRealDriver;
AuNet::NetSocketConnect nsConnect;
nsConnect.pDriver = pDriver;
nsConnect.endpoint = AuNet::NetEndpoint(AuNet::ETransportProtocol::eProtocolTCP, kHTTP11Address, 443);
auto pSocket = pNetProcessor->GetSocketService()->Connect(nsConnect);
ASSERT_TRUE(bool(pSocket));
while (pIoProcessor->HasItems())
{
pIoProcessor->RunTick();
}
}
void RunTests()
{
Aurora::RuntimeStartInfo info;
info.console.fio.enableLogging = false;
Aurora::RuntimeStart(info);
}

View File

@ -0,0 +1,112 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Main.cpp
Date: 2022-2-18
Author: Reece
***/
#include <AuroraRuntime.hpp>
#include <Aurora/IO/IOExperimental.hpp>
#include <Aurora/IO/Net/NetExperimental.hpp>
#include <gtest/gtest.h>
TEST(Net, ServerDemo)
{
auto pIoProcessor = AuIO::NewIOProcessorNoQueue(false);
ASSERT_TRUE(bool(pIoProcessor));
auto pNetProcessor = AuNet::NewNetworkInterface();
ASSERT_TRUE(bool(pNetProcessor));
auto pNetWorker = pNetProcessor->GetWorkersService()->Attach(pIoProcessor);
ASSERT_TRUE(bool(pNetWorker));
auto pSocketFactory = AuMakeShared<AuNet::ISocketDriverFactoryFunctional>();
ASSERT_TRUE(bool(pSocketFactory));
pSocketFactory->NewSocketDriverFunctional = []() -> AuSPtr<AuNet::ISocketDriver>
{
struct TempDriver : AuNet::ISocketDriverFunctional
{
AuSPtr<AuNet::ISocket> pDriverSocket;
};
auto pRealDriver = AuMakeShared<TempDriver>();
pRealDriver->OnPreestablishFunctional = [=](const AuSPtr<AuNet::ISocket> &socket) -> bool
{
pRealDriver->pDriverSocket = socket;
return true;
};
pRealDriver->OnEstablishFunctional = [=]()
{
auto pChannel = pRealDriver->pDriverSocket->ToChannel();
pChannel->AsStreamWriter()->Write(AuMemoryViewRead("Hello World", 11));
};
pRealDriver->OnFatalErrorReportedFunctional = [=](const AuNet::NetError &error)
{
AuLogDbg("[2] On error: {}", NetErrorToExtendedString(error));
};
pRealDriver->OnStreamUpdatedFunctional = [=]()
{
auto pChannel = pRealDriver->pDriverSocket->ToChannel();
auto pReader = pChannel->AsReadableByteBuffer();
AuString message;
message.resize(pReader->RemainingBytes());
pReader->Read(message.data(), message.size());
AuLogDbg("[2] Got: {}", message);
};
pRealDriver->OnFinalizeFunctional = [=]()
{
pRealDriver->~TempDriver(); // reset circular dependence on captured pRealDriver
AuLogDbg("[2] Finalize");
};
return pRealDriver;
};
auto pServerDriver = AuMakeShared<AuNet::ISocketServerDriverFunctional>();
ASSERT_TRUE(bool(pServerDriver));
pServerDriver->OnBindFunctional = [&]()
{
AuLogDbg("[1] On bind");
};
pServerDriver->OnFatalErrorReportedFunctional = [&](const AuNet::NetError &error)
{
AuLogDbg("[1] On error: {}", NetErrorToExtendedString(error));
};
pServerDriver->OnFinalizeFunctional = [&]()
{
AuLogDbg("[1] On finalize");
};
AuNet::NetSocketBind nsSocketBind;
nsSocketBind.pDriver = pServerDriver;
nsSocketBind.ip = AuNet::IPAddress("127.0.0.1");
nsSocketBind.protocol = AuNet::ETransportProtocol::eProtocolTCP;
nsSocketBind.uPort = 8087;
nsSocketBind.pFactory = pSocketFactory;
auto pSocket = pNetProcessor->GetSocketService()->NewServer(nsSocketBind);
ASSERT_TRUE(bool(pSocket));
while (pIoProcessor->HasItems())
{
pIoProcessor->RunTick();
}
}
void RunTests()
{
Aurora::RuntimeStartInfo info;
info.console.fio.enableLogging = false;
Aurora::RuntimeStart(info);
}

View File

@ -0,0 +1,73 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Main.cpp
Date: 2022-2-18
Author: Reece
***/
#include <AuroraRuntime.hpp>
#include <Aurora/IO/IOExperimental.hpp>
#include <Aurora/IO/Net/NetExperimental.hpp>
#include <gtest/gtest.h>
TEST(UDP, DatagramServer)
{
auto pIoProcessor = AuIO::NewIOProcessorNoQueue(false);
ASSERT_TRUE(bool(pIoProcessor));
auto pNetProcessor = AuNet::NewNetworkInterface();
ASSERT_TRUE(bool(pNetProcessor));
auto pNetWorker = pNetProcessor->GetWorkersService()->Attach(pIoProcessor);
ASSERT_TRUE(bool(pNetWorker));
auto pDriver = AuMakeShared<AuNet::IDatagramDriverFunctional>();
ASSERT_TRUE(bool(pDriver));
pDriver->OnBindFunctional = []()
{
AuLogDbg("[UDP] On bind");
};
pDriver->OnPacketFunctional = [](const AuNet::NetEndpoint &client,
const AuSPtr<AuByteBuffer> &pPacket)
{
AuLogDbg("[UDP] On packet");
};
pDriver->OnErrorFunctional = [](const AuNet::NetError &error)
{
AuLogDbg("[UDP] On error: {}", NetErrorToExtendedString(error));
};
pDriver->OnFatalErrorReportedFunctional = [](const AuNet::NetError &error)
{
AuLogDbg("[UDP] On fatal error: {}", NetErrorToExtendedString(error));
};
pDriver->OnFinalizeFunctional = []()
{
AuLogDbg("[UDP] On finalize");
};
AuNet::NetDatagramBind nsDatagramBind;
nsDatagramBind.pDriver = pDriver;
nsDatagramBind.ip = AuNet::IPAddress("127.0.0.1");
nsDatagramBind.uPort = 8087;
nsDatagramBind.pDriver = pDriver;
auto pSocket = pNetProcessor->GetDatagramService()->NewDatagramServer(nsDatagramBind);
ASSERT_TRUE(bool(pSocket));
while (pIoProcessor->HasItems())
{
pIoProcessor->RunTick();
}
}
void RunTests()
{
Aurora::RuntimeStartInfo info;
info.console.fio.enableLogging = false;
Aurora::RuntimeStart(info);
}

2
Vendor/mbedtls vendored

@ -1 +1 @@
Subproject commit 4e4d72cce22b68d395bb5e23591d776f53923510
Subproject commit 13784a572a40e5f5e756ab325b67655348fd67a8