Moonlight-XboxOG latest
Moonlight Xbox OG is a port of the Moonlight Game Streaming client to the original Xbox console.
host_pairing.h File Reference

Declares host pairing helpers. More...

#include <atomic>
#include <cstdint>
#include <functional>
#include <string>
#include <string_view>
#include <vector>
Include dependency graph for host_pairing.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  network::HostAppEntry
 One application entry returned by the host app list API. More...
 
struct  network::testing::HostPairingHttpTestRequest
 Scripted HTTP request details exposed to host-pairing unit tests. More...
 
struct  network::testing::HostPairingHttpTestResponse
 Scripted HTTP response returned by a host-pairing unit-test handler. More...
 
struct  network::HostPairingRequest
 Parameters required to perform a host pairing request. More...
 
struct  network::HostPairingResult
 Outcome of attempting to pair with a host. More...
 
struct  network::HostPairingServerInfo
 Parsed host status fields used by browsing and pairing flows. More...
 
struct  network::PairingIdentity
 Client identity material used for Moonlight host pairing. More...
 
struct  network::StreamLaunchConfiguration
 Parameters required to start or resume a streaming session. More...
 
struct  network::StreamLaunchResult
 Parsed result of a successful /launch or /resume request. More...
 

Typedefs

using network::testing::HostPairingHttpTestHandler = std::function<bool(const HostPairingHttpTestRequest &, HostPairingHttpTestResponse *, std::string *, const std::atomic<bool> *)>
 Callback used by tests to replace host-pairing HTTP and TLS traffic.
 

Functions

void network::testing::clear_host_pairing_http_test_handler ()
 Remove any scripted HTTP handler previously installed for host-pairing tests.
 
PairingIdentity network::create_pairing_identity (std::string *errorMessage=nullptr)
 Create a fresh client identity for Moonlight pairing.
 
bool network::error_indicates_unpaired_client (std::string_view errorMessage)
 Return whether an error message indicates the client is not paired.
 
bool network::generate_pairing_pin (std::string *pin, std::string *errorMessage=nullptr)
 Generate a secure four-digit PIN for host pairing.
 
uint64_t network::hash_app_list_entries (const std::vector< HostAppEntry > &apps)
 Compute a stable hash for a fetched app list.
 
bool network::is_valid_pairing_identity (const PairingIdentity &identity)
 Return whether a pairing identity contains the required PEM materials.
 
bool network::launch_or_resume_stream (const std::string &address, uint16_t preferredHttpPort, const PairingIdentity &clientIdentity, const StreamLaunchConfiguration &configuration, StreamLaunchResult *result, std::string *errorMessage=nullptr)
 Launch or resume one host application and return stream session details.
 
HostPairingResult network::pair_host (const HostPairingRequest &request, const std::atomic< bool > *cancelRequested=nullptr)
 Pair the client with a host using the provided request parameters.
 
bool network::parse_app_list_response (std::string_view xml, std::vector< HostAppEntry > *apps, std::string *errorMessage=nullptr)
 Parse the XML response returned by the host app-list endpoint.
 
bool network::parse_server_info_response (std::string_view xml, uint16_t fallbackHttpPort, HostPairingServerInfo *serverInfo, std::string *errorMessage=nullptr)
 Parse the XML response returned by the host server-info endpoint.
 
bool network::query_app_asset (const std::string &address, uint16_t httpsPort, const PairingIdentity *clientIdentity, int appId, std::vector< unsigned char > *assetBytes, std::string *errorMessage=nullptr)
 Query one app asset such as box art over HTTPS.
 
bool network::query_app_list (const std::string &address, uint16_t preferredHttpPort, const PairingIdentity *clientIdentity, std::vector< HostAppEntry > *apps, HostPairingServerInfo *serverInfo=nullptr, std::string *errorMessage=nullptr)
 Query the app list exported by a host.
 
bool network::query_server_info (const std::string &address, uint16_t preferredHttpPort, const PairingIdentity *clientIdentity, HostPairingServerInfo *serverInfo, std::string *errorMessage=nullptr)
 Query live host status using an optional client identity.
 
std::string network::resolve_reachable_address (const std::string &requestedAddress, const HostPairingServerInfo &serverInfo)
 Choose the best reachable address for a host.
 
void network::testing::set_host_pairing_http_test_handler (HostPairingHttpTestHandler handler)
 Install a scripted HTTP handler for host-pairing unit tests.
 

Detailed Description

Declares host pairing helpers.

Function Documentation

◆ create_pairing_identity()

PairingIdentity network::create_pairing_identity ( std::string * errorMessage = nullptr)

Create a fresh client identity for Moonlight pairing.

Parameters
errorMessageOptional output for key or certificate generation failures.
Returns
Generated pairing identity, or an empty identity on failure.

◆ error_indicates_unpaired_client()

bool network::error_indicates_unpaired_client ( std::string_view errorMessage)

Return whether an error message indicates the client is not paired.

Parameters
errorMessageCandidate error text.
Returns
true when the text maps to an unpaired-client condition.

◆ generate_pairing_pin()

bool network::generate_pairing_pin ( std::string * pin,
std::string * errorMessage = nullptr )

Generate a secure four-digit PIN for host pairing.

Parameters
pinOutput buffer populated with exactly four decimal digits.
errorMessageOptional output for entropy or random-byte failures.
Returns
true when a secure PIN was generated successfully.

◆ hash_app_list_entries()

uint64_t network::hash_app_list_entries ( const std::vector< HostAppEntry > & apps)

Compute a stable hash for a fetched app list.

Parameters
appsApp entries to hash.
Returns
Stable hash value for content-change detection.

◆ is_valid_pairing_identity()

bool network::is_valid_pairing_identity ( const PairingIdentity & identity)

Return whether a pairing identity contains the required PEM materials.

Parameters
identityCandidate pairing identity.
Returns
true when the identity is usable for authenticated requests.

◆ launch_or_resume_stream()

bool network::launch_or_resume_stream ( const std::string & address,
uint16_t preferredHttpPort,
const PairingIdentity & clientIdentity,
const StreamLaunchConfiguration & configuration,
StreamLaunchResult * result,
std::string * errorMessage = nullptr )

Launch or resume one host application and return stream session details.

The helper first refreshes /serverinfo using the supplied paired client identity, then resumes the running session when the requested app is already active or launches a new session otherwise.

Parameters
addressHost address to query.
preferredHttpPortPreferred HTTP port override.
clientIdentityPaired client identity used for authenticated launch requests.
configurationStream launch parameters including app ID and remote-input keys.
resultOutput populated with launch metadata required by moonlight-common-c.
errorMessageOptional output for request or parse failures.
Returns
true when the host accepted the launch or resume request.

◆ pair_host()

HostPairingResult network::pair_host ( const HostPairingRequest & request,
const std::atomic< bool > * cancelRequested = nullptr )

Pair the client with a host using the provided request parameters.

Parameters
requestPairing parameters and client identity.
cancelRequestedOptional cancellation flag checked during the request.
Returns
Pairing outcome including success state and user-visible detail.

◆ parse_app_list_response()

bool network::parse_app_list_response ( std::string_view xml,
std::vector< HostAppEntry > * apps,
std::string * errorMessage = nullptr )

Parse the XML response returned by the host app-list endpoint.

Parameters
xmlRaw XML response body.
appsOutput vector populated with parsed app entries.
errorMessageOptional output for parse or validation failures.
Returns
true when the response was parsed successfully.

◆ parse_server_info_response()

bool network::parse_server_info_response ( std::string_view xml,
uint16_t fallbackHttpPort,
HostPairingServerInfo * serverInfo,
std::string * errorMessage = nullptr )

Parse the XML response returned by the host server-info endpoint.

Parameters
xmlRaw XML response body.
fallbackHttpPortHTTP port to use when the response omits it.
serverInfoOutput structure populated from the response.
errorMessageOptional output for parse or validation failures.
Returns
true when the response was parsed successfully.

◆ query_app_asset()

bool network::query_app_asset ( const std::string & address,
uint16_t httpsPort,
const PairingIdentity * clientIdentity,
int appId,
std::vector< unsigned char > * assetBytes,
std::string * errorMessage = nullptr )

Query one app asset such as box art over HTTPS.

Parameters
addressHost address to query.
httpsPortHost HTTPS port.
clientIdentityOptional client identity for authenticated requests.
appIdHost application identifier.
assetBytesOutput vector populated with downloaded asset bytes.
errorMessageOptional output for request failures.
Returns
true when the asset was downloaded successfully.

◆ query_app_list()

bool network::query_app_list ( const std::string & address,
uint16_t preferredHttpPort,
const PairingIdentity * clientIdentity,
std::vector< HostAppEntry > * apps,
HostPairingServerInfo * serverInfo = nullptr,
std::string * errorMessage = nullptr )

Query the app list exported by a host.

Parameters
addressHost address to query.
preferredHttpPortPreferred HTTP port override.
clientIdentityOptional client identity for authenticated requests.
appsOutput vector populated with parsed app entries.
serverInfoOptional output populated with the latest host status data.
errorMessageOptional output for request or parse failures.
Returns
true when the app list was retrieved successfully.

◆ query_server_info()

bool network::query_server_info ( const std::string & address,
uint16_t preferredHttpPort,
const PairingIdentity * clientIdentity,
HostPairingServerInfo * serverInfo,
std::string * errorMessage = nullptr )

Query live host status using an optional client identity.

Parameters
addressHost address to query.
preferredHttpPortPreferred HTTP port override.
clientIdentityOptional client identity for authenticated requests.
serverInfoOutput structure populated with parsed status data.
errorMessageOptional output for request or parse failures.
Returns
true when host status was retrieved successfully.

◆ resolve_reachable_address()

std::string network::resolve_reachable_address ( const std::string & requestedAddress,
const HostPairingServerInfo & serverInfo )

Choose the best reachable address for a host.

Parameters
requestedAddressAddress originally requested by the user.
serverInfoParsed host status information.
Returns
Reachable address to use for subsequent requests.

◆ set_host_pairing_http_test_handler()

void network::testing::set_host_pairing_http_test_handler ( HostPairingHttpTestHandler handler)

Install a scripted HTTP handler for host-pairing unit tests.

Parameters
handlerCallback that should service subsequent host-pairing HTTP requests.