AuroraRuntime/Source/IO/Net/AuNetEndpoint.cpp

128 lines
3.1 KiB
C++
Raw Normal View History

[+] Network + Protocol + TLS - Initial Commit ============================================================================= 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
2022-08-28 19:02:06 +00:00
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetEndpoint.cpp
Date: 2022-8-16
Author: Reece
***/
#include "Networking.hpp"
#include "AuNetEndpoint.hpp"
namespace Aurora::IO::Net
{
AuUInt8 OptimizeEndpoint(NetEndpoint &ep)
{
// TFW structure is more of a defacto standard than the instantiation of the fields
int offset;
auto &hint = ep.hint[AuArraySize(ep.hint) - 1];
if (!hint)
{
AuMemset(ep.hint, 0, AuArraySize(ep.hint));
switch (ep.ip.ip)
{
case EIPProtocol::eIPProtocolV6:
{
AuWriteU16(ep.hint, 0, AF_INET6);
AuWriteU16BE(ep.hint, 2, ep.uPort);
offset = { 0 };
offset += 4; // flowinfo
for (int i = 0; i < AuArraySize(ep.ip.v6); i++)
{
AuWriteU16BE(ep.hint + 4 + 4 + offset, i * sizeof(*ep.ip.v6), ep.ip.v6[i]);//AuArraySize(ep.ip.v6) - 1 - i]);
}
AuWriteU16BE(ep.hint, 24, ep.uIPv6Scope);
hint = true;
break;
}
case EIPProtocol::eIPProtocolV4:
{
AuWriteU16(ep.hint, 0, AF_INET);
AuWriteU16BE(ep.hint, 2, ep.uPort);
AuWriteU32LE(ep.hint, 4, AuReadU32LE(ep.ip.v4, 0));
hint = true;
break;
}
default:
hint = false;
};
}
return EndpointToLength(ep);
}
AuUInt8 EndpointToLength(const NetEndpoint &ep)
{
[+] Network + Protocol + TLS - Initial Commit ============================================================================= 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
2022-08-28 19:02:06 +00:00
switch (ep.ip.ip)
{
case EIPProtocol::eIPProtocolV6:
{
return 28;
}
case EIPProtocol::eIPProtocolV4:
{
return 16;
}
default:
{
return 0;
}
};
}
void DeoptimizeEndpoint(NetEndpoint &ep)
{
switch (AuReadU16(ep.hint, 0))
{
case AF_INET6:
{
ep.uPort = AuReadU16BE(ep.hint, 2);
ep.ip.ip = EIPProtocol::eIPProtocolV6;
ep.ip.UpdateFromName(true, (const char *)ep.hint + 8);
break;
}
case AF_INET:
{
ep.uPort = AuReadU16BE(ep.hint, 2);
ep.ip.ip = EIPProtocol::eIPProtocolV4;
ep.ip.UpdateFromName(false, (const char *)ep.hint + 4);
break;
}
};
}
AuUInt IPToDomain(EIPProtocol protocol);
AuUInt IPToDomain(const NetEndpoint &ep)
{
return IPToDomain(ep.ip.ip);
}
AuUInt TransportToPlatformType(const NetEndpoint &ep)
{
return TransportToPlatformType(ep.transportProtocol);
}
AuUInt TransportToPlatformType(ETransportProtocol protocol)
{
switch (protocol)
{
case ETransportProtocol::eProtocolTCP:
{
return SOCK_STREAM;
}
case ETransportProtocol::eProtocolUDP:
{
return SOCK_DGRAM;
}
}
return 0;
}
}