mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-15 21:22:40 +00:00
Force remote streaming mode if connecting through a VPN
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include <QUdpSocket>
|
#include <QUdpSocket>
|
||||||
#include <QHostInfo>
|
#include <QHostInfo>
|
||||||
#include <QNetworkInterface>
|
#include <QNetworkInterface>
|
||||||
|
#include <QNetworkProxy>
|
||||||
|
|
||||||
#define SER_NAME "hostname"
|
#define SER_NAME "hostname"
|
||||||
#define SER_UUID "uuid"
|
#define SER_UUID "uuid"
|
||||||
@@ -237,6 +238,60 @@ bool NvComputer::wake()
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NvComputer::isReachableOverVpn()
|
||||||
|
{
|
||||||
|
if (activeAddress.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTcpSocket s;
|
||||||
|
|
||||||
|
s.setProxy(QNetworkProxy::NoProxy);
|
||||||
|
s.connectToHost(activeAddress, 47984);
|
||||||
|
if (s.waitForConnected(3000)) {
|
||||||
|
Q_ASSERT(!s.localAddress().isNull());
|
||||||
|
|
||||||
|
for (const QNetworkInterface& nic : QNetworkInterface::allInterfaces()) {
|
||||||
|
// Ensure the interface is up
|
||||||
|
if ((nic.flags() & QNetworkInterface::IsUp) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const QNetworkAddressEntry& addr : nic.addressEntries()) {
|
||||||
|
if (addr.ip() == s.localAddress()) {
|
||||||
|
qInfo() << "Found matching interface:" << nic.humanReadableName() << nic.type() << nic.flags();
|
||||||
|
|
||||||
|
if (nic.flags() & QNetworkInterface::IsPointToPoint) {
|
||||||
|
// Treat point-to-point links as likely VPNs
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nic.type() == QNetworkInterface::Virtual ||
|
||||||
|
nic.type() == QNetworkInterface::Ppp) {
|
||||||
|
// Treat PPP and virtual interfaces as likely VPNs
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
||||||
|
qInfo() << "MTU is" << nic.maximumTransmissionUnit();
|
||||||
|
if (nic.maximumTransmissionUnit() < 1500) {
|
||||||
|
// Treat MTUs under 1500 as likely VPNs
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Didn't meet any of our VPN heuristics
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// If we fail to connect, just pretend that it's not a VPN
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QVector<QString> NvComputer::uniqueAddresses()
|
QVector<QString> NvComputer::uniqueAddresses()
|
||||||
{
|
{
|
||||||
QVector<QString> uniqueAddressList;
|
QVector<QString> uniqueAddressList;
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ public:
|
|||||||
bool
|
bool
|
||||||
wake();
|
wake();
|
||||||
|
|
||||||
|
bool
|
||||||
|
isReachableOverVpn();
|
||||||
|
|
||||||
QVector<QString>
|
QVector<QString>
|
||||||
uniqueAddresses();
|
uniqueAddresses();
|
||||||
|
|
||||||
|
|||||||
@@ -356,8 +356,6 @@ bool Session::initialize()
|
|||||||
m_StreamConfig.fps = m_Preferences->fps;
|
m_StreamConfig.fps = m_Preferences->fps;
|
||||||
m_StreamConfig.bitrate = m_Preferences->bitrateKbps;
|
m_StreamConfig.bitrate = m_Preferences->bitrateKbps;
|
||||||
m_StreamConfig.hevcBitratePercentageMultiplier = 75;
|
m_StreamConfig.hevcBitratePercentageMultiplier = 75;
|
||||||
m_StreamConfig.streamingRemotely = STREAM_CFG_AUTO;
|
|
||||||
m_StreamConfig.packetSize = 1392;
|
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Video bitrate: %d kbps",
|
"Video bitrate: %d kbps",
|
||||||
@@ -937,6 +935,19 @@ void Session::exec(int displayOriginX, int displayOriginY)
|
|||||||
hostInfo.serverInfoGfeVersion = siGfeVersion.data();
|
hostInfo.serverInfoGfeVersion = siGfeVersion.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isReachableOverVpn() does network I/O, so we only attempt to check
|
||||||
|
// VPN reachability if we've already contacted the PC successfully
|
||||||
|
if (m_Computer->isReachableOverVpn()) {
|
||||||
|
// It looks like our route to this PC is over a VPN.
|
||||||
|
// Treat it as remote even if the target address is in RFC 1918 address space.
|
||||||
|
m_StreamConfig.streamingRemotely = STREAM_CFG_REMOTE;
|
||||||
|
m_StreamConfig.packetSize = 1024;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_StreamConfig.streamingRemotely = STREAM_CFG_AUTO;
|
||||||
|
m_StreamConfig.packetSize = 1392;
|
||||||
|
}
|
||||||
|
|
||||||
int err = LiStartConnection(&hostInfo, &m_StreamConfig, &k_ConnCallbacks,
|
int err = LiStartConnection(&hostInfo, &m_StreamConfig, &k_ConnCallbacks,
|
||||||
&m_VideoCallbacks,
|
&m_VideoCallbacks,
|
||||||
m_AudioDisabled ? nullptr : &m_AudioCallbacks,
|
m_AudioDisabled ? nullptr : &m_AudioCallbacks,
|
||||||
|
|||||||
Reference in New Issue
Block a user