![]() |
Moonlight-XboxOG latest
Moonlight Xbox OG is a port of the Moonlight Game Streaming client to the original Xbox console.
|
Implements host pairing helpers. More...
#include "src/network/host_pairing.h"#include <algorithm>#include <array>#include <atomic>#include <cctype>#include <cstddef>#include <cstdint>#include <cstdio>#include <cstdlib>#include <cstring>#include <functional>#include <memory>#include <string>#include <string_view>#include <vector>#include <openssl/bio.h>#include <openssl/err.h>#include <openssl/evp.h>#include <openssl/pem.h>#include <openssl/rand.h>#include <openssl/rsa.h>#include <openssl/ssl.h>#include <openssl/x509.h>#include "src/network/runtime_network.h"#include "src/platform/error_utils.h"#include "third-party/moonlight-common-c/src/Limelight.h"#include <errno.h>#include <hal/debug.h>#include <lwip/inet.h>#include <lwip/sockets.h>Typedefs | |
| using | SOCKET = int |
| Native socket handle type used on nxdk and POSIX builds. | |
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. | |
| bool | network::query_server_info (const std::string &address, uint16_t preferredHttpPort, HostPairingServerInfo *serverInfo, std::string *errorMessage) |
| Query host status without providing a client identity. | |
| int | rand_s (unsigned int *randomValue) |
| Fill a buffer with secure random bytes using the nxdk compatibility entry point. | |
| 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. | |
Implements host pairing helpers.
| PairingIdentity network::create_pairing_identity | ( | std::string * | errorMessage = nullptr | ) |
Create a fresh client identity for Moonlight pairing.
| errorMessage | Optional output for key or certificate generation failures. |
| bool network::error_indicates_unpaired_client | ( | std::string_view | errorMessage | ) |
Return whether an error message indicates the client is not paired.
| errorMessage | Candidate error text. |
| bool network::generate_pairing_pin | ( | std::string * | pin, |
| std::string * | errorMessage = nullptr ) |
Generate a secure four-digit PIN for host pairing.
| pin | Output buffer populated with exactly four decimal digits. |
| errorMessage | Optional output for entropy or random-byte failures. |
| uint64_t network::hash_app_list_entries | ( | const std::vector< HostAppEntry > & | apps | ) |
Compute a stable hash for a fetched app list.
| apps | App entries to hash. |
| bool network::is_valid_pairing_identity | ( | const PairingIdentity & | identity | ) |
Return whether a pairing identity contains the required PEM materials.
| identity | Candidate pairing identity. |
| 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.
| address | Host address to query. |
| preferredHttpPort | Preferred HTTP port override. |
| clientIdentity | Paired client identity used for authenticated launch requests. |
| configuration | Stream launch parameters including app ID and remote-input keys. |
| result | Output populated with launch metadata required by moonlight-common-c. |
| errorMessage | Optional output for request or parse failures. |
| HostPairingResult network::pair_host | ( | const HostPairingRequest & | request, |
| const std::atomic< bool > * | cancelRequested = nullptr ) |
Pair the client with a host using the provided request parameters.
| request | Pairing parameters and client identity. |
| cancelRequested | Optional cancellation flag checked during the request. |
| 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.
| xml | Raw XML response body. |
| apps | Output vector populated with parsed app entries. |
| errorMessage | Optional output for parse or validation failures. |
| 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.
| xml | Raw XML response body. |
| fallbackHttpPort | HTTP port to use when the response omits it. |
| serverInfo | Output structure populated from the response. |
| errorMessage | Optional output for parse or validation failures. |
| 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.
| address | Host address to query. |
| httpsPort | Host HTTPS port. |
| clientIdentity | Optional client identity for authenticated requests. |
| appId | Host application identifier. |
| assetBytes | Output vector populated with downloaded asset bytes. |
| errorMessage | Optional output for request failures. |
| 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.
| address | Host address to query. |
| preferredHttpPort | Preferred HTTP port override. |
| clientIdentity | Optional client identity for authenticated requests. |
| apps | Output vector populated with parsed app entries. |
| serverInfo | Optional output populated with the latest host status data. |
| errorMessage | Optional output for request or parse failures. |
| 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.
| address | Host address to query. |
| preferredHttpPort | Preferred HTTP port override. |
| clientIdentity | Optional client identity for authenticated requests. |
| serverInfo | Output structure populated with parsed status data. |
| errorMessage | Optional output for request or parse failures. |
| bool network::query_server_info | ( | const std::string & | address, |
| uint16_t | preferredHttpPort, | ||
| HostPairingServerInfo * | serverInfo, | ||
| std::string * | errorMessage ) |
Query host status without providing a client identity.
| address | Host address to query. |
| preferredHttpPort | Preferred HTTP port override. |
| serverInfo | Output structure populated with parsed status data. |
| errorMessage | Optional output for request or parse failures. |
| int rand_s | ( | unsigned int * | randomValue | ) |
Fill a buffer with secure random bytes using the nxdk compatibility entry point.
| randomValue | Output integer populated with secure random bits. |
| std::string network::resolve_reachable_address | ( | const std::string & | requestedAddress, |
| const HostPairingServerInfo & | serverInfo ) |
Choose the best reachable address for a host.
| requestedAddress | Address originally requested by the user. |
| serverInfo | Parsed host status information. |
| void network::testing::set_host_pairing_http_test_handler | ( | HostPairingHttpTestHandler | handler | ) |
Install a scripted HTTP handler for host-pairing unit tests.
| handler | Callback that should service subsequent host-pairing HTTP requests. |