FreeRDP
Loading...
Searching...
No Matches
udp.h File Reference

Pacing server output on the UDP tunnel for servers built with -DWITH_RDPEUDP_SERVER=ON. More...

#include <freerdp/api.h>
#include <freerdp/types.h>
#include <freerdp/peer.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  FreeRDP_UdpSendState
 Link state for pacing encoders. Set size to sizeof(FreeRDP_UdpSendState) before calling. New fields replace reserved ones to ensure the size remains constant. More...
struct  FreeRDP_UdpPeerCallbacks
 Per-peer UDP callbacks, executed on the thread running the freerdp_peer check. Set size to sizeof(FreeRDP_UdpPeerCallbacks). New fields replace reserved ones to ensure the structure size remains constant. More...

Typedefs

typedef void(* psPeerUdpLinkChanged) (void *custom, FreeRDP_UdpLinkState state)
typedef void(* psPeerUdpWriteUnblocked) (void *custom)

Functions

enum WINPR_C23_ENUM_TYPE (uint32_t)
 UDP connection state for a peer.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_peer_set_udp_callbacks (freerdp_peer *peer, const FreeRDP_UdpPeerCallbacks *callbacks, void *custom)
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_peer_get_udp_send_state (freerdp_peer *peer, FreeRDP_UdpSendState *state)

Variables

 FreeRDP_UdpLinkState

Detailed Description

Pacing server output on the UDP tunnel for servers built with -DWITH_RDPEUDP_SERVER=ON.

FreeRDP: A Remote Desktop Protocol Implementation Server side UDP multitransport

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Servers do not need this file to utilize the tunnel; each peer shares a process-wide UDP listener on the TCP address and port and is assigned a worker thread. Because the reliable tunnel does not drop data, servers producing data faster than the link capacity should check FreeRDP_UdpSendState and wait for WriteUnblocked.

This header is installed only if WITH_RDPEUDP_SERVER is defined in freerdp/config.h.

Definition in file udp.h.


Data Structure Documentation

◆ FreeRDP_UdpSendState

struct FreeRDP_UdpSendState

Link state for pacing encoders. Set size to sizeof(FreeRDP_UdpSendState) before calling. New fields replace reserved ones to ensure the size remains constant.

Since
version 3.34.0

Definition at line 60 of file udp.h.

Data Fields
UINT64 reserved[64 - 3]
ALIGN64 UINT32 rttMs

Smoothed round-trip time; 0 before the first sample.

ALIGN64 size_t size

Set by the caller; see the structure description above.

ALIGN64 BOOL writeBlocked

TRUE if queued data exceeds link capacity; see WriteUnblocked.

◆ FreeRDP_UdpPeerCallbacks

struct FreeRDP_UdpPeerCallbacks

Per-peer UDP callbacks, executed on the thread running the freerdp_peer check. Set size to sizeof(FreeRDP_UdpPeerCallbacks). New fields replace reserved ones to ensure the structure size remains constant.

Since
version 3.34.0

Definition at line 80 of file udp.h.

Data Fields
ALIGN64 psPeerUdpLinkChanged LinkChanged
UINT64 reserved[64 - 3]
ALIGN64 size_t size

Set by the caller; see the struct description above.

ALIGN64 psPeerUdpWriteUnblocked WriteUnblocked

Typedef Documentation

◆ psPeerUdpLinkChanged

typedef void(* psPeerUdpLinkChanged) (void *custom, FreeRDP_UdpLinkState state)

Callback invoked when the peer's UDP connection state changes.

Definition at line 70 of file udp.h.

◆ psPeerUdpWriteUnblocked

typedef void(* psPeerUdpWriteUnblocked) (void *custom)

Called when the tunnel can accept more data after writeBlocked was set. Note: freerdp_peer's IsWriteBlocked and DrainOutputBuffer only apply to TCP.

Definition at line 74 of file udp.h.

Function Documentation

◆ freerdp_peer_get_udp_send_state()

WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_peer_get_udp_send_state ( freerdp_peer * peer,
FreeRDP_UdpSendState * state )

Retrieves the link state for pacing. Because the reliable tunnel cannot drop data, exceeding its queue limit will cause the tunnel to fail. The session terminates only if channels have already migrated to UDP; otherwise, it continues on TCP.

Returns
FALSE if no tunnel exists
Since
version 3.34.0

Definition at line 705 of file multitransport_server.c.

706{
707 if (!state)
708 return FALSE;
709 /* The state structure version 3.34.0 ends with the rttMs field. */
710 const size_t required = offsetof(FreeRDP_UdpSendState, rttMs) + sizeof(state->rttMs);
711 if (state->size < required)
712 {
713 WLog_ERR(TAG,
714 "the size of FreeRDP_UdpSendState is %" PRIuz
715 ", but it should be at least %" PRIuz,
716 state->size, required);
717 return FALSE;
718 }
719
720 rdpUdpSendState full = WINPR_C_ARRAY_INIT;
721 if (!freerdp_peer_get_udp_send_state_full(peer, &full))
722 return FALSE;
723
724 FreeRDP_UdpSendState out = WINPR_C_ARRAY_INIT;
725 out.writeBlocked = full.writeBlocked;
726 out.rttMs = full.rttMs;
727 /* Update size to inform the caller how many bytes were filled */
728 const size_t size = (state->size < sizeof(out)) ? state->size : sizeof(out);
729 out.size = size;
730 memcpy(state, &out, size);
731 return TRUE;
732}
Comprehensive UDP send state information, including additional metrics.
Definition udplistener.h:71
ALIGN64 BOOL writeBlocked
Definition udp.h:63
ALIGN64 UINT32 rttMs
Definition udp.h:65
ALIGN64 size_t size
Definition udp.h:62
Link state for pacing encoders. Set size to sizeof(FreeRDP_UdpSendState) before calling....
Definition udp.h:61

References FreeRDP_UdpSendState::rttMs, rdpUdpSendState::rttMs, FreeRDP_UdpSendState::size, FreeRDP_UdpSendState::writeBlocked, and rdpUdpSendState::writeBlocked.

◆ freerdp_peer_set_udp_callbacks()

WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_peer_set_udp_callbacks ( freerdp_peer * peer,
const FreeRDP_UdpPeerCallbacks * callbacks,
void * custom )

Sets the UDP callbacks for a peer. This should be called after the peer context is created and before the tunnel is offered.

Parameters
callbacksThe callback hooks, or nullptr for none.
Since
version 3.34.0

Definition at line 669 of file multitransport_server.c.

671{
672 if (!callbacks)
673 return freerdp_peer_set_udp_hooks(peer, nullptr, nullptr);
674
675 /* The callback structure for version 3.34.0 ends with the WriteUnblocked field. */
676 const size_t required =
677 offsetof(FreeRDP_UdpPeerCallbacks, WriteUnblocked) + sizeof(callbacks->WriteUnblocked);
678 if (callbacks->size < required)
679 {
680 WLog_ERR(TAG,
681 "FreeRDP_UdpPeerCallbacks size %" PRIuz " is too small, expected at least %" PRIuz,
682 callbacks->size, required);
683 return FALSE;
684 }
685
686 const rdpUdpPeerHooks hooks = { .LinkChanged = callbacks->LinkChanged,
687 .WriteUnblocked = callbacks->WriteUnblocked };
688 return freerdp_peer_set_udp_hooks(peer, &hooks, custom);
689}
Callbacks from FreeRDP_UdpPeerCallbacks and internal hooks. Executed on the thread running the freerd...
Definition udplistener.h:82
ALIGN64 size_t size
Definition udp.h:82
Per-peer UDP callbacks, executed on the thread running the freerdp_peer check. Set size to sizeof(Fre...
Definition udp.h:81

References FreeRDP_UdpPeerCallbacks::size.

◆ WINPR_C23_ENUM_TYPE()

enum WINPR_C23_ENUM_TYPE ( uint32_t )

UDP connection state for a peer.

Since
version 3.34.0

< No UDP connection exists or it failed; the peer remains on TCP.

< The tunnel is offered via TCP; the flow is now awaiting a SYN packet.

< A SYN provided the hash, but identity is unproven as the hash could be intercepted

< The security cookie has been received within the tunnel's TLS session.

< Client has also accepted on TCP; the tunnel can now carry channel data.

Definition at line 1 of file udp.h.

44 {
45 FREERDP_UDP_LINK_NONE,
47 FREERDP_UDP_LINK_OFFERED,
49 FREERDP_UDP_LINK_SYN_RECEIVED,
51 FREERDP_UDP_LINK_VERIFIED,
53 FREERDP_UDP_LINK_READY
55 } FreeRDP_UdpLinkState;

References WINPR_C23_ENUM_TYPE().

Referenced by WINPR_C23_ENUM_TYPE().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ FreeRDP_UdpLinkState

FreeRDP_UdpLinkState

Definition at line 55 of file udp.h.