Moonlight-XboxOG latest
Moonlight Xbox OG is a port of the Moonlight Game Streaming client to the original Xbox console.
host_pairing.h
Go to the documentation of this file.
1
5#pragma once
6
7// standard includes
8#include <atomic>
9#include <cstdint>
10#include <functional>
11#include <string>
12#include <string_view>
13#include <vector>
14
15namespace network {
16
21 std::string uniqueId;
22 std::string certificatePem;
23 std::string privateKeyPem;
24 };
25
31 std::string appVersion;
32 std::string gfeVersion;
33 uint16_t httpPort = 0;
34 uint16_t httpsPort = 0;
35 bool paired = false;
39 std::string hostName;
40 std::string uuid;
41 std::string activeAddress;
42 std::string localAddress;
43 std::string remoteAddress;
44 std::string ipv6Address;
45 std::string macAddress;
46 uint32_t runningGameId = 0;
47 };
48
52 struct HostAppEntry {
53 std::string name;
54 int id = 0;
55 bool hdrSupported = false;
56 bool hidden = false;
57 };
58
63 std::string address;
64 uint16_t httpPort;
65 std::string pin;
66 std::string deviceName;
68 };
69
74 bool success;
76 std::string message;
77 };
78
83 int appId = 0;
84 int width = 640;
85 int height = 480;
86 int fps = 30;
88 bool playAudioOnPc = false;
91 std::string remoteInputAesIvHex;
92 };
93
105
112 bool is_valid_pairing_identity(const PairingIdentity &identity);
113
120 PairingIdentity create_pairing_identity(std::string *errorMessage = nullptr);
121
129 bool generate_pairing_pin(std::string *pin, std::string *errorMessage = nullptr);
130
140 bool parse_server_info_response(std::string_view xml, uint16_t fallbackHttpPort, HostPairingServerInfo *serverInfo, std::string *errorMessage = nullptr);
141
150 bool parse_app_list_response(std::string_view xml, std::vector<HostAppEntry> *apps, std::string *errorMessage = nullptr);
151
158 bool error_indicates_unpaired_client(std::string_view errorMessage);
159
166 uint64_t hash_app_list_entries(const std::vector<HostAppEntry> &apps);
167
175 std::string resolve_reachable_address(const std::string &requestedAddress, const HostPairingServerInfo &serverInfo);
176
188 const std::string &address,
189 uint16_t preferredHttpPort,
190 const PairingIdentity *clientIdentity,
191 HostPairingServerInfo *serverInfo,
192 std::string *errorMessage = nullptr
193 );
194
206 bool query_app_list(
207 const std::string &address,
208 uint16_t preferredHttpPort,
209 const PairingIdentity *clientIdentity,
210 std::vector<HostAppEntry> *apps,
211 HostPairingServerInfo *serverInfo = nullptr,
212 std::string *errorMessage = nullptr
213 );
214
226 bool query_app_asset(
227 const std::string &address,
228 uint16_t httpsPort,
229 const PairingIdentity *clientIdentity,
230 int appId,
231 std::vector<unsigned char> *assetBytes,
232 std::string *errorMessage = nullptr
233 );
234
251 const std::string &address,
252 uint16_t preferredHttpPort,
253 const PairingIdentity &clientIdentity,
254 const StreamLaunchConfiguration &configuration,
255 StreamLaunchResult *result,
256 std::string *errorMessage = nullptr
257 );
258
266 HostPairingResult pair_host(const HostPairingRequest &request, const std::atomic<bool> *cancelRequested = nullptr);
267
268 namespace testing {
269
274 std::string address;
275 uint16_t port = 0;
276 std::string pathAndQuery;
277 bool useTls = false;
281 };
282
287 int statusCode = 0;
288 std::string body;
289 };
290
294 using HostPairingHttpTestHandler = std::function<bool(const HostPairingHttpTestRequest &, HostPairingHttpTestResponse *, std::string *, const std::atomic<bool> *)>;
295
302
307
308 } // namespace testing
309
310} // namespace network
bool is_valid_pairing_identity(const PairingIdentity &identity)
Return whether a pairing identity contains the required PEM materials.
Definition host_pairing.cpp:2393
bool generate_pairing_pin(std::string *pin, std::string *errorMessage)
Generate a secure four-digit PIN for host pairing.
Definition host_pairing.cpp:2411
bool parse_app_list_response(std::string_view xml, std::vector< HostAppEntry > *apps, std::string *errorMessage)
Parse the XML response returned by the host app-list endpoint.
Definition host_pairing.cpp:2526
bool error_indicates_unpaired_client(std::string_view errorMessage)
Return whether an error message indicates the client is not paired.
Definition host_pairing.cpp:2630
std::string resolve_reachable_address(const std::string &requestedAddress, const HostPairingServerInfo &serverInfo)
Choose the best reachable address for a host.
Definition host_pairing.cpp:2640
void set_host_pairing_http_test_handler(HostPairingHttpTestHandler handler)
Install a scripted HTTP handler for host-pairing unit tests.
Definition host_pairing.cpp:2871
uint64_t hash_app_list_entries(const std::vector< HostAppEntry > &apps)
Compute a stable hash for a fetched app list.
Definition host_pairing.cpp:2747
void clear_host_pairing_http_test_handler()
Remove any scripted HTTP handler previously installed for host-pairing tests.
Definition host_pairing.cpp:2875
bool parse_server_info_response(std::string_view xml, uint16_t fallbackHttpPort, HostPairingServerInfo *serverInfo, std::string *errorMessage)
Parse the XML response returned by the host server-info endpoint.
Definition host_pairing.cpp:2440
PairingIdentity create_pairing_identity(std::string *errorMessage)
Create a fresh client identity for Moonlight pairing.
Definition host_pairing.cpp:2397
bool query_server_info(const std::string &address, uint16_t preferredHttpPort, const PairingIdentity *clientIdentity, HostPairingServerInfo *serverInfo, std::string *errorMessage)
Query live host status using an optional client identity.
Definition host_pairing.cpp:2572
bool query_app_asset(const std::string &address, uint16_t httpsPort, const PairingIdentity *clientIdentity, int appId, std::vector< unsigned char > *assetBytes, std::string *errorMessage)
Query one app asset such as box art over HTTPS.
Definition host_pairing.cpp:2758
bool launch_or_resume_stream(const std::string &address, uint16_t preferredHttpPort, const PairingIdentity &clientIdentity, const StreamLaunchConfiguration &configuration, StreamLaunchResult *result, std::string *errorMessage)
Launch or resume one host application and return stream session details.
Definition host_pairing.cpp:2700
bool query_app_list(const std::string &address, uint16_t preferredHttpPort, const PairingIdentity *clientIdentity, std::vector< HostAppEntry > *apps, HostPairingServerInfo *serverInfo, std::string *errorMessage)
Query the app list exported by a host.
Definition host_pairing.cpp:2657
HostPairingResult pair_host(const HostPairingRequest &request, const std::atomic< bool > *cancelRequested)
Pair the client with a host using the provided request parameters.
Definition host_pairing.cpp:2811
std::function< bool(const HostPairingHttpTestRequest &, HostPairingHttpTestResponse *, std::string *, const std::atomic< bool > *)> HostPairingHttpTestHandler
Callback used by tests to replace host-pairing HTTP and TLS traffic.
Definition host_pairing.h:294
One application entry returned by the host app list API.
Definition host_pairing.h:52
std::string name
Display name reported by the host.
Definition host_pairing.h:53
bool hidden
True when the app is hidden by default on the host.
Definition host_pairing.h:56
bool hdrSupported
True when the app advertises HDR support.
Definition host_pairing.h:55
Parameters required to perform a host pairing request.
Definition host_pairing.h:62
std::string deviceName
Friendly client name presented to the host.
Definition host_pairing.h:66
uint16_t httpPort
Effective host HTTP port used for pairing.
Definition host_pairing.h:64
PairingIdentity identity
Client identity material presented during pairing.
Definition host_pairing.h:67
std::string pin
User-entered or generated pairing PIN.
Definition host_pairing.h:65
std::string address
Host address used for the pairing session.
Definition host_pairing.h:63
Outcome of attempting to pair with a host.
Definition host_pairing.h:73
std::string message
User-visible success or failure detail.
Definition host_pairing.h:76
bool success
True when pairing succeeded.
Definition host_pairing.h:74
bool alreadyPaired
True when the host was already paired before the request.
Definition host_pairing.h:75
Parsed host status fields used by browsing and pairing flows.
Definition host_pairing.h:29
std::string appVersion
Full appversion string reported by the host server.
Definition host_pairing.h:31
std::string ipv6Address
Host-reported IPv6 address.
Definition host_pairing.h:44
std::string activeAddress
Best currently reachable address chosen for live requests.
Definition host_pairing.h:41
bool pairingStatusCurrentClientKnown
True when the host explicitly reported pairing status for this client.
Definition host_pairing.h:36
std::string uuid
Stable host UUID.
Definition host_pairing.h:40
uint16_t httpPort
HTTP port reported or inferred for plaintext requests.
Definition host_pairing.h:33
std::string remoteAddress
Host-reported WAN address.
Definition host_pairing.h:43
bool paired
True when the host reports that this client is paired.
Definition host_pairing.h:35
std::string macAddress
Host-reported MAC address.
Definition host_pairing.h:45
std::string gfeVersion
Full GFE or Sunshine version string reported by the host server.
Definition host_pairing.h:32
std::string localAddress
Host-reported LAN address.
Definition host_pairing.h:42
int serverMajorVersion
Major version reported by the host server.
Definition host_pairing.h:30
bool pairingStatusCurrentClient
Pairing status reported for this specific client identity.
Definition host_pairing.h:37
int serverCodecModeSupport
Codec capability mask reported by the host.
Definition host_pairing.h:38
uint32_t runningGameId
Running game identifier, or zero when idle.
Definition host_pairing.h:46
uint16_t httpsPort
HTTPS port reported for encrypted requests and assets.
Definition host_pairing.h:34
std::string hostName
User-facing host name reported by the server.
Definition host_pairing.h:39
Client identity material used for Moonlight host pairing.
Definition host_pairing.h:20
std::string certificatePem
Client certificate in PEM format.
Definition host_pairing.h:22
std::string uniqueId
Stable unique identifier presented to the host.
Definition host_pairing.h:21
std::string privateKeyPem
Private key matching the client certificate in PEM format.
Definition host_pairing.h:23
Parameters required to start or resume a streaming session.
Definition host_pairing.h:82
int fps
Requested stream frame rate.
Definition host_pairing.h:86
bool playAudioOnPc
True when the host PC should continue local audio playback during streaming.
Definition host_pairing.h:88
int audioConfiguration
Moonlight audio configuration bitfield.
Definition host_pairing.h:87
int height
Requested stream height in pixels.
Definition host_pairing.h:85
int appId
Host application identifier that should be launched or resumed.
Definition host_pairing.h:83
std::string remoteInputAesKeyHex
Hex-encoded 16-byte remote-input AES key.
Definition host_pairing.h:90
std::string remoteInputAesIvHex
Hex-encoded 16-byte remote-input AES IV.
Definition host_pairing.h:91
int width
Requested stream width in pixels.
Definition host_pairing.h:84
int clientRefreshRateX100
Optional client refresh rate multiplied by 100.
Definition host_pairing.h:89
Parsed result of a successful /launch or /resume request.
Definition host_pairing.h:97
int serverCodecModeSupport
Codec capability mask to pass to moonlight-common-c.
Definition host_pairing.h:103
std::string rtspSessionUrl
Optional RTSP session URL returned by the host.
Definition host_pairing.h:100
HostPairingServerInfo serverInfo
Latest host server-info metadata used for the launch decision.
Definition host_pairing.h:99
bool resumedSession
True when an existing host session was resumed instead of launching a new app.
Definition host_pairing.h:98
std::string appVersion
Full appversion string to pass to moonlight-common-c.
Definition host_pairing.h:101
std::string gfeVersion
Full GFE or Sunshine version string reported during launch.
Definition host_pairing.h:102
Scripted HTTP request details exposed to host-pairing unit tests.
Definition host_pairing.h:273
int socketIoTimeoutMilliseconds
Socket read/write timeout that the real transport would apply.
Definition host_pairing.h:280
std::string pathAndQuery
Raw HTTP path and query string.
Definition host_pairing.h:276
std::string expectedTlsCertificatePem
Optional pinned host certificate expected by the request.
Definition host_pairing.h:279
bool useTls
True when the request would normally use TLS.
Definition host_pairing.h:277
const PairingIdentity * tlsClientIdentity
Optional client identity attached to TLS requests.
Definition host_pairing.h:278
std::string address
Destination host address requested by the pairing helper.
Definition host_pairing.h:274
uint16_t port
Destination host port requested by the pairing helper.
Definition host_pairing.h:275
Scripted HTTP response returned by a host-pairing unit-test handler.
Definition host_pairing.h:286
std::string body
HTTP response body returned to the caller.
Definition host_pairing.h:288
int statusCode
HTTP status code returned to the caller.
Definition host_pairing.h:287