Sunshine master
Self-hosted game stream host for Moonlight.
nvhttp.cpp File Reference

Definitions for the nvhttp (GameStream) server. More...

#include <filesystem>
#include <format>
#include <string>
#include <utility>
#include <boost/asio/ssl/context.hpp>
#include <boost/asio/ssl/context_base.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <Simple-Web-Server/server_http.hpp>
#include "config.h"
#include "display_device.h"
#include "file_handler.h"
#include "globals.h"
#include "httpcommon.h"
#include "logging.h"
#include "network.h"
#include "nvhttp.h"
#include "platform/common.h"
#include "process.h"
#include "rtsp.h"
#include "system_tray.h"
#include "utility.h"
#include "uuid.h"
#include "video.h"
Include dependency graph for nvhttp.cpp:

Classes

struct  nvhttp::client_t
 Persisted pairing data for one Moonlight client. More...
 
struct  nvhttp::conf_intern_t
 Internal HTTPS credential paths for the configuration server. More...
 
struct  nvhttp::named_cert_t
 Certificate entry associated with a client name and UUID. More...
 
class  nvhttp::SunshineHTTPSServer
 HTTPS server backend that adds Sunshine's client-certificate verification. More...
 
struct  nvhttp::tunnel< SimpleWeb::HTTP >
 Plain HTTP server wrapper used for non-TLS endpoints. More...
 
struct  nvhttp::tunnel< SunshineHTTPS >
 HTTPS tunnel session used for encrypted client requests. More...
 

Namespaces

namespace  nvhttp
 Contains all the functions and variables related to the nvhttp (GameStream) server.
 

Typedefs

using nvhttp::http_server_t = SimpleWeb::Server<SimpleWeb::HTTP>
 Plain HTTP server type used for GameStream endpoints without TLS.
 
using nvhttp::https_server_t = SunshineHTTPSServer
 HTTPS server type used for GameStream endpoints requiring TLS.
 
using nvhttp::req_http_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Request>
 Shared HTTP request object received by redirect and discovery handlers.
 
using nvhttp::req_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Request>
 Shared HTTPS request object received by GameStream handlers.
 
using nvhttp::resp_http_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Response>
 Shared HTTP response object passed to redirect and discovery handlers.
 
using nvhttp::resp_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Response>
 Shared HTTPS response object passed to GameStream handlers.
 

Enumerations

enum class  nvhttp::op_e { nvhttp::ADD , nvhttp::REMOVE }
 Certificate operations supported by the pairing API. More...
 

Functions

void nvhttp::add_authorized_client (const std::string &name, std::string &&cert)
 Add authorized client data.
 
void nvhttp::appasset (resp_https_t response, req_https_t request)
 Return an application asset requested by the client.
 
void nvhttp::applist (resp_https_t response, req_https_t request)
 Build the GameStream application list response.
 
void nvhttp::cancel (resp_https_t response, req_https_t request)
 Check whether cel.
 
void nvhttp::clientchallenge (pair_session_t &sess, pt::ptree &tree, const std::string &challenge)
 Handle the client-challenge phase of GameStream pairing.
 
void nvhttp::clientpairingsecret (pair_session_t &sess, std::shared_ptr< safe::queue_t< crypto::x509_t > > &add_cert, pt::ptree &tree, const std::string &client_pairing_secret)
 Handle the client pairing-secret phase of GameStream pairing.
 
void nvhttp::erase_all_clients ()
 Remove all paired clients.
 
void nvhttp::fail_pair (pair_session_t &sess, pt::ptree &tree, const std::string status_msg)
 Return the GameStream pairing failure response.
 
nlohmann::json nvhttp::get_all_clients ()
 Get all paired clients.
 
std::string nvhttp::get_arg (const args_t &args, const char *name, const char *default_value=nullptr)
 Read a named query argument from the HTTP request map.
 
std::string nvhttp::get_cert_by_uuid (const std::string_view uuid)
 Get cert by UUID.
 
uint32_t nvhttp::get_codec_mode_flags ()
 Get codec mode flags.
 
void nvhttp::getservercert (pair_session_t &sess, pt::ptree &tree, const std::string &pin)
 Return the server certificate text for pairing responses.
 
bool nvhttp::is_client_enabled (const std::string_view cert_pem)
 Check whether a paired client certificate is allowed to connect.
 
void nvhttp::launch (bool &host_audio, resp_https_t response, req_https_t request)
 Launch the requested application for a GameStream session.
 
void nvhttp::load_state ()
 Load state from its backing store.
 
std::shared_ptr< rtsp_stream::launch_session_tnvhttp::make_launch_session (bool host_audio, const args_t &args)
 Create launch session.
 
template<class T >
void nvhttp::not_found (std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > response, std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request)
 Return a GameStream HTTP not-found response.
 
template<class T >
void nvhttp::pair (std::shared_ptr< safe::queue_t< crypto::x509_t > > &add_cert, std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > response, std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request)
 Dispatch the top-level GameStream pairing request by phase.
 
bool nvhttp::pin (std::string pin, std::string name)
 Compare the user supplied pin to the Moonlight pin.
 
template<class T >
void nvhttp::print_req (std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request)
 Write req details to the log.
 
void nvhttp::remove_session (const pair_session_t &sess)
 removes the temporary pairing session
 
void nvhttp::resume (bool &host_audio, resp_https_t response, req_https_t request)
 Resume an existing GameStream session.
 
void nvhttp::save_state ()
 Persist the current state to its backing store.
 
void nvhttp::serverchallengeresp (pair_session_t &sess, pt::ptree &tree, const std::string &encrypted_response)
 Handle the server-challenge response phase of GameStream pairing.
 
template<class T >
void nvhttp::serverinfo (std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > response, std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request)
 Build the GameStream server-info response.
 
bool nvhttp::set_client_enabled (std::string_view uuid, bool enabled)
 Enable or disable a client.
 
void nvhttp::setup (const std::string &pkey, const std::string &cert)
 Setup the nvhttp server.
 
void nvhttp::start ()
 Start the nvhttp server.
 
bool nvhttp::unpair_client (std::string_view uuid)
 Remove single client.
 

Variables

crypto::cert_chain_t nvhttp::cert_chain
 Certificate chain presented by Sunshine's GameStream HTTPS server.
 
client_t nvhttp::client_root
 In-memory representation of the paired-client database.
 
struct nvhttp::conf_intern_t nvhttp::conf_intern
 TLS credential paths loaded from Sunshine's runtime configuration.
 
std::string nvhttp::last_verified_client_cert
 Last client certificate accepted by the TLS verify callback. // NOSONAR(cpp:S5421) - intentionally mutable global.
 
std::unordered_map< std::string, pair_session_tnvhttp::map_id_sess
 Pairing sessions keyed by temporary unique ID.
 
std::atomic< uint32_t > nvhttp::session_id_counter
 Monotonic counter used to allocate GameStream session IDs.
 

Detailed Description

Definitions for the nvhttp (GameStream) server.