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

Definitions for Windows mDNS service registration. More...

#include <WinSock2.h>
#include <Windows.h>
#include <WinDNS.h>
#include <winerror.h>
#include "misc.h"
#include "src/config.h"
#include "src/logging.h"
#include "src/network.h"
#include "src/nvhttp.h"
#include "src/platform/common.h"
#include "src/thread_safe.h"
#include "utf_utils.h"
Include dependency graph for publish.cpp:

Classes

struct  _DNS_SERVICE_CANCEL
 Windows DNS-SD cancellation request data. More...
 
struct  _DNS_SERVICE_INSTANCE
 Windows DNS-SD service instance registration data. More...
 
struct  _DNS_SERVICE_REGISTER_REQUEST
 Windows DNS-SD service registration request data. More...
 
class  platf::publish::mdns_registration_t
 Windows DNS-SD registration lifetime for the advertised Sunshine service. More...
 

Macros

#define __SV(quote)
 Macro for SV.
 
#define _FN(x, ret, args)
 Macro for FN.
 
#define SV(quote)
 Macro for SV.
 

Typedefs

typedef DWORD(* _DnsServiceDeRegister_fn) (_In_ PDNS_SERVICE_REGISTER_REQUEST pRequest, _Inout_opt_ PDNS_SERVICE_CANCEL pCancel)
 Function pointer type for the dynamically loaded DNS-SD entry point.

 
typedef VOID(* _DnsServiceFreeInstance_fn) (_In_ PDNS_SERVICE_INSTANCE pInstance)
 Function pointer type for the dynamically loaded DNS-SD entry point.

 
typedef DWORD(* _DnsServiceRegister_fn) (_In_ PDNS_SERVICE_REGISTER_REQUEST pRequest, _Inout_opt_ PDNS_SERVICE_CANCEL pCancel)
 Function pointer type for the dynamically loaded DNS-SD entry point.

 
typedef struct _DNS_SERVICE_CANCEL DNS_SERVICE_CANCEL
 Windows DNS-SD cancellation request data.
 
typedef struct _DNS_SERVICE_INSTANCE DNS_SERVICE_INSTANCE
 Windows DNS-SD service instance registration data.
 
typedef VOID WINAPI DNS_SERVICE_REGISTER_COMPLETE(_In_ DWORD Status, _In_ PVOID pQueryContext, _In_ PDNS_SERVICE_INSTANCE pInstance)
 DNS service registration completion callback.
 
typedef struct _DNS_SERVICE_REGISTER_REQUEST DNS_SERVICE_REGISTER_REQUEST
 Windows DNS-SD service registration request data.
 
typedef struct _DNS_SERVICE_CANCELPDNS_SERVICE_CANCEL
 Alias for DNS SERVICE CANCEL.
 
typedef struct _DNS_SERVICE_INSTANCEPDNS_SERVICE_INSTANCE
 Alias for DNS SERVICE INSTANCE.
 
typedef DNS_SERVICE_REGISTER_COMPLETEPDNS_SERVICE_REGISTER_COMPLETE
 Pointer to the Windows DNS-SD registration completion callback.
 
typedef struct _DNS_SERVICE_REGISTER_REQUESTPDNS_SERVICE_REGISTER_REQUEST
 Alias for DNS SERVICE REGISTER REQUEST.
 

Functions

int platf::publish::load_funcs (HMODULE handle)
 Resolve required function pointers from the native library.
 
VOID WINAPI platf::publish::register_cb (DWORD status, PVOID pQueryContext, PDNS_SERVICE_INSTANCE pInstance)
 Handle completion of a Windows DNS-SD registration request.
 
std::unique_ptr< deinit_tplatf::publish::start ()
 Main entry point for publication of our service on macOS.
 

Variables

constexpr auto DNS_QUERY_REQUEST_VERSION1 = 0x1
 Windows DNS API constant for query request version1.
 
constexpr auto DNS_QUERY_RESULTS_VERSION1 = 0x1
 Windows DNS API constant for query results version1.
 
constexpr auto DNS_REQUEST_PENDING = 9506L
 Windows DNS API constant for request pending.
 
constexpr auto SERVICE_DOMAIN = "local"
 Protocol or platform constant for service domain.
 
const auto SERVICE_TYPE_DOMAIN = std::format("{}.{}"sv, platf::SERVICE_TYPE, SERVICE_DOMAIN)
 Protocol or platform constant for service type domain.
 

Detailed Description

Definitions for Windows mDNS service registration.

Macro Definition Documentation

◆ __SV

#define __SV ( quote)
Value:
L##quote##sv

Macro for SV.

◆ _FN

#define _FN ( x,
ret,
args )
Value:
\
typedef ret(*x##_fn) args; \
\
static x##_fn x
Functions for handling command line arguments.
Definition entry_handler.cpp:37

Macro for FN.

◆ SV

#define SV ( quote)
Value:
__SV(quote)
#define __SV(quote)
Macro for SV.
Definition publish.cpp:40

Macro for SV.

Typedef Documentation

◆ _DnsServiceDeRegister_fn

typedef DWORD(* _DnsServiceDeRegister_fn) (_In_ PDNS_SERVICE_REGISTER_REQUEST pRequest, _Inout_opt_ PDNS_SERVICE_CANCEL pCancel)

Function pointer type for the dynamically loaded DNS-SD entry point.

◆ _DnsServiceFreeInstance_fn

typedef VOID(* _DnsServiceFreeInstance_fn) (_In_ PDNS_SERVICE_INSTANCE pInstance)

Function pointer type for the dynamically loaded DNS-SD entry point.

◆ _DnsServiceRegister_fn

typedef DWORD(* _DnsServiceRegister_fn) (_In_ PDNS_SERVICE_REGISTER_REQUEST pRequest, _Inout_opt_ PDNS_SERVICE_CANCEL pCancel)

Function pointer type for the dynamically loaded DNS-SD entry point.

◆ DNS_SERVICE_REGISTER_COMPLETE

typedef VOID WINAPI DNS_SERVICE_REGISTER_COMPLETE(_In_ DWORD Status, _In_ PVOID pQueryContext, _In_ PDNS_SERVICE_INSTANCE pInstance)

DNS service registration completion callback.

Parameters
StatusRegistration status.
pQueryContextUser query context.
pInstanceDNS service instance.

Function Documentation

◆ load_funcs()

int platf::publish::load_funcs ( HMODULE handle)

Resolve required function pointers from the native library.

Parameters
handleNative library or object handle used by the operation.
Returns
0 when all required DNS-SD functions are resolved; nonzero otherwise.

◆ register_cb()

VOID WINAPI platf::publish::register_cb ( DWORD status,
PVOID pQueryContext,
PDNS_SERVICE_INSTANCE pInstance )

Handle completion of a Windows DNS-SD registration request.

Parameters
statusNative status code returned by the platform API.
pQueryContextAlarm object signaled when registration completes.
pInstanceRegistered DNS-SD service instance returned by Windows.
Returns
Callback has no return value; completion is reported through the alarm.

◆ start()

std::unique_ptr<::platf::deinit_t > platf::publish::start ( )
nodiscard

Main entry point for publication of our service on macOS.

This function initiates a connection to the macOS mDNS service and requests to register our Sunshine service. Registration will occur asynchronously (unless it fails immediately, which is probably only possible if the host machine is misconfigured).

Returns
Either nullptr (if the registration fails immediately) or a uniqur_ptr<deinit_t>, which will manage polling for a response from the mDNS service, and then, when deconstructed, will deregister the service.