Merge latest to mp_handshake_conndata
Signed-off-by: puvvadar <puvvadar@amazon.com>
This commit is contained in:
@@ -94,6 +94,7 @@ namespace AzNetworking
|
||||
class ITimeoutHandler
|
||||
{
|
||||
public:
|
||||
virtual ~ITimeoutHandler() = default;
|
||||
|
||||
//! Handler callback for timed out items.
|
||||
//! @param item containing registered timeout details
|
||||
|
||||
@@ -103,13 +103,13 @@ namespace AzNetworking
|
||||
//! @return boolean true on success
|
||||
virtual bool Disconnect(ConnectionId connectionId, DisconnectReason reason) = 0;
|
||||
|
||||
//! Sets whether this connection interface can disconnect by virtue of a timeout
|
||||
//! @param timeoutEnabled If this connection interface will automatically disconnect due to a timeout
|
||||
virtual void SetTimeoutEnabled(bool timeoutEnabled) = 0;
|
||||
//! Sets the timeout time in milliseconds, 0 ms means timeouts are disabled.
|
||||
//! @param timeoutMs the number of milliseconds with no traffic before we timeout and close a connection
|
||||
virtual void SetTimeoutMs(AZ::TimeMs timeoutMs) = 0;
|
||||
|
||||
//! Whether this connection interface will disconnect by virtue of a time out (does not account for cvars affecting all connections)
|
||||
//! @return boolean true if this connection will not disconnect on timeout (does not account for cvars affecting all connections)
|
||||
virtual bool IsTimeoutEnabled() const = 0;
|
||||
//! Retrieves the timeout time in milliseconds for this network interface, 0 ms means timeouts are disabled.
|
||||
//! @return the timeout time in milliseconds for this network interface, 0 ms means timeouts are disabled
|
||||
virtual AZ::TimeMs GetTimeoutMs() const = 0;
|
||||
|
||||
//! Const access to the metrics tracked by this network interface.
|
||||
//! @return const reference to the metrics tracked by this network interface
|
||||
|
||||
@@ -321,4 +321,19 @@ namespace AzNetworking
|
||||
return serializer.IsValid();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct SerializeObjectHelper<AZ::Aabb>
|
||||
{
|
||||
static bool SerializeObject(ISerializer& serializer, AZ::Aabb& value)
|
||||
{
|
||||
AZ::Vector3 minValue = value.GetMin();
|
||||
AZ::Vector3 maxValue = value.GetMax();
|
||||
serializer.Serialize(minValue, "minValue");
|
||||
serializer.Serialize(maxValue, "maxValue");
|
||||
value.SetMin(minValue);
|
||||
value.SetMax(maxValue);
|
||||
return serializer.IsValid();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,14 +22,15 @@ namespace AzNetworking
|
||||
#endif
|
||||
|
||||
AZ_CVAR(bool, net_TcpTimeoutConnections, true, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Boolean value on whether we should timeout Tcp connections");
|
||||
AZ_CVAR(AZ::TimeMs, net_TcpHearthbeatTimeMs, AZ::TimeMs{ 2 * 1000 }, nullptr, AZ::ConsoleFunctorFlags::Null, "Tcp connection heartbeat frequency");
|
||||
AZ_CVAR(AZ::TimeMs, net_TcpTimeoutTimeMs, AZ::TimeMs{ 10 * 1000 }, nullptr, AZ::ConsoleFunctorFlags::Null, "Time in milliseconds before we timeout an idle Tcp connection");
|
||||
AZ_CVAR(AZ::TimeMs, net_TcpHeartbeatTimeMs, AZ::TimeMs{ 2 * 1000 }, nullptr, AZ::ConsoleFunctorFlags::Null, "Tcp connection heartbeat frequency");
|
||||
AZ_CVAR(AZ::TimeMs, net_TcpDefaultTimeoutMs, AZ::TimeMs{ 10 * 1000 }, nullptr, AZ::ConsoleFunctorFlags::Null, "Time in milliseconds before we timeout an idle Tcp connection");
|
||||
|
||||
TcpNetworkInterface::TcpNetworkInterface(AZ::Name name, IConnectionListener& connectionListener, TrustZone trustZone, TcpListenThread& listenThread)
|
||||
: m_name(name)
|
||||
, m_trustZone(trustZone)
|
||||
, m_connectionListener(connectionListener)
|
||||
, m_listenThread(listenThread)
|
||||
, m_timeoutMs(net_TcpDefaultTimeoutMs)
|
||||
{
|
||||
;
|
||||
}
|
||||
@@ -97,7 +98,7 @@ namespace AzNetworking
|
||||
}
|
||||
|
||||
AZLOG_INFO("Adding new socket %d", static_cast<int32_t>(tcpSocket->GetSocketFd()));
|
||||
const TimeoutId newTimeoutId = m_connectionTimeoutQueue.RegisterItem(static_cast<uint64_t>(tcpSocket->GetSocketFd()), net_TcpHearthbeatTimeMs);
|
||||
const TimeoutId newTimeoutId = m_connectionTimeoutQueue.RegisterItem(static_cast<uint64_t>(tcpSocket->GetSocketFd()), net_TcpHeartbeatTimeMs);
|
||||
connection->SetTimeoutId(newTimeoutId);
|
||||
connection->SendReliablePacket(CorePackets::InitiateConnectionPacket());
|
||||
m_connectionListener.OnConnect(connection.get());
|
||||
@@ -174,14 +175,14 @@ namespace AzNetworking
|
||||
return connection->Disconnect(reason, TerminationEndpoint::Local);
|
||||
}
|
||||
|
||||
void TcpNetworkInterface::SetTimeoutEnabled(bool timeoutEnabled)
|
||||
void TcpNetworkInterface::SetTimeoutMs(AZ::TimeMs timeoutMs)
|
||||
{
|
||||
m_timeoutEnabled = timeoutEnabled;
|
||||
m_timeoutMs = timeoutMs;
|
||||
}
|
||||
|
||||
bool TcpNetworkInterface::IsTimeoutEnabled() const
|
||||
AZ::TimeMs TcpNetworkInterface::GetTimeoutMs() const
|
||||
{
|
||||
return m_timeoutEnabled;
|
||||
return m_timeoutMs;
|
||||
}
|
||||
|
||||
void TcpNetworkInterface::QueueNewConnection(const PendingConnection& pendingConnection)
|
||||
@@ -257,7 +258,7 @@ namespace AzNetworking
|
||||
return;
|
||||
}
|
||||
AZLOG(NET_TcpTraffic, "Adding new socket %d", static_cast<int32_t>(tcpSocket.GetSocketFd()));
|
||||
const TimeoutId timeoutId = m_connectionTimeoutQueue.RegisterItem(static_cast<uint64_t>(tcpSocket.GetSocketFd()), net_TcpTimeoutTimeMs);
|
||||
const TimeoutId timeoutId = m_connectionTimeoutQueue.RegisterItem(static_cast<uint64_t>(tcpSocket.GetSocketFd()), m_timeoutMs);
|
||||
AZStd::unique_ptr<TcpConnection> connection = AZStd::make_unique<TcpConnection>(connectionId, remoteAddress, *this, tcpSocket, timeoutId);
|
||||
AZ_Assert(connection->GetConnectionRole() == ConnectionRole::Acceptor, "Invalid role for connection");
|
||||
GetConnectionListener().OnConnect(connection.get());
|
||||
@@ -316,7 +317,7 @@ namespace AzNetworking
|
||||
{
|
||||
tcpConnection->SendReliablePacket(CorePackets::HeartbeatPacket());
|
||||
}
|
||||
else if (net_TcpTimeoutConnections && m_networkInterface.IsTimeoutEnabled())
|
||||
else if (net_TcpTimeoutConnections && (m_networkInterface.GetTimeoutMs() > AZ::TimeMs{ 0 }))
|
||||
{
|
||||
tcpConnection->Disconnect(DisconnectReason::Timeout, TerminationEndpoint::Local);
|
||||
return TimeoutResult::Delete;
|
||||
|
||||
@@ -99,8 +99,8 @@ namespace AzNetworking
|
||||
bool WasPacketAcked(ConnectionId connectionId, PacketId packetId) override;
|
||||
bool StopListening() override;
|
||||
bool Disconnect(ConnectionId connectionId, DisconnectReason reason) override;
|
||||
void SetTimeoutEnabled(bool timeoutEnabled) override;
|
||||
bool IsTimeoutEnabled() const override;
|
||||
void SetTimeoutMs(AZ::TimeMs timeoutMs) override;
|
||||
AZ::TimeMs GetTimeoutMs() const override;
|
||||
//! @}
|
||||
|
||||
//! Queues a new incoming connection for this network interface.
|
||||
@@ -156,7 +156,7 @@ namespace AzNetworking
|
||||
AZ::Name m_name;
|
||||
TrustZone m_trustZone;
|
||||
uint16_t m_port = 0;
|
||||
bool m_timeoutEnabled = true;
|
||||
AZ::TimeMs m_timeoutMs = AZ::TimeMs{ 0 };
|
||||
IConnectionListener& m_connectionListener;
|
||||
TcpConnectionSet m_connectionSet;
|
||||
TcpSocketManager m_tcpSocketManager;
|
||||
|
||||
@@ -53,18 +53,11 @@ namespace AzNetworking
|
||||
{
|
||||
Close();
|
||||
|
||||
if (!SocketCreateInternal())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!BindSocketForListenInternal(port))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(SetSocketNonBlocking(m_socketFd) && SetSocketNoDelay(m_socketFd)))
|
||||
if (!SocketCreateInternal()
|
||||
|| !BindSocketForListenInternal(port)
|
||||
|| !(SetSocketNonBlocking(m_socketFd) && SetSocketNoDelay(m_socketFd)))
|
||||
{
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -75,18 +68,11 @@ namespace AzNetworking
|
||||
{
|
||||
Close();
|
||||
|
||||
if (!SocketCreateInternal())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!BindSocketForConnectInternal(address))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(SetSocketNonBlocking(m_socketFd) && SetSocketNoDelay(m_socketFd)))
|
||||
if (!SocketCreateInternal()
|
||||
|| !BindSocketForConnectInternal(address)
|
||||
|| !(SetSocketNonBlocking(m_socketFd) && SetSocketNoDelay(m_socketFd)))
|
||||
{
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace AzNetworking
|
||||
|
||||
AZ_CVAR(bool, net_UdpTimeoutConnections, true, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Boolean value on whether we should timeout Udp connections");
|
||||
AZ_CVAR(AZ::TimeMs, net_UdpPacketTimeSliceMs, AZ::TimeMs{ 8 }, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "The number of milliseconds to allow for packet processing");
|
||||
AZ_CVAR(AZ::TimeMs, net_UdpHearthbeatTimeMs, AZ::TimeMs{ 2 * 1000 }, nullptr, AZ::ConsoleFunctorFlags::Null, "Udp connection heartbeat frequency");
|
||||
AZ_CVAR(AZ::TimeMs, net_UdpTimeoutTimeMs, AZ::TimeMs{ 10 * 1000 }, nullptr, AZ::ConsoleFunctorFlags::Null, "Time in milliseconds before we timeout an idle Udp connection");
|
||||
AZ_CVAR(AZ::TimeMs, net_UdpHeartbeatTimeMs, AZ::TimeMs{ 2 * 1000 }, nullptr, AZ::ConsoleFunctorFlags::Null, "Udp connection heartbeat frequency");
|
||||
AZ_CVAR(AZ::TimeMs, net_UdpDefaultTimeoutMs, AZ::TimeMs{ 10 * 1000 }, nullptr, AZ::ConsoleFunctorFlags::Null, "Time in milliseconds before we timeout an idle Udp connection");
|
||||
AZ_CVAR(AZ::TimeMs, net_MinPacketTimeoutMs, AZ::TimeMs{ 200 }, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Minimum time to wait before timing out an unacked packet");
|
||||
AZ_CVAR(int32_t, net_MaxTimeoutsPerFrame, 1000, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Maximum number of packet timeouts to allow to process in a single frame");
|
||||
AZ_CVAR(float, net_RttFudgeScalar, 2.0f, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Scalar value to multiply computed Rtt by to determine an optimal packet timeout threshold");
|
||||
@@ -61,6 +61,7 @@ namespace AzNetworking
|
||||
, m_connectionListener(connectionListener)
|
||||
, m_socket(net_UdpUseEncryption ? new DtlsSocket() : new UdpSocket())
|
||||
, m_readerThread(readerThread)
|
||||
, m_timeoutMs(net_UdpDefaultTimeoutMs)
|
||||
{
|
||||
const AZ::CVarFixedString compressor = static_cast<AZ::CVarFixedString>(net_UdpCompressor);
|
||||
const AZ::Name compressorName = AZ::Name(compressor);
|
||||
@@ -138,7 +139,7 @@ namespace AzNetworking
|
||||
}
|
||||
|
||||
const ConnectionId connectionId = m_connectionSet.GetNextConnectionId();
|
||||
const TimeoutId timeoutId = m_connectionTimeoutQueue.RegisterItem(aznumeric_cast<uint64_t>(connectionId), net_UdpHearthbeatTimeMs);
|
||||
const TimeoutId timeoutId = m_connectionTimeoutQueue.RegisterItem(aznumeric_cast<uint64_t>(connectionId), m_timeoutMs);
|
||||
|
||||
AZStd::unique_ptr<UdpConnection> connection = AZStd::make_unique<UdpConnection>(connectionId, remoteAddress, *this, ConnectionRole::Connector);
|
||||
UdpPacketEncodingBuffer dtlsData;
|
||||
@@ -403,14 +404,14 @@ namespace AzNetworking
|
||||
return connection->Disconnect(reason, TerminationEndpoint::Local);
|
||||
}
|
||||
|
||||
void UdpNetworkInterface::SetTimeoutEnabled(bool timeoutEnabled)
|
||||
void UdpNetworkInterface::SetTimeoutMs(AZ::TimeMs timeoutMs)
|
||||
{
|
||||
m_timeoutEnabled = timeoutEnabled;
|
||||
m_timeoutMs = timeoutMs;
|
||||
}
|
||||
|
||||
bool UdpNetworkInterface::IsTimeoutEnabled() const
|
||||
AZ::TimeMs UdpNetworkInterface::GetTimeoutMs() const
|
||||
{
|
||||
return m_timeoutEnabled;
|
||||
return m_timeoutMs;
|
||||
}
|
||||
|
||||
bool UdpNetworkInterface::IsEncrypted() const
|
||||
@@ -681,7 +682,7 @@ namespace AzNetworking
|
||||
|
||||
// How long should we sit in the timeout queue before heartbeating or disconnecting
|
||||
const ConnectionId connectionId = m_connectionSet.GetNextConnectionId();
|
||||
const TimeoutId timeoutId = m_connectionTimeoutQueue.RegisterItem(aznumeric_cast<uint64_t>(connectionId), net_UdpTimeoutTimeMs);
|
||||
const TimeoutId timeoutId = m_connectionTimeoutQueue.RegisterItem(aznumeric_cast<uint64_t>(connectionId), m_timeoutMs);
|
||||
|
||||
AZLOG(Debug_UdpConnect, "Accepted new Udp Connection");
|
||||
AZStd::unique_ptr<UdpConnection> connection = AZStd::make_unique<UdpConnection>(connectionId, connectPacket.m_address, *this, ConnectionRole::Acceptor);
|
||||
@@ -745,7 +746,7 @@ namespace AzNetworking
|
||||
{
|
||||
udpConnection->SendUnreliablePacket(CorePackets::HeartbeatPacket());
|
||||
}
|
||||
else if (net_UdpTimeoutConnections && m_networkInterface.IsTimeoutEnabled())
|
||||
else if (net_UdpTimeoutConnections && (m_networkInterface.GetTimeoutMs() > AZ::TimeMs{ 0 }))
|
||||
{
|
||||
udpConnection->Disconnect(DisconnectReason::Timeout, TerminationEndpoint::Local);
|
||||
return TimeoutResult::Delete;
|
||||
|
||||
@@ -104,8 +104,8 @@ namespace AzNetworking
|
||||
bool WasPacketAcked(ConnectionId connectionId, PacketId packetId) override;
|
||||
bool StopListening() override;
|
||||
bool Disconnect(ConnectionId connectionId, DisconnectReason reason) override;
|
||||
void SetTimeoutEnabled(bool timeoutEnabled) override;
|
||||
bool IsTimeoutEnabled() const override;
|
||||
void SetTimeoutMs(AZ::TimeMs timeoutMs) override;
|
||||
AZ::TimeMs GetTimeoutMs() const override;
|
||||
//! @}
|
||||
|
||||
//! Returns true if this is an encrypted socket, false if not.
|
||||
@@ -181,7 +181,7 @@ namespace AzNetworking
|
||||
TrustZone m_trustZone;
|
||||
uint16_t m_port = 0;
|
||||
bool m_allowIncomingConnections = false;
|
||||
bool m_timeoutEnabled = true;
|
||||
AZ::TimeMs m_timeoutMs = AZ::TimeMs{ 0 };
|
||||
IConnectionListener& m_connectionListener;
|
||||
UdpConnectionSet m_connectionSet;
|
||||
TimeoutQueue m_connectionTimeoutQueue;
|
||||
|
||||
@@ -79,17 +79,15 @@ namespace AzNetworking
|
||||
{
|
||||
const int32_t error = GetLastNetworkError();
|
||||
AZLOG_ERROR("Failed to bind UDP socket to port %u (%d:%s)", uint32_t(port), error, GetNetworkErrorDesc(error));
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!SetSocketBufferSizes(m_socketFd, net_UdpSendBufferSize, net_UdpRecvBufferSize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SetSocketNonBlocking(m_socketFd))
|
||||
if (!SetSocketBufferSizes(m_socketFd, net_UdpSendBufferSize, net_UdpRecvBufferSize)
|
||||
|| !SetSocketNonBlocking(m_socketFd))
|
||||
{
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,27 +26,29 @@ namespace AzNetworking
|
||||
{
|
||||
m_running = true;
|
||||
m_joinable = true;
|
||||
m_thread = AZStd::thread([this]()
|
||||
{
|
||||
OnStart();
|
||||
while (m_running)
|
||||
m_thread = AZStd::thread(
|
||||
m_threadDesc,
|
||||
[this]()
|
||||
{
|
||||
const AZ::TimeMs startTimeMs = AZ::GetElapsedTimeMs();
|
||||
OnUpdate(m_updateRate);
|
||||
const AZ::TimeMs updateTimeMs = AZ::GetElapsedTimeMs() - startTimeMs;
|
||||
OnStart();
|
||||
while (m_running)
|
||||
{
|
||||
const AZ::TimeMs startTimeMs = AZ::GetElapsedTimeMs();
|
||||
OnUpdate(m_updateRate);
|
||||
const AZ::TimeMs updateTimeMs = AZ::GetElapsedTimeMs() - startTimeMs;
|
||||
|
||||
if (m_updateRate > updateTimeMs)
|
||||
{
|
||||
AZStd::chrono::milliseconds sleepTimeMs(static_cast<int64_t>(m_updateRate - updateTimeMs));
|
||||
AZStd::this_thread::sleep_for(sleepTimeMs);
|
||||
if (m_updateRate > updateTimeMs)
|
||||
{
|
||||
AZStd::chrono::milliseconds sleepTimeMs(static_cast<int64_t>(m_updateRate - updateTimeMs));
|
||||
AZStd::this_thread::sleep_for(sleepTimeMs);
|
||||
}
|
||||
else if (m_updateRate < updateTimeMs)
|
||||
{
|
||||
AZLOG(NET_TimedThread, "TimedThread bled %d ms", aznumeric_cast<int32_t>(updateTimeMs - m_updateRate));
|
||||
}
|
||||
}
|
||||
else if (m_updateRate < updateTimeMs)
|
||||
{
|
||||
AZLOG(NET_TimedThread, "TimedThread bled %d ms", aznumeric_cast<int32_t>(updateTimeMs - m_updateRate));
|
||||
}
|
||||
}
|
||||
OnStop();
|
||||
}, &m_threadDesc);
|
||||
OnStop();
|
||||
});
|
||||
}
|
||||
|
||||
void TimedThread::Stop()
|
||||
|
||||
@@ -149,8 +149,9 @@ namespace UnitTest
|
||||
EXPECT_EQ(testServer.m_serverNetworkInterface->GetConnectionSet().GetConnectionCount(), 1);
|
||||
EXPECT_EQ(testClient.m_clientNetworkInterface->GetConnectionSet().GetConnectionCount(), 1);
|
||||
|
||||
testClient.m_clientNetworkInterface->SetTimeoutEnabled(true);
|
||||
EXPECT_TRUE(testClient.m_clientNetworkInterface->IsTimeoutEnabled());
|
||||
const AZ::TimeMs timeoutMs = AZ::TimeMs{ 100 };
|
||||
testClient.m_clientNetworkInterface->SetTimeoutMs(timeoutMs);
|
||||
EXPECT_EQ(testClient.m_clientNetworkInterface->GetTimeoutMs(), timeoutMs);
|
||||
|
||||
EXPECT_TRUE(testServer.m_serverNetworkInterface->StopListening());
|
||||
}
|
||||
|
||||
@@ -279,8 +279,9 @@ namespace UnitTest
|
||||
EXPECT_EQ(testServer.m_serverNetworkInterface->GetConnectionSet().GetConnectionCount(), 1);
|
||||
EXPECT_EQ(testClient.m_clientNetworkInterface->GetConnectionSet().GetConnectionCount(), 1);
|
||||
|
||||
testClient.m_clientNetworkInterface->SetTimeoutEnabled(true);
|
||||
EXPECT_TRUE(testClient.m_clientNetworkInterface->IsTimeoutEnabled());
|
||||
const AZ::TimeMs timeoutMs = AZ::TimeMs{ 100 };
|
||||
testClient.m_clientNetworkInterface->SetTimeoutMs(timeoutMs);
|
||||
EXPECT_EQ(testClient.m_clientNetworkInterface->GetTimeoutMs(), timeoutMs);
|
||||
|
||||
EXPECT_FALSE(dynamic_cast<UdpNetworkInterface*>(testClient.m_clientNetworkInterface)->IsEncrypted());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user