This class implements a UDP network interface. More...
#include <UdpNetworkInterface.h>
Inherits AzNetworking::INetworkInterface.
Public Member Functions | |
UdpNetworkInterface (const AZ::Name &name, IConnectionListener &connectionListener, TrustZone trustZone, UdpReaderThread &readerThread) | |
AZ::Name | GetName () const override |
ProtocolType | GetType () const override |
TrustZone | GetTrustZone () const override |
uint16_t | GetPort () const override |
IConnectionSet & | GetConnectionSet () override |
IConnectionListener & | GetConnectionListener () override |
bool | Listen (uint16_t port) override |
ConnectionId | Connect (const IpAddress &remoteAddress, uint16_t localPort=0) override |
void | Update () override |
Updates the INetworkInterface. | |
bool | SendReliablePacket (ConnectionId connectionId, const IPacket &packet) override |
PacketId | SendUnreliablePacket (ConnectionId connectionId, const IPacket &packet) override |
bool | WasPacketAcked (ConnectionId connectionId, PacketId packetId) override |
bool | StopListening () override |
bool | Disconnect (ConnectionId connectionId, DisconnectReason reason) override |
void | SetTimeoutMs (AZ::TimeMs timeoutMs) override |
AZ::TimeMs | GetTimeoutMs () const override |
bool | IsEncrypted () const override |
bool | IsOpen () const override |
Public Member Functions inherited from AzNetworking::INetworkInterface | |
AZ_RTTI (INetworkInterface, "{ECDA6FA2-4AA0-435E-881F-214C4B179A31}") | |
virtual AZ::Name | GetName () const =0 |
virtual ProtocolType | GetType () const =0 |
virtual TrustZone | GetTrustZone () const =0 |
virtual uint16_t | GetPort () const =0 |
virtual IConnectionSet & | GetConnectionSet ()=0 |
virtual IConnectionListener & | GetConnectionListener ()=0 |
virtual bool | Listen (uint16_t port)=0 |
virtual ConnectionId | Connect (const IpAddress &remoteAddress, uint16_t localPort=0)=0 |
virtual void | Update ()=0 |
Updates the INetworkInterface. | |
virtual bool | SendReliablePacket (ConnectionId connectionId, const IPacket &packet)=0 |
virtual PacketId | SendUnreliablePacket (ConnectionId connectionId, const IPacket &packet)=0 |
virtual bool | WasPacketAcked (ConnectionId connectionId, PacketId packetId)=0 |
virtual bool | StopListening ()=0 |
virtual bool | Disconnect (ConnectionId connectionId, DisconnectReason reason)=0 |
virtual void | SetTimeoutMs (AZ::TimeMs timeoutMs)=0 |
virtual AZ::TimeMs | GetTimeoutMs () const =0 |
const NetworkInterfaceMetrics & | GetMetrics () const |
NetworkInterfaceMetrics & | GetMetrics () |
virtual bool | IsEncrypted () const =0 |
virtual bool | IsOpen () const =0 |
Friends | |
class | UdpReliableQueue |
class | UdpConnection |
This class implements a UDP network interface.
UdpNetworkInterface is an implementation of AzNetworking::INetworkInterface. Since UDP is a very bare bones protocol, the Open 3D Engine implementation has to provide significantly more than its TCP counterpart (since TCP implements a significant number of reliability features.)
When sent through UDP, a packet can have additional actions performed on it depending on which features are enabled and configured. Each feature listed in this description is in the order a packet will see them on Send.
The general structure of a UDP packet is:
For more information, read Networking Packets in the O3DE documentation.
UDP packets can be sent reliably or unreliably. Reliably sent packets are registered for tracking first. This causes the reliable packet to be resent if a timeout on the packet is reached. Once the packet is acknowledged, the packet is unregistered.
If the raw packet size exceeds the configured maximum transmission unit (MTU) then the packet is broken into multiple fragments to avoid fragmentation at the routing level. Fragment reliability is controlled by the cvar net_FragmentsAlwaysReliable. When true, fragments are always sent reliably to ensure the source packet can be reconstructed. This means unreliable packets exceeding MTU will be split into several reliable packets to guarantee delivery but at a cost of extra network processing. (Default) When false, fragments inherit the reliability type of their source packet. This may cause non-reliable packet transmission to fail if packet is fragmented, if even one fragment fails to be delivered due to network conditions.
Optimizing packets to remain under MTU and appropriate usage of reliable packets is recommended before enabling net_FragmentsAlwaysReliable.
Operations that alter the payload generally follow this step so that they can be separately applied to the Fragments in addition to not being applied to both the original and Fragments.
Compression here refers to content insensitive compression using libraries like LZ4. If enabled, the target payload is run through the compressor and replaces the original payload if it's in fact smaller. To tell if compression is enabled on a given packet, we operate on a bit in the packet's Flags. The Sender writes this bit while the Receiver checks it to see if a packet needs to be decompressed.
O3DE could potentially move from over MTU to under with compression, and the UDP interface doesn't check for this. Detecting a change that would reduce the number of fragmented packets would require pre-emptively compressing payloads to tell if that change happened, which could potentially lead to a lot of unnecessary calls to the compressor.
AzNetworking uses the OpenSSL library to implement Datagram Layer Transport Security (DTLS) encryption on UDP traffic. Encryption operates as described in O3DE Networking Encryption on the documentation website. Once both endpoints have completed their handshake, all traffic is expected to be fully encrypted.
AzNetworking::UdpNetworkInterface::UdpNetworkInterface | ( | const AZ::Name & | name, |
IConnectionListener & | connectionListener, | ||
TrustZone | trustZone, | ||
UdpReaderThread & | readerThread | ||
) |
Constructor.
name | the name of this network interface instance. |
connectionListener | reference to the connection listener responsible for handling all connection events |
trustZone | the trust level assigned to this network interface, server to server or client to server |
readerThread | pointer to the reader thread to be bound to this network interface |
|
overridevirtual |
Opens a new connection to the provided address.
remoteAddress | the IpAddress of the remote process to open a connection to |
localPort | the local port number to open a socket on to initiate the connection, 0 binds to any available port |
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Disconnects the specified connection.
connectionId | identifier of the connection to terminate |
reason | reason for the disconnect |
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Returns a reference to the connection listener for this network interface.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Returns the connection set for this network interface.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
INetworkInterface interface.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Returns the port number this network interface is bound to.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Retrieves the timeout time in milliseconds for this network interface, 0 ms means timeouts are disabled.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Retrieves the trust zone for this network interface instance.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Retrieves the type of this network interface instance.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Returns true if communications on this network interface are encrypted, false if not.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Returns true if this connection instance is in an open state, and is capable of actively sending and receiving packets.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Opens the network interface to allow it to accept new incoming connections.
port | the listen port number this network interface will potentially bind to, 0 if it's a don't care |
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
A helper function that transmits a packet on this connection reliably. Note that a packetId is not returned here, since retransmits may cause the packetId to change
connectionId | identifier of the connection to send to |
packet | packet to transmit |
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
A helper function that transmits a packet on this connection unreliably.
connectionId | identifier of the connection to send to |
packet | packet to transmit |
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Sets the timeout time in milliseconds, 0 ms means timeouts are disabled.
timeoutMs | the number of milliseconds with no traffic before we timeout and close a connection |
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Closes the network interface to stop accepting new incoming connections.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Updates the INetworkInterface.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Returns true if the given packet id was confirmed acknowledged by the remote endpoint, false otherwise.
connectionId | identifier of the connection to send to |
packetId | the packet id of the packet to confirm acknowledgment of |
Implements AzNetworking::INetworkInterface.