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

Implements host auto-discovery helpers. More...

#include "src/network/host_discovery.h"
#include <algorithm>
#include <cctype>
#include <cstdint>
#include <mutex>
#include <string>
#include <string_view>
#include <unordered_map>
#include <utility>
#include <vector>
#include "src/app/host_records.h"
#include "src/logging/logger.h"
#include "src/network/runtime_network.h"
#include <cstddef>
#include <lwip/apps/mdns.h>
#include <lwip/apps/mdns_domain.h>
#include <lwip/err.h>
#include <lwip/igmp.h>
#include <lwip/netif.h>
#include <lwip/prot/dns.h>
#include <lwip/tcpip.h>
#include <windows.h>
Include dependency graph for host_discovery.cpp:

Functions

bool network::testing::append_mdns_discovered_host (DiscoverHostsResult *result, std::string displayName, const std::string &address, uint16_t port)
 Expose host normalization and deduplication to host-native unit tests.
 
void network::testing::clear_host_discovery_test_handler ()
 Remove any scripted host-discovery handler installed for tests.
 
DiscoverHostsResult network::discover_hosts (uint32_t timeoutMilliseconds)
 Discover Moonlight-compatible hosts on the local network.
 
std::string network::testing::first_host_discovery_label (std::string_view domainText)
 Expose the internal DNS-label parser to host-native unit tests.
 
void network::testing::set_host_discovery_test_handler (HostDiscoveryTestHandler handler)
 Install a scripted host-discovery handler for unit tests.
 
void network::testing::sort_discovered_hosts (std::vector< DiscoveredHost > *hosts)
 Expose the runtime host ordering rules to host-native unit tests.
 
std::string network::testing::trim_host_discovery_text (std::string_view text)
 Expose the internal whitespace trimmer to host-native unit tests.
 

Variables

struct netif * g_pnetif
 nxdk-provided pointer to the active lwIP network interface.
 

Detailed Description

Implements host auto-discovery helpers.

Function Documentation

◆ append_mdns_discovered_host()

bool network::testing::append_mdns_discovered_host ( DiscoverHostsResult * result,
std::string displayName,
const std::string & address,
uint16_t port )

Expose host normalization and deduplication to host-native unit tests.

Parameters
resultDiscovery result to update.
displayNameCandidate user-facing label.
addressCandidate IPv4 address.
portCandidate HTTP port, or zero for the default port.
Returns
True when a new host was appended.

◆ discover_hosts()

DiscoverHostsResult network::discover_hosts ( uint32_t timeoutMilliseconds)

Discover Moonlight-compatible hosts on the local network.

The Xbox build uses lwIP mDNS/DNS-SD search support to look for compatible GameStream services. Host-native test builds return scripted results when a test handler is installed, or an empty successful result otherwise.

Parameters
timeoutMillisecondsMaximum discovery window in milliseconds.
Returns
Discovered hosts plus an optional error message.

◆ first_host_discovery_label()

std::string network::testing::first_host_discovery_label ( std::string_view domainText)

Expose the internal DNS-label parser to host-native unit tests.

Parameters
domainTextService instance or host domain text.
Returns
The first DNS label after discovery-style trimming.

◆ set_host_discovery_test_handler()

void network::testing::set_host_discovery_test_handler ( HostDiscoveryTestHandler handler)

Install a scripted host-discovery handler for unit tests.

Parameters
handlerCallback that should service subsequent discovery requests.

◆ sort_discovered_hosts()

void network::testing::sort_discovered_hosts ( std::vector< DiscoveredHost > * hosts)

Expose the runtime host ordering rules to host-native unit tests.

Parameters
hostsHosts to sort in place.

◆ trim_host_discovery_text()

std::string network::testing::trim_host_discovery_text ( std::string_view text)

Expose the internal whitespace trimmer to host-native unit tests.

Parameters
textRaw discovery text.
Returns
Discovery text with surrounding ASCII whitespace removed.